26.03.2013, 16:59
(
Последний раз редактировалось EiresJason; 21.03.2015 в 15:47.
)
Hi, i have been trying to get this to work for ages now and i just don't think i can actually progress on it xD
I was wondering if anyone could help me out please;
My problem is that I want a vehicles 'fuel' to lower as long as the engine is running. I currently have it so that if you're in the vehicle and the engine is on, the fuel lowers but i want it so that if you're in the vehicle or not in the vehicle, the fuel lowers. (Basically just as long as the engine is running and theres more than 0 fuel).
It seems if i get one part working; the other part fails
Also, when the fuel hits 0; the engine turns off but if i type /e(my cmd to start the engine), it will run for a second as if it had like 1fuel leftover. I also tried to tweak this but everything else stopped lol
If anyone could help me out it would be awesome Thanks to anyone who replies;
ALL RELATED CODE:
code in OnGameModeInit
This is my /engine command. I say /e above because i just return /engine if the user types /e.
Thanks to anyone who can help really This has been driving me crazy.
I was wondering if anyone could help me out please;
My problem is that I want a vehicles 'fuel' to lower as long as the engine is running. I currently have it so that if you're in the vehicle and the engine is on, the fuel lowers but i want it so that if you're in the vehicle or not in the vehicle, the fuel lowers. (Basically just as long as the engine is running and theres more than 0 fuel).
It seems if i get one part working; the other part fails
Also, when the fuel hits 0; the engine turns off but if i type /e(my cmd to start the engine), it will run for a second as if it had like 1fuel leftover. I also tried to tweak this but everything else stopped lol
If anyone could help me out it would be awesome Thanks to anyone who replies;
ALL RELATED CODE:
pawn Код:
new bool:ISENGINEON = false;
new fuel[MAX_VEHICLES]; //fuel per vehicle
forward timer_fuel_lower(playerid); //timer for lowering the fuel value
forward timer_refuel(playerid); //timer to refuel vehicle
new isrefuelling[MAX_PLAYERS] = 0; //bool to check if player is already refuelling
new Text:td_fuel[MAX_PLAYERS]; //textdraw with fuel
pawn Код:
for(new i=0;i<MAX_VEHICLES;i++)
{
fuel[i] = 100; //sets every car's fuel to 100 in a loop
}
SetTimer("timer_fuel_lower",1000,true); //sets the timer to drop the fuel
pawn Код:
public timer_fuel_lower()
{
for(new i=0;i<MAX_PLAYERS;i++) { //loop for all players
if (isrefuelling[i]) continue; //stop when a player is already refuelling
new vid = GetPlayerVehicleID(i); //getting vehicle ID
new engine,lights,alarm,doors,bonnet,boot,objective;
GetVehicleParamsEx(vid,engine,lights,alarm,doors,bonnet,boot,objective);
if(engine == 1)
{
//if (GetPlayerVehicleSeat(i) == 0) { //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] == 0) //if fuel is empty
{
engine = 0;
SetVehicleParamsEx(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)
//RemovePlayerFromVehicle(i); //remove player out of vehicle
GameTextForPlayer(i,"~r~You are out of ~w~fuel~r~!",5000,4); //show text
//new string[125];format(string,sizeof string,"Fuel:%i",fuel[vid]); //preparing string with next fuel value
//TextDrawSetString(td_fuel[i],string); //updating textdraw
}
}
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;
}
public timer_refuel(playerid)
{
new vid = GetPlayerVehicleID(playerid);
fuel[vid] = fuel[vid] = 100; //restoring fuel to 100
isrefuelling[playerid] = 0;//resetting anti-spam thingy :3
TextDrawSetString(td_fuel[playerid],"Fuel:100"); //small update on textdraw
TogglePlayerControllable(playerid,1); //unfreeze player
}
pawn Код:
CMD:engine(playerid, params[])
{
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)//Checks if the player is the driver
{
new string[128];
new vehicle = GetPlayerVehicleID(playerid);
new engine,lights,alarm,doors,bonnet,boot,objective;
GetVehicleParamsEx(vehicle,engine,lights,alarm,doors,bonnet,boot,objective);
if(engine == 1)//If the engine is off
{
format(string, sizeof(string), "%s turns the key in the ignition, turning the engine off.", GetName(playerid), params);
ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
SetVehicleParamsEx(vehicle,0,0,alarm,doors,bonnet,boot,objective);
ISENGINEON =false;
}
else//Else is the engine is on
{
SetVehicleParamsEx(vehicle,1,0,alarm,doors,bonnet,boot,objective);
format(string, sizeof(string), "%s places the key in the vehicles ignition and turns it, starting the engine.", GetName(playerid), params);
ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
ISENGINEON = true;
}
}
return 1;
}