timer problem - 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: timer problem (
/showthread.php?tid=446929)
timer problem -
exclide1 - 27.06.2013
Hello. I'm trying to create a spawn kill protection with the function "IsPlayerInRangeOfPoint".
Here is what I have:
At the top:
pawn Код:
new gatetimer[MAX_PLAYERS];
forward GateTimer(playerid);
public GateTimer(playerid)
{
for(new i = 1; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
if(!IsPlayerInRangeOfPoint(i, 7.0, 1415.2137,2773.7051,14.8135))
{
SendClientMessage(i, COLOR_RED, "Spawn protection countdown has started. You have 10 seconds.");
SetTimerEx("AntiSpawnkill",10000,0,"i",i);
KillTimer(gatetimer[playerid]);
}
}
}
return 1;
}
forward AntiSpawnkill(playerid);
public AntiSpawnkill(playerid)
{
SetPlayerHealth(playerid, 100.0);
SendClientMessage(playerid, 0xFF8000C8, "Spawn protection over.");
timer1 = false;
return 1;
}
OnPlayerSpawn:
pawn Код:
SetPlayerHealth(playerid, 99999.0);
SendClientMessage(playerid, COLOR_RED, "Spawn protection countdown will start on your movement.");
gatetimer[playerid] = SetTimerEx("GateTimer", 1500, true, "i", playerid);
What it should do is start a repeative timer after player spawn, that checks every 1.5 sec if the player is in specified range, if not >>(if(!IsPlayerInRangeOfPoint(i, 7.0, 1415.2137,2773.7051,14.8135))<<,, then it kills the repeative timer and starts another timer, that will set players health back to 100. BUT somehow the first repeative timer is getting killed, even if the player IS InRangeOfPoint, so it doesn't start the other timer, neither is sends the client message. I'd appreciate any help!
Re: timer problem -
Jefff - 28.06.2013
pawn Код:
forward GateTimer(playerid);
public GateTimer(playerid)
{
if(!IsPlayerInRangeOfPoint(playerid, 7.0, 1415.2137,2773.7051,14.8135))
{
SendClientMessage(playerid, COLOR_RED, "Spawn protection countdown has started. You have 10 seconds.");
SetTimerEx("AntiSpawnkill",10000,0,"i",playerid);
KillTimer(gatetimer[playerid]);
}
return 1;
}
Re: timer problem -
exclide1 - 28.06.2013
Quote:
Originally Posted by Jefff
pawn Код:
forward GateTimer(playerid); public GateTimer(playerid) { if(!IsPlayerInRangeOfPoint(playerid, 7.0, 1415.2137,2773.7051,14.8135)) { SendClientMessage(playerid, COLOR_RED, "Spawn protection countdown has started. You have 10 seconds."); SetTimerEx("AntiSpawnkill",10000,0,"i",playerid); KillTimer(gatetimer[playerid]); } return 1; }
|
Thank you! I guess I have to learn more about looping! But can you tell me why does the first timer call GateTimer() twice now?
Re: timer problem -
Jefff - 28.06.2013
I dont know, must be second timer in your gm and hes running second time, put in spawn
KillTimer(gatetimer[playerid]);
above
gatetimer[playerid] = SetTimerEx("GateTimer", 1500, true, "i", playerid);
Re: timer problem -
exclide1 - 28.06.2013
Quote:
Originally Posted by Jefff
I dont know, must be second timer in your gm and hes running second time, put in spawn
KillTimer(gatetimer[playerid]);
above
gatetimer[playerid] = SetTimerEx("GateTimer", 1500, true, "i", playerid);
|
I used ******'s foreach, instead of default loop and it worked itself out. Thanks again!