Custom Fuel system taking 2 fuel instead of 1.
#1

Hello there. I made my own fuel system, very simple. I have set a timer under OnPlayerEnterVehicle, that leads to function CFuel every 2 Minutes. That works, but, than, it loses 2 fuel, instead of 1...

Here is the code:

pawn Код:
Under OnPlayerStateChange, after checking if player is in vehicle...

SetTimer("CFuel", 120000, true);

Than, the function..

forward CFuel(playerid);
public CFuel(playerid)
{
    new vid;
    vid = GetPlayerVehicleID(playerid);
    format(file, sizeof(file), "RRP/vehicles/%d.ini", vid);
    if(fexist(file))
    {
        if(dini_Int(file, "Fuel") <= 0)
        {
            SendClientMessage(playerid, COLOR_LIGHTRED, "You are out of fuel.");
            GetVehicleParamsEx(vid,engine,lights,alarm,doors,bonnet,boot,objective);
            SetVehicleParamsEx(vid,false,lights,alarm,doors,bonnet,boot,objective);
            return 1;
        }
        if(dini_Int(file, "Fuel") <= 100)
        {
            dini_IntSet(file, "Fuel", dini_Int(file, "Fuel")-1);
            return 1;
        }
        return 1;
    }
    return 1;
}
Reply
#2

SetTimerEx.
Reply
#3

pawn Код:
if(dini_Int(file, "Fuel") == 0)
        {
            SendClientMessage(playerid, COLOR_LIGHTRED, "You are out of fuel.");
            GetVehicleParamsEx(vid,engine,lights,alarm,doors,bonnet,boot,objective);
            SetVehicleParamsEx(vid,false,lights,alarm,doors,bonnet,boot,objective);
            return 1;
        }
        if(dini_Int(file, "Fuel") <= 100)
        {
            dini_IntSet(file, "Fuel", dini_Int(file, "Fuel")-=1);
            return 1;
        }
Try it,idk if works.
Reply
#4

Also; you want to define the variable for the timer name. So then you can kill it when the player get's out.
Reply
#5

SetTimer is a global timer for every player,

Use SetTimerEx instead to only set it for the player,
Reply
#6

Thanks guys. I fixed it.. The problem was i setted the timmer before checking if player is inside vehicle, so it probably was setting everytime player state change.
Reply
#7

awesome
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)