Fuel System - Help -
luis_lpv_22 - 28.11.2011
Hi All, I'm making a fuel system.
I have a "Fuel consumption" timer for all vehicles. When vehicle's fuel is out, it must stop the engine of this vehicle, but it stops all engines.
pawn Код:
public FuelConsumption(vehicleid)
{
for(new i=0;i<MAX_VEHICLES;i++)
{
// bla bla...
VehicleGas -= 1;
if(VehicleGas[i] == 0) SetVehicleParamsEx(i, VEHICLE_PARAMS_OFF, lights, alarm, doors, bonnet, boot, objective);
// blaa..
}
}
Some suggests?
Thanks you in advance
PD: Sorry for my bad english.
Re: Fuel System - Help -
Jake__ - 28.11.2011
Bro. With this line:
for(new i=0;i<MAX_VEHICLES;i++)
You're telling the script to read from vehicles, not players.
Where here:
SetVehicleParamsEx(i, VEHICLE_PARAMS_OFF, lights, alarm, doors, bonnet, boot, objective);
You're also telling the script to read from vehicles, not players.
The reason being is because i, in this code, stands for max_vehicles, not for max_players.
So you need to probably do this:
Код:
#include <a_samp>
forward FuelConsumption();
public FuelConsumption()
{
for(new i=0;i<MAX_VEHICLES;i++)
{
VehicleGas -= 1;
if(VehicleGas[i] == 0)
{
for(new playerid; playerid < MAX_PLAYERS; playerid++)
{
SetVehicleParamsEx(playerid, VEHICLE_PARAMS_OFF, lights, alarm, doors, bonnet, boot, objective);
}
}
}
return 1; // Not really sure if yours is a timer or what, don't return this value if you don't need to in your code.
}
Respuesta: Fuel System - Help -
luis_lpv_22 - 28.11.2011
Thanks for your reply but I tested it and don't works.
More suggests?
Re: Fuel System - Help -
Unte99 - 28.11.2011
Why do you use this
pawn Код:
for(new i=0;i<MAX_VEHICLES;i++)
if you have a static "vehicleid" in your public function ?
Re: Fuel System - Help -
CONTROLA - 28.11.2011
pawn Код:
public OnGameModeInit()
{
//things
SetTimer("FuelConsumption", 5000, true);
return 1;
}
new VehicleGas[MAX_VEHICLES];
forward FuelConsumption();
public FuelConsumption()
{
for(new i=0;i<MAX_PLAYERS;i++)
{
GetVehicleParamsEx(vehgas,engine,lights,alarm,doors,bonnet,boot,objective);
if(IsPlayerInAnyVehicle(i)) {} else return 1;
new vehgas = GetPlayerVehicleID(i);
VehicleGas[vehgas] -= 1;
if(VehicleGas[vehgas] >= 0) SetVehicleParamsEx(vehgas, VEHICLE_PARAMS_OFF, lights, alarm, doors, bonnet, boot, objective);
}
return 1;
}
Re: Fuel System - Help -
Unte99 - 28.11.2011
Before you set the params, you have to get the params:
pawn Код:
GetVehicleParamsEx(vehgas,engine,lights,alarm,doors,bonnet,boot,objective);
SetVehicleParamsEx(vehgas, 0, lights, alarm, doors, bonnet, boot, objective);