[HELP] Fuel problem!!
#1

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;
}
Reply
#2

Show us your engine command or how you close the engine?

EDIT: Also,
https://sampwiki.blast.hk/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...

PHP код:
// top of the script
native IsValidVehicle(vehicleid);
// somewhere in the script
forward FuelTimer();
public 
FuelTimer()
{
    for(new 
vehidveh GetVehiclePoolSize(); vehid <= vehvehid++)
    {
        if(
IsValidVehicle(vehid))
        {
            new 
engineclightscalarmcdoorscbonnetcbootcobjectivec;
            
GetVehicleParamsEx(vehidengineclightscalarmcdoorscbonnetcbootcobjectivec);
            if(
enginec)
            {
                if(
Fuel[vehid] > 0)
                {
                    if(
GetVehicleSpeed(vehid0) != 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;

Reply
#3

Код:
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 © 1997-2006, ITB CompuPhase


1 Error.
Reply
#4

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)