In need of some assistance on timers
#1

Currently I am revamping a trucking job on my script. With the lack of an OnPlayerAttachTrailer I'm having to use timers as a trailer check, which I'm absolutely horrible at.

The code below is meant to show dialog 43 when the player hooks up a trailer, however, nothing happens. At all. I'm not sure if the timer is being initiated incorrectly, if I'm killing it too early, or if I'm simply coding what happens when the timer runs out wrongly. Whatever it is, I need some help.
pawn Код:
//At the top of my script
forward TC(playerid);
new TrailerCheck[MAX_PLAYERS];
forward LUC(playerid);
new TTLevelUpCheck[MAX_PLAYERS];

//Initiating the timers by command
YCMD:confirmtruck(playerid, params[], help)
{
    if(PlayerInfo[playerid][pJob] == 5)
    {
        new vehicle = GetPlayerVehicleID(playerid);
        if(vehicle == 139 || vehicle == 138 || vehicle == 137)
        {
            TrailerCheck[playerid] = SetTimerEx("TrailerCheck",1000,true,"i",playerid);
            TTLevelUpCheck[playerid] = SetTimerEx("TTLevelUpCheck",1000,true,"i",playerid);
            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)
        {
            TrailerCheck[playerid] = SetTimerEx("TrailerCheck",1000,true,"i",playerid);
            TTLevelUpCheck[playerid] = SetTimerEx("TTLevelUpCheck",1000,true,"i",playerid);
            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)
        {
            TrailerCheck[playerid] = SetTimerEx("TrailerCheck",1000,true,"i",playerid);
            TTLevelUpCheck[playerid] = SetTimerEx("TTLevelUpCheck",1000,true,"i",playerid);
            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;
}

//The bottom of my script
public TC(playerid)
{
    new vehicleid = GetPlayerVehicleID(playerid);
    new trailerid = GetVehicleModel(GetVehicleTrailer(vehicleid));
    if(IsPlayerInAnyVehicle(playerid))
    {
        if(IsTrailerAttachedToVehicle(vehicleid) == 1 && trailerid == 450)//dirttrucks
        {
            KillTimer(TrailerCheck[playerid]);
            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(TrailerCheck[playerid]);
            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(TrailerCheck[playerid]);
            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;
}
public LUC(playerid)
{
    if(PlayerInfo[playerid][pJob] == 5)
    {
        if(PlayerInfo[playerid][pTTSoilLevel] == 3)
        {
            KillTimer(TTLevelUpCheck[playerid]);
            PlayerInfo[playerid][pTTLevel] = 2;
            SendClientMessage(playerid,COLOUR_ORANGE,"Your trucking level has increased, you can now use level 2 trucks!");
        }
        if(PlayerInfo[playerid][pTTFuelLevel] == 3)
        {
            KillTimer(TTLevelUpCheck[playerid]);
            PlayerInfo[playerid][pTTLevel] = 3;
            SendClientMessage(playerid,COLOUR_ORANGE,"Your trucking level has increased, you can now use level 3 trucks!");
        }
        if(PlayerInfo[playerid][pTTSurplusLevel] == 3)
        {
            KillTimer(TTLevelUpCheck[playerid]);
            PlayerInfo[playerid][pTTLevel] += 1;
            SendClientMessage(playerid,COLOUR_ORANGE,"Your trucking level has increased!");
        }
    }
    return 1;
}
Cheers!
Reply
#2

I don't know if you did this on purpose, but the function you are calling in SetTimer doesn't match the function at the bottom of your script.
pawn Код:
SetTimerEx("TrailerCheck" // blah blah

public TC(playerid)
// same thing for the LevelUp function as well.
One is TrailerCheck the function is TC. They have to be the same.

Also, in the command /confirmtruck.
pawn Код:
new vehicle = GetPlayerVehicleID(playerid);
The way you are using it, it should be
pawn Код:
new vehicle = GetVehicleModel(GetPlayerVehicleID(playerid));
Vehicle ID is the server-sided vehicle ID.
Reply
#3

I'm not attempting to fetch the vehicle model in /confirmtruck, what I have is correct.

As for the function names though, if they aren't different, I get:
Quote:

C:\Users\Devon\Desktop\Other\Servers\Devon's Roleplay\gamemodes\AAADevonsRoleplay.pwn(5725) : error 028: invalid subscript (not an array or too many subscripts): "TrailerCheck"
C:\Users\Devon\Desktop\Other\Servers\Devon's Roleplay\gamemodes\AAADevonsRoleplay.pwn(5725) : warning 215: expression has no effect
C:\Users\Devon\Desktop\Other\Servers\Devon's Roleplay\gamemodes\AAADevonsRoleplay.pwn(5725) : error 001: expected token: ";", but found "]"
C:\Users\Devon\Desktop\Other\Servers\Devon's Roleplay\gamemodes\AAADevonsRoleplay.pwn(5725) : error 029: invalid expression, assumed zero
C:\Users\Devon\Desktop\Other\Servers\Devon's Roleplay\gamemodes\AAADevonsRoleplay.pwn(5725) : fatal error 107: too many error messages on one line

Reply
#4

This is urgent, nothing I do helps.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)