Checking Whether on Ground in Lua

Have a question, suggestion, or comment about Aleph One's features and functionality (Lua, MML, the engine itself, etc)? Post such topics here.
Post Reply
User avatar
PerseusSpartacus
Mjolnir Mark IV
Posts: 334
Joined: Apr 30th '12, 05:03
Location: Somewhere in the 19th Century...

I'm planning to create a small Lua script that adds jumping abilities to Marathon in a balanced and fair manner (much like Halo or Unreal Tournament) but I need to know how to check whether the player is on the ground, that way he can't 'double-jump' or jump in mid-air. I can figure out the rest, but I could use a quick tutorial on how to check whether the player is on the ground.
User avatar
treellama
Vidmaster
Posts: 6107
Joined: Jun 2nd '06, 02:05
Location: Pittsburgh
Contact:

Code: Select all

if player.z == player.polygon.z then
    player:print("YOU ARE ON THE GROUND")
end
But you can figure out the rest?
User avatar
PerseusSpartacus
Mjolnir Mark IV
Posts: 334
Joined: Apr 30th '12, 05:03
Location: Somewhere in the 19th Century...

treellama wrote:But you can figure out the rest?
Yeah, I've dealt with Lua before, when using Corona SDK. All Lua APIs operate very similarly, from what I can tell. At the very least, constructing 'triggers' or 'functions' operates basically the same - a lot of 'if's, 'and's, and 'then's. Should be a piece of cake. ;)
Powerful experience to live in fear, isn't it? That's what it is to be a slave.
User avatar
PerseusSpartacus
Mjolnir Mark IV
Posts: 334
Joined: Apr 30th '12, 05:03
Location: Somewhere in the 19th Century...

Okay, I've made a small Lua script that adds jumping abilities to Marathon while ensuring the player can only jump when he/she is firmly on the ground. Here's the code:

Code: Select all

-- Hopper.lua
-- 
-- To use this script, select it as the solo script in environment
-- preferences
--
-- To jump, press the Microphone key

Triggers = {}

function Triggers.idle()

   if Game.ticks == 0 then
      Players.print("Jumping enabled")
   end

   -- handle jumping
   for p in Players() do
      if p.action_flags.microphone_button then
	 if not p._latched and p.z == p.polygon.z then
	    p._latched = true
	    p:accelerate(0, 0, 0.05)
	 end
	 p.action_flags.microphone_button = false
      else
	 p._latched = false
      end
   end

end
If you want to change the jumping strength, just replace the '0.05' with a higher or lower number. Mind you, it's pretty sensitive: even changing it to 0.075 can let you jump over ledges that are 1 WU high, which is a pretty drastic difference from what it does currently.

Note that this works perfectly in Single-player, but it might not work as a netscript. You'll have to test for me.
User avatar
Hopper
Mjolnir Mark IV
Posts: 585
Joined: May 10th '09, 17:02
Contact:

PerseusSpartacus wrote:

Code: Select all

-- Hopper.lua
Don't make me send you a DMCA takedown notice!
User avatar
PerseusSpartacus
Mjolnir Mark IV
Posts: 334
Joined: Apr 30th '12, 05:03
Location: Somewhere in the 19th Century...

Hopper wrote:Don't make me send you a DMCA takedown notice!
I thought you'd like it. ;)
Powerful experience to live in fear, isn't it? That's what it is to be a slave.
User avatar
megabyte
Vidmaster
Posts: 1006
Joined: Feb 15th '07, 02:43
Location: Asympotatoes, Mars
Contact:

I haven't been around here in ages but this just popped up in my RSS reader. I haven't tested this out yet, but one of the first scripts I released was a jump script. The primary difference is that players grunt on jumping in mine :P. Oh also there was a reason i didn't check the Z value and compare it the polygon but its been 5 years since I tried that.

http://simplici7y.com/items/jump-script
User avatar
PerseusSpartacus
Mjolnir Mark IV
Posts: 334
Joined: Apr 30th '12, 05:03
Location: Somewhere in the 19th Century...

Okay, just posted my script on Simplici7y. I'll probably add more stuff later, like optional fall damage or maybe even mid-air control (though that would be kind of tricky). You can find it here:

http://simplici7y.com/items/hopper-lua
User avatar
craZboy557
Cyborg
Posts: 101
Joined: May 11th '13, 21:29

Could you add instructions for installation and use?
Spoiler:
Sig of the Week:
Most of my suggestions for how to improve a game boil down to "It should be more like Halo."

_____________________________________________________________________________

Image
Post Reply