PDA

View Full Version : [HELP] Fuel problem!!


catal4n
07/12/2016, 09:47 AM
Alright, hello dear scripters, i had a big problem about my fuel system. The fact is fuel is going down even if the engine is on or off also if a driver is in or not. Here are the codes for fuel. Any ideas or any help? Thanks i will rep you guys if you help me fixing this. Have a nice day.

forward FuelTimer();
public FuelTimer()
{
for(new vehid=0; vehid < MAX_VEHICLES; vehid++)
{
new enginec, lightsc, alarmc, doorsc, bonnetc, bootc, objectivec;
GetVehicleParamsEx(vehid, enginec, lightsc, alarmc, doorsc, bonnetc, bootc, objectivec);
if(enginec && Fuel[vehid])
{
FuelVar[vehid] ++;
if(GetVehicleSpeed(vehid, 0) != 0 && FuelVar[vehid] >= 72/2)
{
FuelVar[vehid] = 0;
Fuel[vehid] --;
}
else if(GetVehicleSpeed(vehid, 0) == 0 && FuelVar[vehid] >= 108/2)
{
FuelVar[vehid] = 0;
Fuel[vehid] --;
}
}
}
return 1;
}

Logic_
07/12/2016, 09:56 AM
Show us your engine command or how you close the engine?

EDIT: Also,
http://wiki.sa-mp.com/wiki/SetVehicleParamsEx
since 0.3a you will have to reapply this function when OnVehicleStreamIn is called.

EDIT 2:
Optimized version of the code can be...


// top of the script
native IsValidVehicle(vehicleid);

// somewhere in the script
forward FuelTimer();
public FuelTimer()
{
for(new vehid, veh = GetVehiclePoolSize(); vehid <= veh; vehid++)
{
if(IsValidVehicle(vehid))
{
new enginec, lightsc, alarmc, doorsc, bonnetc, bootc, objectivec;
GetVehicleParamsEx(vehid, enginec, lightsc, alarmc, doorsc, bonnetc, bootc, objectivec);
if(enginec)
{
if(Fuel[vehid] > 0)
{
if(GetVehicleSpeed(vehid, 0) != 0)
{
FuelVar[vehid] ++;
if(FuelVar[vehid] >= 72/2)
{
FuelVar[vehid] = 0;
Fuel[vehid] --;
}
else if(FuelVar[vehid] >= 108/2)
{
FuelVar[vehid] = 0;
Fuel[vehid] --;
}
}
}
}
}
}
return 1;
}

catal4n
07/12/2016, 10:20 AM
C:\Users\eMachines\Desktop\SAMP\GAMEMODES FOR UGRP\CGRP\gamemodes\G-RP1.pwn(102745) : error 017: undefined symbol "GetVehiclePoolSize"
Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase


1 Error.

catal4n
07/12/2016, 10:33 AM
Instead of for(new vehid, veh = GetVehiclePoolSize(); vehid <= veh; vehid++)

i used for(new vehid=0; vehid < MAX_VEHICLES; vehid++)

And now it works thank you very much.