Detect if player is falling
#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


Messages In This Thread
Detect if player is falling - by StrickenKid - 18.04.2009, 16:46
Re: Detect if player is falling - by StrickenKid - 18.04.2009, 18:34
Re: Detect if player is falling - by MenaceX^ - 18.04.2009, 18:36
Re: Detect if player is falling - by Backwardsman97 - 18.04.2009, 18:52
Re: Detect if player is falling - by StrickenKid - 18.04.2009, 19:12
Re: Detect if player is falling - by Backwardsman97 - 19.04.2009, 00:38
Re: Detect if player is falling - by StrickenKid - 19.04.2009, 00:46

Forum Jump:


Users browsing this thread: 1 Guest(s)