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.

Checking Whether on Ground in Lua

Post Jul 15th '13, 18:57

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

PerseusSpartacus
Somewhere in the 19th Century...

Post Jul 15th '13, 19:14

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

treellama
Pittsburgh

Post Jul 15th '13, 20:26

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
Somewhere in the 19th Century...

Post Jul 15th '13, 23:37

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

PerseusSpartacus
Somewhere in the 19th Century...

Post Jul 15th '13, 23:41

PerseusSpartacus wrote:
Code: Select all
-- Hopper.lua

Don't make me send you a DMCA takedown notice!
User avatar

Hopper

Post Jul 16th '13, 00:30

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

PerseusSpartacus
Somewhere in the 19th Century...

Post Jul 16th '13, 15:39

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

megabyte
Asympotatoes, Mars

Post Aug 18th '13, 01:26

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

PerseusSpartacus
Somewhere in the 19th Century...

Post Aug 18th '13, 18:52

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
User avatar

craZboy557


Return to Aleph One Discussion



Who is online

Users browsing this forum: No registered users