Detect if player is falling - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Detect if player is falling (
/showthread.php?tid=73880)
Detect if player is falling -
StrickenKid - 18.04.2009
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!
Re: Detect if player is falling -
StrickenKid - 18.04.2009
BUMP: no one?
Re: Detect if player is falling -
MenaceX^ - 18.04.2009
There's nothing espeicaly about that, but you can do it by getting player's speed in a timer.
Re: Detect if player is falling -
Backwardsman97 - 18.04.2009
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.
Re: Detect if player is falling -
StrickenKid - 18.04.2009
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.
Re: Detect if player is falling -
Backwardsman97 - 19.04.2009
Btw, you probably want to add in a check to make sure they aren't in a vehicle.
Re: Detect if player is falling -
StrickenKid - 19.04.2009
already done