Problem killing timer
#1

Ok so for some reason this timer isn't being killed when the player does /dispatch off (It turns on fine with /dispatch on). Does anyone see somthing I am doing wrong? I have no compile errors.

I have added these in the right spots BTW:
forward DispatchAlert(playerid);
new DispatchAlertVar[MAX_PLAYERS];

Here is the command code:
pawn Код:
if(strcmp(cmd,"/dispatch",true)==0)
    {
        new rslt[24];
        rslt = strtok(cmdtext, idx);
        if(!strlen(rslt))
        {
            SendClientMessage(playerid, COLOR_WHITE, "USAGE: /dispatch [ON/OFF)");
            return 1;
        }
        if(strcmp(rslt,"on",true) == 0)
        {
            if(PlayerInfo[playerid][pDBanned] == 1)
            {
                SendClientMessage(playerid, COLOR_GREY, "** You are banned From Cop Duty!");
                return 1;
            }
            GameTextForPlayer(playerid, "~w~Powering Up...", 11000, 5);
            for(new i = 0; i < MAX_PLAYERS; i++)
            {
                if(IsPlayerConnected(playerid) && IsACop(playerid) || IsAFiremen(playerid))
                {
                    if(PlayerInfo[i][pDuty] == 1 && IsACop(i) || IsPlayerAdmin(i) && IsACop(i))
                    {
                        SetPlayerMarkerForPlayer(playerid, i, COLOR_YELLOW);
                    }
                    if(JobDuty[i] == 1 && IsAFiremen(i))
                    {
                        SetPlayerMarkerForPlayer(playerid, i, COLOR_YELLOW);
                    }
                    //GameTextForPlayer(playerid, "~w~Searching for vehicles...", 11000, 5);
                    DispatchAlertVar[playerid] = SetTimerEx("DispatchAlert",10000,true, "i", playerid);
                }
            }
        }
        else if(strcmp(rslt,"off",true) == 0)
        {
            for(new i = 0; i < MAX_PLAYERS; i++)
            {
                if(IsPlayerConnected(playerid) && IsACop(playerid) || IsAFiremen(playerid)|| IsPlayerAdmin(playerid))
                {
                    KillTimer(DispatchAlertVar[playerid]);
                    SetPlayerMarkerForPlayer(i, playerid, TEAM_HIT_COLOR);
                    //GameTextForPlayer(playerid, "~w~DVDS Powering Down......", 1000, 5);
                    GameTextForPlayer(playerid, "~w~Powering Down...", 11000, 5);
                }
            }
        }
        new y, m, d;
        new h,mi,s;
        getdate(y,m,d);
        gettime(h,mi,s);
        format(string,sizeof(string), "(%d/%d/%d)[%d:%d:%d] %s [CMD] -> /dispatch",d,m,y,h,mi,s,sendername);
        CommandLog(string);
        return 1;
    }
Here is the timer code:
pawn Код:
public DispatchAlert(playerid)
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        SetPlayerMarkerForPlayer(i, playerid, TEAM_HIT_COLOR);
        if(IsPlayerConnected(playerid) && IsACop(i) || IsAFiremen(i))
        {
            if(PlayerInfo[playerid][pDuty] == 1 && IsACop(playerid) || IsPlayerAdmin(playerid) && IsACop(i))
            {
                SetPlayerMarkerForPlayer(playerid, i, COLOR_BLUE);
            }
            if(JobDuty[playerid] == 1 && IsAFiremen(playerid) && IsAFiremen(i))
            {
                SetPlayerMarkerForPlayer(playerid, i, COLOR_ORANGE);
            }
        }
    }
    new string[800 char];
    new CurrentCars;
    CurrentCars = 0;
    for(new i = 0; i < MAX_VEHICLES; i++)  // MY WIP Police Vehicle Info system. Includes Health, driver, passengers, Location?, and Veh ID
    {
        if(IsACopCar(i))//All Cop Cars
        {
            for(new q = 0; q < MAX_PLAYERS; q++)
            {
                if(IsPlayerInVehicle(q, i))//All Cop Cars with People in the vehicle
                {
                    if(GetPlayerVehicleSeat(q) == 0)//All cop cars with a driver
                    {
                        new vehicle[24];
                        new player[800];
                        new Float:engine;
                        GetVehicleHealth(i, engine);
                        new Float:currenthealth;
                        currenthealth = engine / 10;
                        GetVehicleName(i, vehicle, sizeof(vehicle));
                        new zone[MAX_ZONE_NAME];
                        GetVehicle2DZone(i, zone, MAX_ZONE_NAME);
                        new atext[20];
                        if(gEngine[i] == 1) { atext = "{76EE00}ON{FFFFFF}"; }
                        else if(gEngine[i] == 0) { atext = "{EE0000}OFF{FFFFFF}"; }
                        new kmh = GetPlayerSpeed(q, true);
                        format(player, sizeof(player), "{FFFFFF}Vehicle: %s (%d)  |  Gov ID: %d  |  Driver: %s (%d) \n", vehicle, GetVehicleModel(i), i, Nick(q), q);// Want to add more stuff here...
                        strcat(string, player)
                        format(player, sizeof(player), "  {FFFFFF}Engine Status: %s  |  Health: %.1f %%  |  Speed: %d |  Location: %s \n", atext, currenthealth, kmh, zone);// Want to add more stuff here...
                        strcat(string, player)
                        ShowPlayerDialog(playerid, 1592, DIALOG_STYLE_MSGBOX, "Dispatch Vehicles Display System (DVDS)", string, "Close", "");
                        strdel(string, 0, strlen(string));
                        CurrentCars = 1;
                        return 1;
                    }
                }
            }
        }
        /*else if (CurrentCars == 0)// If no cars are found
        {
            new player[800];
            format(player, sizeof(player), "           - No Occupied Vehicles Found! -              \n");
            strins(string, player, strlen(string), sizeof(string));
            ShowPlayerDialog(playerid, 1592, DIALOG_STYLE_MSGBOX, "Dispatch Vehicles Display System (DVDS)", string, "Close", "");
            strdel(string, 0, strlen(string));
        }
        return 1;*/

    }
    return 1;
}
Reply
#2

Does the gametext, inside the if which includes the killtmer too, show up? If it doesn't, not killing is reasonable.
Reply
#3

Quote:
Originally Posted by jakejohnsonusa
Посмотреть сообщение
Ok so for some reason this timer isn't being killed when the player does /dispatch off (It turns on fine with /dispatch on). Does anyone see somthing I am doing wrong? I have no compile errors.

I have added these in the right spots BTW:
forward DispatchAlert(playerid);
new DispatchAlertVar[MAX_PLAYERS];

Here is the command code:
pawn Код:
for(new i = 0; i < MAX_PLAYERS; i++)
            {
                if(IsPlayerConnected(playerid) && IsACop(playerid) || IsAFiremen(playerid))
                    {
                    DispatchAlertVar[playerid] = SetTimerEx("DispatchAlert",10000,true, "i", playerid);
                }
            }
        }
the problem is caused because you put the timer in a loop which is creating MAX_PLAYERS amount of timers, your /dispatch off would only stop one so you'd still have MAX_PLAYERS - 1 amount of timers still running
Reply
#4

You also wrote inside loops playerid instead of "i":
pawn Код:
for(new i = 0; i < MAX_PLAYERS; i++)
    {
                if(IsPlayerConnected(i) && (IsACop(i) || IsAFiremen(i))
                {
                    if((PlayerInfo[i][pDuty] == 1 && IsACop(i)) || (IsPlayerAdmin(i) && IsACop(i)))
                    {
                        SetPlayerMarkerForPlayer(i, i, COLOR_YELLOW);
                    }
                    if(JobDuty[i] == 1 && IsAFiremen(i))
                    {
                        SetPlayerMarkerForPlayer(i, i, COLOR_YELLOW);
                    }
                    //GameTextForPlayer(playerid, "~w~Searching for vehicles...", 11000, 5);
                    DispatchAlertVar[i] = SetTimerEx("DispatchAlert",10000,true, "i", i);
                }
            }
pawn Код:
for(new i = 0; i < MAX_PLAYERS; i++)
            {
                if (IsPlayerConnected(i) && (IsACop(i) || (IsAFiremen(i)|| IsPlayerAdmin(i)))
                {
                    KillTimer(DispatchAlertVar[i]);
                    SetPlayerMarkerForPlayer(i, i, TEAM_HIT_COLOR);
                    //GameTextForPlayer(playerid, "~w~DVDS Powering Down......", 1000, 5);
                    GameTextForPlayer(i, "~w~Powering Down...", 11000, 5);
                }
Reply
#5

No thats somthing else you're seeing. Thats for my Police radar display. It's only for the playerid that does the command.

@cessil what exactly does that mean? And how should I fix it then?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)