Detect if player is falling
#1

is there a practical way to detect if the player is falling? i was thinking of detecting if the Z co-ord changes faster than the X or Y, i tried something like that but failed.

Thanks For Any Help!
Reply
#2

BUMP: no one?
Reply
#3

There's nothing espeicaly about that, but you can do it by getting player's speed in a timer.
Reply
#4

Actually I just made this real quick and tested it. It seems to work fine.

pawn Code:
forward FallingChecker();
forward OnPlayerFall(playerid);

new Float:LastX[MAX_PLAYERS],Float:LastY[MAX_PLAYERS],Float:LastZ[MAX_PLAYERS];

//OnGameModeInit
SetTimer("FallingChecker",500,1);

public FallingChecker()
{
   new Float:x,Float:y,Float:z,Float:d;
   for(new i =0; i<MAX_PLAYERS; i++)
   {
     if(IsPlayerConnected(i))
     {
        GetPlayerPos(i,x,y,z);
        d = floatsqroot((x-LastX[i] * x-LastX[i]) + (y-LastY[i] * y-LastY[i]));
        if(d < 10 && (LastZ[i] - z) > 5)
        {
          OnPlayerFall(i);
        }
        LastX[i] = x;
        LastY[i] = y;
        LastZ[i] = z;
     }
   }
   return 1;
}

public OnPlayerFall(playerid)
{
    SendClientMessage(playerid,0x000000FF,"You are falling!");
    return 1;
}
Obviously not 100% accurate but it gets the job done. :P It works by seeing if the player has moved less then 10 units and fallen more then 5. You can change those values.
Reply
#5

hey thanks man! i also just had a thought. this function would be pretty cool in a stunt server. detect if a player is falling and if they are give them a parachute.
Reply
#6

Btw, you probably want to add in a check to make sure they aren't in a vehicle.
Reply
#7

already done
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)