SA-MP Forums Archive
how to check if a player's position has been drastically changed? - 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)
+--- Thread: how to check if a player's position has been drastically changed? (/showthread.php?tid=317492)



how to check if a player's position has been drastically changed? - T0pAz - 11.02.2012

How to check if a player's position has been drastically changed without the use of timer?


Re: how to check if a player's position has been drastically changed? - fordawinzz - 11.02.2012

onplayerupdate?


Re: how to check if a player's position has been drastically changed? - T0pAz - 11.02.2012

Quote:
Originally Posted by fordawinzz
Посмотреть сообщение
onplayerupdate?
How?


Re: how to check if a player's position has been drastically changed? - Babul - 11.02.2012

1 word: delta.
pawn Код:
new Float:PlayerPosOld[MAX_PLAYERS][3];
OnPlayerUpdate:
pawn Код:
new Float:PosNew[3];
new Float:PosDelta[3];
GetPlayerPos(playerid,PosNew[playerid][0],PosNew[playerid][1],PosNew[playerid][2]);

PosDelta[0]=PosNew[0]-PlayerPosOld[playerid][0];
PosDelta[1]=PosNew[0]-PlayerPosOld[playerid][0];
PosDelta[2]=PosNew[0]-PlayerPosOld[playerid][0];

PlayerPosOld[MAX_PLAYERS][0]=PosNew[0];
PlayerPosOld[MAX_PLAYERS][1]=PosNew[1];
PlayerPosOld[MAX_PLAYERS][2]=PosNew[2];
after this, the PosDelta will have stored the difference betwen each position change. ignoring the [2] can be, i doubt that any player teleports into the sky (or below ground)...

oh, maybe adding this in another callback can help to avoid lag. the OnPlayerKeyStateChange fits better imo - no player can move without pressing at least 1 key.


Re: how to check if a player's position has been drastically changed? - T0pAz - 11.02.2012

Quote:
Originally Posted by Babul
Посмотреть сообщение
1 word: delta.
pawn Код:
new Float:PlayerPosOld[MAX_PLAYERS][3];
OnPlayerUpdate:
pawn Код:
new Float:PosNew[3];
new Float:PosDelta[3];
GetPlayerPos(playerid,PosNew[playerid][0],PosNew[playerid][1],PosNew[playerid][2]);

PosDelta[0]=PosNew[0]-PlayerPosOld[playerid][0];
PosDelta[1]=PosNew[0]-PlayerPosOld[playerid][0];
PosDelta[2]=PosNew[0]-PlayerPosOld[playerid][0];

PlayerPosOld[MAX_PLAYERS][0]=PosNew[0];
PlayerPosOld[MAX_PLAYERS][1]=PosNew[1];
PlayerPosOld[MAX_PLAYERS][2]=PosNew[2];
after this, the PosDelta will have stored the difference betwen each position change. ignoring the [2] can be, i doubt that any player teleports into the sky (or below ground)...

oh, maybe adding this in another callback can help to avoid lag. the OnPlayerKeyStateChange fits better imo - no player can move without pressing at least 1 key.
It's really embarrassing for me to forget it. You deserve reputation from me.