Timer doesnt seem to quit the loop.
#1

Okay so i am experiencing problems with killing a timer. For some reason sometimes this function keeps running in an infinite loop. Causing players to lose all of their money. This is my function:
pawn Код:
public Trucker_VehicleTimer(playerid)
{
    new OldVehicleID = APlayerData[playerid][VehicleID];
    new NewVehicleID = GetPlayerVehicleID(playerid);
    new OldTrailerID = APlayerData[playerid][TrailerID];
    new NewTrailerID = GetVehicleTrailer(GetPlayerVehicleID(playerid));

    if (APlayerData[playerid][VehicleTimerTime] != 0)
    {
        // If VehicleID and TrailerID are still the same as when the player accepted the job
        if ((OldVehicleID == NewVehicleID) && (OldTrailerID == NewTrailerID))
            APlayerData[playerid][VehicleTimerTime] = Trucker_TimeToFailMission; // Reset the time before the mission fails
        else // One (or both) aren't still the same (player lost his trailer or vehicle)
        {
            new TimeLeft[5];
            // Reduce the time left by 1
            APlayerData[playerid][VehicleTimerTime] = APlayerData[playerid][VehicleTimerTime] - 1;
            // Convert the time left to a string for displaying
            valstr(TimeLeft, APlayerData[playerid][VehicleTimerTime]);
            // Display the time left
            GameTextForPlayer(playerid, TimeLeft, 1000, 4);
            // Send only one message to inform the player what he must do
            if (APlayerData[playerid][VehicleTimerTime] == (Trucker_TimeToFailMission - 1))
                SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}You must enter your vehicle or re-attach your trailer");
        }
    }
    else
    {
        // Time left has reached 0
        Trucker_EndJob(playerid);
        // If the player is part of a convoy, kick him from it (as he failed his mission, the rest of the convoy would be stuck)
        Convoy_Leave(playerid);
        // Inform the player that he failed the mission
        GameTextForPlayer(playerid, "~w~You ~r~failed~w~ your mission. You lost ~y~$1000~w~ to cover expenses.", 5000, 4);
        GivePlayerCash(playerid, -1000);
        KillTimer(APlayerData[playerid][VehicleTimer]);
    }
}
The timer keeps running. How to stop it when it keeps looping?
Reply
#2

When it's looping is it displaying

pawn Код:
GameTextForPlayer(playerid, "~w~You ~r~failed~w~ your mission. You lost ~y~$1000~w~ to cover expenses.", 5000, 4);
Reply
#3

Yes it did
Reply
#4

Quote:
Originally Posted by thimo
Посмотреть сообщение
Yes it did
Show me the code when you activate the timer please.
Reply
#5

pawn Код:
Dialog_TruckerSelectEndLoc(playerid, response, listitem)
{
    new RouteText[128], loadName[50], startlocName[50], endlocName[50], LoadMsg[128], Float:x, Float:y, Float:z, ProductID;

    if(!response) return 1;

    ProductID = APlayerData[playerid][LoadID];
    // Store the chosen end-location in the player's account
    APlayerData[playerid][JobLoc2] = ALoads[ProductID][ToLocations][listitem];

    // Get the names for the load, startlocation and endlocation
    format(loadName, 50, "%s", ALoads[ProductID][LoadName]);
    format(startlocName, 50, "%s", ALocations[APlayerData[playerid][JobLoc1]][LocationName]);
    format(endlocName, 50, "%s", ALocations[APlayerData[playerid][JobLoc2]][LocationName]);

    // Job has started
    APlayerData[playerid][JobStarted] = true;
    // Store the vehicleID (required to be able to check if the player left his vehicle)
    APlayerData[playerid][VehicleID] = GetPlayerVehicleID(playerid);
    // Store the trailerID (required to be able to check if the player lost his trailer)
    APlayerData[playerid][TrailerID] = GetVehicleTrailer(GetPlayerVehicleID(playerid));
    // Set jobstep to 1 (going to load the goods)
    APlayerData[playerid][JobStep] = 1;
    // Combine all data into a string for the TextDraw (the player can see this all the time) to describe the mission
    format(RouteText, 255, "~w~Hauling ~b~%s~w~ from ~r~%s~w~ to %s", loadName, startlocName, endlocName);
    // Set the TextDraw so the player can see it
    TextDrawSetString(Mission[playerid], RouteText);
    // Grab the x, y, z positions for the first location
    x = ALocations[APlayerData[playerid][JobLoc1]][LocX];
    y = ALocations[APlayerData[playerid][JobLoc1]][LocY];
    z = ALocations[APlayerData[playerid][JobLoc1]][LocZ];
    // Create a checkpoint where the player should load the goods
    SetPlayerCheckpoint(playerid, x, y, z, 7);
    // Start a timer that ticks every second to see if the player is still inside his vehicle
    APlayerData[playerid][VehicleTimerTime] = Trucker_TimeToFailMission;
    APlayerData[playerid][VehicleTimer] = SetTimerEx("Trucker_VehicleTimer", 1000, true, "d" , playerid);
    // Inform the player that he must load his goods
    format(LoadMsg, 128, "{00FF00}Pickup the %s at %s", loadName, startlocName);
    SendClientMessage(playerid, 0xFFFFFFFF, LoadMsg);

    return 1;
}
It also gets called when you start a convoy job.
Reply
#6

That's very strange because if the message is being displayed and the money is being taken the KillTimer is in the same place so therefore should be killing the timer. I'll have to pass on this one I am stumped!
Reply
#7

Yes and it happens quite often. I don't understand this at all. Its being killed but still running :S
Reply
#8

Anyone help? Please
Reply
#9

pawn Код:
public Trucker_VehicleTimer(playerid)
{
    static continueRun[MAX_PLAYERS];
    if(!continueRun[playerid])
    {
        new OldVehicleID = APlayerData[playerid][VehicleID];
        new NewVehicleID = GetPlayerVehicleID(playerid);
        new OldTrailerID = APlayerData[playerid][TrailerID];
        new NewTrailerID = GetVehicleTrailer(GetPlayerVehicleID(playerid));

        if (APlayerData[playerid][VehicleTimerTime] != 0)
        {
            // If VehicleID and TrailerID are still the same as when the player accepted the job
            if ((OldVehicleID == NewVehicleID) && (OldTrailerID == NewTrailerID))
                APlayerData[playerid][VehicleTimerTime] = Trucker_TimeToFailMission; // Reset the time before the mission fails
            else // One (or both) aren't still the same (player lost his trailer or vehicle)
            {
                new TimeLeft[5];
                // Reduce the time left by 1
                APlayerData[playerid][VehicleTimerTime] = APlayerData[playerid][VehicleTimerTime] - 1;
                // Convert the time left to a string for displaying
                valstr(TimeLeft, APlayerData[playerid][VehicleTimerTime]);
                // Display the time left
                GameTextForPlayer(playerid, TimeLeft, 1000, 4);
                // Send only one message to inform the player what he must do
                if (APlayerData[playerid][VehicleTimerTime] == (Trucker_TimeToFailMission - 1))
                    SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}You must enter your vehicle or re-attach your trailer");
            }
        }
        else
        {
            // Time left has reached 0
            Trucker_EndJob(playerid);
            // If the player is part of a convoy, kick him from it (as he failed his mission, the rest of the convoy would be stuck)
            Convoy_Leave(playerid);
            // Inform the player that he failed the mission
            GameTextForPlayer(playerid, "~w~You ~r~failed~w~ your mission. You lost ~y~$1000~w~ to cover expenses.", 5000, 4);
            GivePlayerCash(playerid, -1000);
            KillTimer(APlayerData[playerid][VehicleTimer]);
            continueRun[playerid] = 1;
        }
    }
    else
    {
        KillTimer(APlayerData[playerid][VehicleTimer]);
    }
}
This should end the looping problem, try to print(str[]); to debug it if it still runs after getting killed twice.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)