timer problem
#1

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!
Reply
#2

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;
}
Reply
#3

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?
Reply
#4

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);
Reply
#5

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!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)