31.08.2013, 12:34
(
Последний раз редактировалось MechaTech; 31.08.2013 в 13:05.
)
Hello guys,
I've a problem with a fuel system, I've used somebody's fuel system filterscript and made it a bit 'advanced'. I'm trying to make it so the fuel will decrease whenever the engine is on. It doesn't matter if you are inside the vehicle or not.
First problem:
When I'm going to start the gamemode and log in the server. Then I'm going to enter the vehicle and turn the engine on, the fuel itself decreases in the background, but it doesn't update the textdraw. So I am going to exit the vehicle and re-enter it, and then suddenly it works perfectly. The textdraw updates itself and the fuel decreases.
Second problem:
The fuel is only decreasing when I am inside the vehicle and the engine is on, but if I am going to exit the vehicle, leaving the engine on. The fuel wont decrease and it will just pauze. When I enter the vehicle again it will decrease again. But the fuel should decrease even if I am out of the vehicle and the engine is on.
EDIT!!!!!: I've fixed those two problem, but now it gives me 1 other bug. When I am turning the engine on it will decrease the fuel for all vehicles. But it just needs to decrease the fuel for the vehicle where the engine is turned ON.
Here is the whole fuel and engine script:
I've a problem with a fuel system, I've used somebody's fuel system filterscript and made it a bit 'advanced'. I'm trying to make it so the fuel will decrease whenever the engine is on. It doesn't matter if you are inside the vehicle or not.
First problem:
When I'm going to start the gamemode and log in the server. Then I'm going to enter the vehicle and turn the engine on, the fuel itself decreases in the background, but it doesn't update the textdraw. So I am going to exit the vehicle and re-enter it, and then suddenly it works perfectly. The textdraw updates itself and the fuel decreases.
Second problem:
The fuel is only decreasing when I am inside the vehicle and the engine is on, but if I am going to exit the vehicle, leaving the engine on. The fuel wont decrease and it will just pauze. When I enter the vehicle again it will decrease again. But the fuel should decrease even if I am out of the vehicle and the engine is on.
EDIT!!!!!: I've fixed those two problem, but now it gives me 1 other bug. When I am turning the engine on it will decrease the fuel for all vehicles. But it just needs to decrease the fuel for the vehicle where the engine is turned ON.
Here is the whole fuel and engine script:
pawn Код:
new engine,lights,alarm,doors,bonnet,boot,objective;
new EngineTimer[MAX_PLAYERS];
new fuel[MAX_VEHICLES];
forward timer_fuel_lower();
forward timer_refuel(playerid);
new isrefuelling[MAX_PLAYERS] = 0;
new Text:td_fuel[MAX_PLAYERS];
forward StartEngine(playerid);
pawn Код:
public OnGameModeInit()
{
ManualVehicleEngineAndLights();
for(new i=0;i<MAX_VEHICLES;i++)
{
fuel[i] = 100;
}
SetTimer("timer_fuel_lower",400,true);
}
pawn Код:
public OnVehicleSpawn(vehicleid)
{
SetVehicleParamsEx(GetPlayerVehicleID(vehicleid),0,lights,alarm,doors,bonnet,boot,objective);
fuel[vehicleid] = 100;
return 1;
}
pawn Код:
public OnVehicleDeath(vehicleid, killerid)
{
EngineTimer[vehicleid] = 0;
return 1;
}
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
td_fuel[playerid]= TextDrawCreate( 198.392517, 425.833618, "Fuel~r~: ");
TextDrawLetterSize(td_fuel[playerid], 0.181537, 1.133334);
TextDrawAlignment( td_fuel[playerid], 1);
TextDrawColor( td_fuel[playerid], -16711681);
TextDrawSetShadow( td_fuel[playerid], 1);
TextDrawSetOutline( td_fuel[playerid], 0);
TextDrawBackgroundColor( td_fuel[playerid], 255);
TextDrawFont( td_fuel[playerid], 2);
TextDrawSetProportional( td_fuel[playerid], 1);
return 1;
}
pawn Код:
public OnPlayerExitVehicle(playerid, vehicleid)
{
TextDrawHideForPlayer(playerid,td_fuel[playerid]);
return 1;
}
pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if (newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)
{
new vid = GetPlayerVehicleID(playerid);
new string[125];format(string,sizeof string,"Fuel: ~r~%i~g~ pcnt",fuel[vid]);
TextDrawSetString(td_fuel[playerid],string);
TextDrawShowForPlayer(playerid,td_fuel[playerid]);
}
else
{
TextDrawHideForPlayer(playerid,td_fuel[playerid]);
}
return 1;
}
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(PRESSED(KEY_HANDBRAKE))
{
if(GetPlayerState(playerid)==PLAYER_STATE_DRIVER && IsAValidVehicle(GetPlayerVehicleID(playerid)))
{
new vid = GetPlayerVehicleID(playerid);
if (fuel[vid]<1)
{
SendClientMessage(playerid, COLOR_GREY, "This vehicle is out of fuel!");
return 0;
}
else if(EngineTimer[playerid] == 0)
{
GetVehicleParamsEx(GetPlayerVehicleID(playerid),engine,lights,alarm,doors,bonnet,boot,objective);
if(engine<=0)
{
SetTimerEx("StartEngine", 2000, 0, "i", playerid);
GameTextForPlayer(playerid, "~g~Starting Engine...", 1700, 5);
EngineTimer[playerid] = 1;
return 1;
}
else
{
return 1;
}
}
}
}
return 1;
}
pawn Код:
public timer_fuel_lower()
{
for(new i=0;i<MAX_PLAYERS;i++)
{
if (isrefuelling[i]) continue;
new vid = GetPlayerVehicleID(i);
GetVehicleParamsEx(GetPlayerVehicleID(vid),engine,lights,alarm,doors,bonnet,boot,objective);
if(engine>=1)
{
if(fuel[i] >= 1)
{
fuel[i]--;
}
else if (fuel[vid]<1)
{
fuel[vid] = 0;
SetVehicleParamsEx(vid,false,0,0,0,0,0,0);
if(IsPlayerInVehicle(i, vid))
{
GameTextForPlayer(i,"~r~The vehicle ran out of ~w~fuel~r~!",5000,4);
}
}
}
new string[125];format(string,sizeof string,"Fuel: ~r~%i~g~ pcnt",fuel[vid]);
TextDrawSetString(td_fuel[i],string);
}
return 1;
}
pawn Код:
public StartEngine(playerid)
{
new string[124];
new name[MAX_PLAYER_NAME];
EngineTimer[playerid] = 0;
GetPlayerName(playerid, name, sizeof(name));
GameTextForPlayer(playerid, "~g~Engine on", 2000, 5);
SetVehicleParamsEx(GetPlayerVehicleID(playerid),1,lights,alarm,doors,bonnet,boot,objective);
format(string,sizeof(string),"* %s has turned the %s's engine ON. *", name, VehicleNames[GetVehicleModel(GetPlayerVehicleID(playerid))-400]);
ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
return 1;
}