Some Timer Help
#1

On a trucking job I'm working on, I'm having to show a dialog when a player hooks up his trailer. In the case of the code below, if more than one player is doing the job then the timers do not kill correctly. The command below starts the timer.
pawn Код:
YCMD:confirmtruck(playerid, params[], help)
{
    if(PlayerInfo[playerid][pJob] == 5)
    {
        TTTimer1 = SetTimerEx("TrailerCheck",1000,true,"i",playerid);
        TTTimer2 = SetTimerEx("TTLevelUpCheck",1000,true,"i",playerid);
        new vehicle = GetPlayerVehicleID(playerid);
        if(vehicle == 139 || vehicle == 138 || vehicle == 137)
        {
            PlayerInfo[playerid][pIsWorking] = 1;
            Ccp[playerid] = 16;
            SetPlayerCheckpoint(playerid,52.5144,-270.2235,1.6817,5.0);
            SendClientMessage(playerid,COLOUR_ORANGE,"Pick up a load at the factory in Blue Berry Acres.");
            TogglePlayerControllable(playerid,1);
        }
        else if(vehicle == 88 || vehicle == 87 || vehicle == 86)
        {
            PlayerInfo[playerid][pIsWorking] = 1;
            Ccp[playerid] = 17;
            SetPlayerCheckpoint(playerid,-1029.0247,-654.1725,32.0078, 5.0);
            SendClientMessage(playerid,COLOUR_ORANGE,"Pick up your fuel at Red County Oil Processing.");
            TogglePlayerControllable(playerid,1);
        }
        else if(vehicle == 85 || vehicle == 84 || vehicle == 83)
        {
            PlayerInfo[playerid][pIsWorking] = 1;
            Ccp[playerid] = 18;
            SetPlayerCheckpoint(playerid,2794.7849,-1602.4868,10.9287, 5.0);
            SendClientMessage(playerid,COLOUR_ORANGE,"Pick up your surplus at the Sprunk Factory..");
            TogglePlayerControllable(playerid,1);
        }
        else
        {
            SendClientMessage(playerid,COLOUR_RED,"Enter an available truck first!");
        }
    }
    else
    {
        SendClientMessage(playerid,COLOUR_RED,"Truckers only!");
    }
    return 1;
}
And I'm attempting to kill it once the timer finds that a player has attached a trailer, which works, but as stated earlier only for the first person to type the above command. Other players will get the dialog when they hook up but the timer does not kill and the dialog continues to reappear and reappear.

pawn Код:
public TrailerCheck(playerid)
{
    new vehicleid = GetPlayerVehicleID(playerid);
    new trailerid = GetVehicleModel(GetVehicleTrailer(vehicleid));
    if(IsPlayerInAnyVehicle(playerid))
    {
        if(IsTrailerAttachedToVehicle(vehicleid) == 1 && trailerid == 450)//dirttrucks
        {
            KillTimer(TTTimer1);
            ShowPlayerDialog(playerid,42,DIALOG_STYLE_LIST,"Available Destinations","Blueberry to Flint County Farm\nBlueberry to the Cemetary\nBlueberry to the Stadium","Select","Cancel");
        }
        else if(IsTrailerAttachedToVehicle(vehicleid) == 1 && trailerid == 584)//fueltrucks
        {
            KillTimer(TTTimer1);
            ShowPlayerDialog(playerid,43,DIALOG_STYLE_LIST,"Available Destinations","Red County to Flint County\nRed County to Vinewood\nRed County to Idlewood","Select","Cancel");
        }
        else if(IsTrailerAttachedToVehicle(vehicleid) == 1 && trailerid == 435)//surplustrucks
        {
            KillTimer(TTTimer1);
            ShowPlayerDialog(playerid,44,DIALOG_STYLE_LIST,"Available Destinations","East Beach to Flint County\nEach Beach to Vinewood\nEast Beach to Idlewood","Select","Cancel");
        }
    }
    return 1;
}
I have tried following Ivex's post here: https://sampforum.blast.hk/showthread.php?tid=166479 and nothing changed. Any ideas?
Reply
#2

Change the TTTimer1 and TTTimer2 to a array like TTTimer1[MAX_PLAYERS];
Because now you are killing the timer not for only one player, but for all players who are using this function at that moment.

[EDIT] I hope it works, because I'm going to sleep, so I cannot help to untill tomorrow.
Reply
#3

Quote:
Originally Posted by Roel
Посмотреть сообщение
Change the TTTimer1 and TTTimer2 to a array like TTTimer1[MAX_PLAYERS];
Because now you are killing the timer not for only one player, but for all players who are using this function at that moment.

[EDIT] I hope it works, because I'm going to sleep, so I cannot help to untill tomorrow.
Yep, why wouldn't it.

Add TTimer[MAX_PLAYERS]; at the top of the script, then just do TTimer[playerid]=SetTimerEx.... in the command and KillTimer(TTimer[playerid]);.
Reply
#4

Yes that's what I done

Quote:

I have tried following Ivex's post here: https://sampforum.blast.hk/showthread.php?tid=166479 and nothing changed. Any ideas?

and it didn't work. I'll try it again.

Edit: seems to have, thanks a lot!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)