Custom Fuel system taking 2 fuel instead of 1. -
ricardo178 - 28.05.2012
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;
}
Re: Custom Fuel system taking 2 fuel instead of 1. -
Vince - 28.05.2012
SetTimerEx.
Re: Custom Fuel system taking 2 fuel instead of 1. -
Face9000 - 28.05.2012
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.
Re: Custom Fuel system taking 2 fuel instead of 1. -
iGetty - 28.05.2012
Also; you want to define the variable for the timer name. So then you can kill it when the player get's out.
Re: Custom Fuel system taking 2 fuel instead of 1. -
milanosie - 28.05.2012
SetTimer is a global timer for every player,
Use SetTimerEx instead to only set it for the player,
Re: Custom Fuel system taking 2 fuel instead of 1. -
ricardo178 - 28.05.2012
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.
Re: Custom Fuel system taking 2 fuel instead of 1. -
Zaer0 - 27.04.2013
awesome