public timer_fuel_lower()
{
new engine, lights, alarm, doors, bonnet, boot, objective;
for(new i=0;i<MAX_PLAYERS;i++) { //loop for all players
new PlayerVehicle = GetVehicleFileID(GetPlayerVehicleID(i));
if (isrefuelling[i]) continue; //stop when a player is already refuelling
new vid = GetPlayerVehicleID(i); //getting vehicle ID
if (GetPlayerVehicleSeat(i) == 0 && EngineOn[vid] == 1 || IsPlayerInHotWiredCar == 1 || Vehicles[PlayerVehicle][CarGroup] >= 0 && Vehicles[PlayerVehicle][CarGroup] == Player[i][Group]) { //if the player is a driver (it should only lower the fuel when theres an driver!)
fuel[vid] = fuel[vid] -1; //lowering fuel value
if (fuel[vid]<1) //if fuel is empty
{
GetVehicleParamsEx(vid, engine, lights, alarm, doors, bonnet, boot, objective);
fuel[vid] = 0; //setting fuel to 0 (else the timer will set it to -1 -2 -3 etc before removing player)
SetVehicleParamsEx(vid, 0, lights, alarm, doors, bonnet, boot, 0);
SendClientMessage(i, WHITE, "This vehicle is out of fuel");
}
}
new string[125];format(string,sizeof string,"Fuel:%i",fuel[vid]); //preparing string with next fuel value
TextDrawSetString(td_fuel[i],string); //updating textdraw
}
return 1;
}
hmm what about looping through all the vehicles and check if they have no drivers/passengers then lower their fuel?
|
// use this to check if a vehicle has drivers/passengers
stock DoesVehHasDriversOrPassengers(vehicleid)
{
for(new p = 0; p < MAX_PLAYERS; p++)
{
if(GetPlayerState(p) == PLAYER_STATE_DRIVER || GetPlayerState(p) == PLAYER_STATE_PASSENGER)
{
if(GetPlayerVehicleID(p) == vehicleid)
{
return 1;
}
}
}
return 0;
}
// This code checks if a vehicle has no drivers/passengers then lowers its fuel
for(new veh = 0; veh < MAX_VEHICLES; veh ++)
{
if(!DoesVehHasDriversOrPassengers(veh))
{
fuel[veh] --;
}
}
yea sure
pawn Код:
|
// use this to check if a vehicle has drivers/passengers
stock DoesVehHasDriversOrPassengers(vehicleid)
{
for(new p = 0; p < MAX_PLAYERS; p++)
{
if(GetPlayerState(p) == PLAYER_STATE_DRIVER || GetPlayerState(p) == PLAYER_STATE_PASSENGER)
{
if(GetPlayerVehicleID(p) == vehicleid)
{
return 1;
}
}
}
return 0;
}
// This code checks if a vehicle has no drivers/passengers then lowers its fuel
for(new veh = 0; veh < MAX_VEHICLES; veh ++)
{
if(!DoesVehHasDriversOrPassengers(veh))
{
if(EngineIsOn[veh] == 1)
{
fuel[veh] --;
}
}
}