Timer Problem
#1

I have a problem when making a timer. Look at part of my script.

On the top of the script:
pawn Code:
forward takeover(playerid, gangzoneid);
forward counter(playerid, gangzoneid);
And then, I added these functions:
pawn Code:
//Gangzone Functions
public takeover(playerid, gangzoneid)
{
    new string[256];
    if(GetGangzoneOwner(gangzoneid) >= 0)
    {
        format(string, sizeof(string), "|- {FFFF00}%s {00FF00}has successfully taking over the territory of {FFFF00}%s {00FF00} -|", PlayerName(playerid), GetTeamName(GetGangzoneOwner(gangzoneid)));
        SendClientMessageToAll(0x00FF00AA, string);
    }
    else
    {
        format(string, sizeof(string), "|- {FFFF00}%s {00FF00}has successfully taking over a territory -|", PlayerName(playerid));
        SendClientMessageToAll(0x00FF00AA, string);
    }

    GangzoneOwner[gangzoneid] = GetPlayerTeam(playerid);
    GangzoneChangeOwner[gangzoneid] = -1;

    GangZoneHideForAll(gangzoneid);
    GangZoneShowForAll(gangzoneid, GetPlayerColor(playerid));
    GangzoneColor[gangzoneid] = GetPlayerColor(playerid);

    KillTimer(GetPVarInt(playerid, "gzcounter"));
}

public counter(playerid, gangzoneid)
{
    new Float:junk, Float:y;
    new string[256];
    GetPlayerPos(playerid, junk, y, junk);

    if(IsPlayerInRangeOfPoint(playerid, 30, GangzoneCheckpoint[gangzoneid][0], y, GangzoneCheckpoint[gangzoneid][2]))
    {
        if(!IsPlayerInRangeOfPoint(playerid, 20, GangzoneCheckpoint[gangzoneid][0], y, GangzoneCheckpoint[gangzoneid][2]))
        {
            GameTextForPlayer(playerid, "~w~Watch out! ~r~You're too far from the ~y~checkpoint!~n~~w~Go back to the checkpoint!", 2000, 2);
        }
    }
    else
    {
        GameTextForPlayer(playerid, "~r~You failed on trying to ~y~takeover~r~ this territory", 4000, 2);

        format(string, sizeof(string), "|- {FFFF00}%s {FF0000}has failed on trying to takeover the territory -|", PlayerName(playerid));
        SendClientMessageToAll(0xFFFF00AA, string);

        KillTimer(GetPVarInt(playerid, "gztimer"));
        KillTimer(GetPVarInt(playerid, "gzcounter"));
    }

    SendClientMessage(playerid, 0xFFFF00AA, "1 second elapsed"); //This is the debug
}
And, I added this in OnPlayerCommandText (Somewhere in it):
pawn Code:
SetPVarInt(playerid, "gztimer", SetTimerEx("takeover", 60000, false, "ii", playerid, IsPlayerInGangzoneCheckpoint(playerid)));
SetPVarInt(playerid, "gzcounter", SetTimerEx("counter", 1000, true, "ii", playerid, IsPlayerInGangzoneCheckpoint(playerid)));
I used the command, I saw that 1 second elapsed message (which is the debug I wanted), but the take over doesn't. I've wait for 1 minute and still nothing happened (I count with the debug). Anyone can help please?
Reply
#2

I don't know what IsPlayerInGangzoneCheckpoint(playerid) returns, but it looks like it returns 1 for true or 0 for false?
Then you use this value as gangzoneid in your timer. Maybe this is intentional, maybe not.
Reply
#3

The IsPlayerInGangzoneCheckpoint(playerid) returns the gangzone ID (No, not "real" gangzone ID, it's another gangzone ID between 0 to 6) and it returns -1 if the palyer isn't in gangzone.

The functions work perfectly, only the timer doesn't run
Reply
#4

Anyone
Reply
#5

if your function IsPlayerInGangzoneCheckpoint(playerid) doesn't return an actual gangzoneid, then I don't think you should be using GangZoneHideForAll(gangzoneid); in the takeover function.

I suggest you use printf / print to debug this. ie find out if the timer is being called, what values the variables have, and then take it from there.
Reply
#6

Hmm, you got a point actually...
Reply
#7

The Territory has flashed. But the timer still won't run. Any idea?
Reply
#8

If that is the case, split the SetPVarInt command up into its parts, use some extra variables, and printf the results.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)