stock StopRefueling(playerid) [TIMER BUG]
#1

Well..I found a bug..When someones goes to refuel his vehicle and types /refuel then it appears a message saying.."Your vehicle's tank has been refilled for $100.". The problem is that the script doesn't send this message ONCE (+ takes 100$ once) but it doesn't stop say: "Your vehicle's tank has been refilled for $100." <= It spams you and it takes all your money..How can I fix it?

Код:
stock StopRefueling(playerid)
{
    GivePlayerCash(playerid, -100);
    SendFormattedMessage(playerid, COLOR_WHITE,"Your vehicle's tank has been refilled for $100.");

    new mypoint = -1;
    for (new i=0; i<MAX_POINTS; i++)
    {
        if(strcmp(Points[i][Name], "Fossil Fuel Company", true) == 0)
        {
            mypoint = i;
        }
    }
    for(new i = 0; i < sizeof(FamilyInfo); i++)
    {
        if(strcmp(Points[mypoint][Owner], FamilyInfo[i][FamilyName], true) == 0)
        {
            FamilyInfo[i][FamilyBank] = FamilyInfo[i][FamilyBank]+(RefuelingVehiclePrice[playerid]/10);
        }
    }

    RefuelingVehicle[playerid] = 0; RefuelingVehiclePrice[playerid] = 0; KillTimer(RefuelingVehicleTimer[playerid]); // should i remove this???!!!
    return true;
}
Reply
#2

Where do you use it?
Reply
#3

What do you mean?

Here?
Код:
CMD:refuel(playerid, params[])
{
    if(IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
	{
	    new vehicleid = GetPlayerVehicleID(playerid);
		new RefuelingVehicleSlot = -1;
	    new engine,lights,alarm,doors,bonnet,boot,objective;
    	GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
	    if(engine == VEHICLE_PARAMS_ON) return SendClientMessageEx(playerid, COLOR_RED, "You need to shut off the engine before filling up (/car engine).");
	    if(!IsAtFuelStation(playerid)) return SendClientMessageEx(playerid, COLOR_RED, "You're not at a fuel station.");
	    if(GetVehicleModel(vehicleid) == 481 || GetVehicleModel(vehicleid) == 509 || GetVehicleModel(vehicleid) == 510) return SendClientMessageEx(playerid,COLOR_RED,"This vehicle doesn't need fuel.");
	    if(VehicleFuel[vehicleid] >= 100.0) return SendClientMessageEx(playerid, COLOR_RED, "This vehicle's tank is already full.");
	    if(RefuelingVehicle[playerid] == 1) return SendClientMessageEx(playerid, COLOR_RED, "You are refilling your vehicle's tank.");
       	SendClientMessageEx(playerid, COLOR_WHITE, "Refueling your vehicle's tank, please wait.");
       	RefuelingVehicle[playerid] = 1;

		for(new vehicleslot = 0; vehicleslot < MAX_PLAYERVEHICLES; vehicleslot++)
		{
			if(IsPlayerInVehicle(playerid, PlayerVehicleInfo[playerid][vehicleslot][pvId]))
			{
				RefuelingVehicleSlot = vehicleslot;
			}
		}
       	RefuelingVehicleTimer[playerid] = SetTimerEx("ReFill", 1000, true, "ii", playerid, RefuelingVehicleSlot);
	}
	return 1;
}
Reply
#4

Someone?
Reply
#5

The problem is with the timer: ReFill callback. It gets called every second (repeated). If in that callback, you give the fuel at once, then the timer shouldn't be repeated:
pawn Код:
RefuelingVehicleTimer[playerid] = SetTimerEx("ReFill", 1000, false, "ii", playerid, RefuelingVehicleSlot);
Else if you give the fuel to the player's vehicle again and again until it reaches the max fuel value, that's the part you should stop the timer (the timer ID has been stored in RefuelingVehicleTimer[playerid]).
Reply
#6

This will kill a repeated timer (like yours):

pawn Код:
KillTimer(RefuelingVehicleTimer[playerid]);
But in your case, it would make more since not to have the timer repeat:

pawn Код:
SetTimerEx("ReFill", 1000, false, "ii", playerid, RefuelingVehicleSlot);//False means it won't repeat every 1000ms/1sec
So, when you make it not repeat, you won't need this part either (as it's used for killing a repeated timer):
pawn Код:
RefuelingVehicleTimer[playerid]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)