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);
public OnGameModeInit()
{
ManualVehicleEngineAndLights();
for(new i=0;i<MAX_VEHICLES;i++)
{
fuel[i] = 100;
}
SetTimer("timer_fuel_lower",400,true);
}
public OnVehicleSpawn(vehicleid)
{
SetVehicleParamsEx(GetPlayerVehicleID(vehicleid),0,lights,alarm,doors,bonnet,boot,objective);
fuel[vehicleid] = 100;
return 1;
}
public OnVehicleDeath(vehicleid, killerid)
{
EngineTimer[vehicleid] = 0;
return 1;
}
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;
}
public OnPlayerExitVehicle(playerid, vehicleid)
{
TextDrawHideForPlayer(playerid,td_fuel[playerid]);
return 1;
}
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;
}
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;
}
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;
}
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;
}
forward timer_fuel_lower(playerid);
public timer_fuel_lower(playerid)
{
if(isrefuelling[playerid]) continue;
new vid = GetPlayerVehicleID(playerid);
GetVehicleParamsEx(GetPlayerVehicleID(vid),engine,lights,alarm,doors,bonnet,boot,objective);
if(engine>=1)
{
if(fuel[playerid] >= 1)
{
fuel[playerid]--;
}
else if (fuel[vid]<1)
{
fuel[vid] = 0;
SetVehicleParamsEx(vid,false,0,0,0,0,0,0);
if(IsPlayerInVehicle(playerid, vid))
{
GameTextForPlayer(playerid,"~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[playerid],string);
return 1;
}
pawn Код:
pawn Код:
|