SA-MP Forums Archive
Updating a players pos with timer - 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: Updating a players pos with timer (/showthread.php?tid=496478)



Updating a players pos with timer - ross8839 - 22.02.2014

Okay, so I want to make a /take command for a restrained player, and every 100-500ms it will set the players pos to the police officer using /take...

and i get him to teleport, but the timer doesn't keep repeating the teleport function but repeats the command if that makes sense... anyone have any idea of how i can do this, code with comments is good, but if you tell me everything i need to know to make it, that's great.

Thanks in advance.


Re: Updating a players pos with timer - BroZeus - 22.02.2014

can u tell more clearly what u want


Re: Updating a players pos with timer - Smileys - 22.02.2014

https://sampwiki.blast.hk/wiki/SetTimer

or

https://sampwiki.blast.hk/wiki/SetTimerEx

and

https://sampwiki.blast.hk/wiki/KillTimer

look at the "repeat" parameter, set it to true.

then later on kill the timer so it won't go on indefinitely.


Re : Updating a players pos with timer - S4t3K - 22.02.2014

Also don't forget to set a variable to the timer for properly using KillTimer

For example

PHP код:

new ptimer; // ptimer like pos timer

public UpdatePlayerPos(playerid)
{
    new 
Float:x, Float:y, Float:z;
    
GetPlayerPos(playerid, x, y, z);
    
// Don't know what you wanna do, so i'll use it with SetPlayerCheckpoint
    
for(new p = 0; p < MAX_PLAYERS;p++)
    {
        if(
p == playerid) continue;
        else return 
SetPlayerCheckpoint(i, x, y, z, 5.0);
    }
// In ur command

ptimer = SetTimerEx("UpdatePlayerPos", 500, true, "d", playerid);

// In the command to stop

if(strcmp(cmdtext, "/stoptimer", true) == 0)
{
     
KillTimer(ptimer);
     print(
"Timer killed");
     return 
1;
}