How to detect a falling or jumping action? (by =TDAr=Zer0Skills)

Started by (vG)DesTroYeR^, Today at 02:54 PM

Previous topic - Next topic

(vG)DesTroYeR^

----------> JUMP DETECTION <----------

function IsJumping(p) {
if(p.Action == 41) return 1; // (true)
else return 0; // (false)
}

----------> JUMP EXAMPLE CODE USAGE <----------

function onPlayerMove(player, lastX, lastY, lastZ, newX, newY, newZ){
if(IsJumping(player)){
player.Speed.z += 1;   // E---X---A---M---P---L---E
}
}


_________________________________________


----------> FALL DETECTION <----------

function IsFalling(p, Znew, Zlast) {
if(IsJumping(p)) return false;
if(Znew == Zlast) return false; // rarely happens if the player is continually moving, since you can barely find a straightforward surface so Z positions are almost always dynamic
local newZlower = (Znew < Zlast ? true : false);
if(newZlower) {
if(Zlast - Znew < 0.15) return false; // Not Falling (e.g, 11.3 - 11.2 = 0.1 is not a fall)
else return true; // > 0.15 is a fall (Approximate numbers - I didn't really calculate it precisely)
}
else {return false;} // Znew is bigger -> so climbing or going up somehow
}

----------> FALLING EXAMPLE CODE USAGE <----------
function onPlayerMove(player, lastX, lastY, lastZ, newX, newY, newZ){
if(IsFalling(player, newZ, lastZ)) player.Immunity = 32; // E---X---A---M---P---L---E
}


Lastly, what you have to do (The code's user) is to make sure about the value (0.15) accuracy by testing it out in ur server, so I will adjust it here accordingly, or I might test it later and find out the precise value.