Skip to content

Instantly share code, notes, and snippets.

@Cheaterman
Forked from anonymous/legena.pwn
Last active August 29, 2015 14:19
Show Gist options
  • Save Cheaterman/d98d6f5ebe899ad5a3b7 to your computer and use it in GitHub Desktop.
Save Cheaterman/d98d6f5ebe899ad5a3b7 to your computer and use it in GitHub Desktop.
#include <a_samp>
#include <streamer>
#include "zcmd"
#define COLOR_WHITE (0xFFFFFFFF) // We have this defined in "includes/TMS/Colors" -- John_Brown
#define COLOR_RED (0xFF0000FF) // We have this defined in "includes/TMS/Colors" -- John_Brown
#define COLOR_GREEN (0x33AA33AA) // We have this defined in "includes/TMS/Colors" -- John_Brown
#if !defined MAX_STRING
#define MAX_STRING (128) // We have this defined... Well... At many places in general. -- John_Brown
#endif
#define MAX_GAS_STATIONS 32
#define DIALOG_GAS 1998
enum Coords
{
Float:COORD_X,
Float:COORD_Y,
Float:COORD_Z
};
new
GasStationCoords[][Coords] =
{
{ -1471.5, 1863.75, 32.7 },
{ -1326.5, 2677.5, 50.1 },
{ 611.5, 1694.5, 7.0 },
{ -2249.25, -2559.0, 32.0 },
{ -1606.5, -2714.0, 48.6 },
{ -93.5, -1175.0, 2.3 },
{ 1377.5, 457.0, 19.9 },
{ 651.5, -565.5, 16.4 },
{ -1675.75, 412.75, 7.2 },
{ -2405.50, 976.25, 45.3 },
{ -2023.25, 156.75, 28.9 },
{ -1131.75, -204.25, 14.2 },
{ 66.50, 1220.50, 18.9 },
{ 350.50, 2537.50, 16.8 },
{ 2147.00, 2747.75, 10.9 },
{ 2639.75, 1106.00, 10.9 },
{ 2115.00, 920.00, 10.9 },
{ 2202.00, 2475.00, 10.9 },
{ 1596.50, 2199.75, 10.9 },
{ 1584.25, 1448.25, 10.9 },
{ 1004.25, -940.50, 42.2 },
{ 1935.00, -1772.75, 13.4 },
{ 0.0, 0.0, 0.0 } // End of structure -- John_Brown
};
new
Float:VehicleGasLevel[MAX_VEHICLES],
GasStations[MAX_GAS_STATIONS],
IdleFuelConsTimer,
ActiveFuelConsTimer
;
forward UpdateIdleFuelCons();
forward UpdateActiveFuelCons();
public OnFilterScriptInit()
{
new i;
for(i = 0; i < MAX_VEHICLES; i++)
VehicleGasLevel[i] = 100;
for(i = 0; i < MAX_GAS_STATIONS; ++i)
if(GasStationCoords[i][COORD_Z])
GasStations[i] = CreateDynamicCP(
GasStationCoords[i][COORD_X],
GasStationCoords[i][COORD_Y],
GasStationCoords[i][COORD_Z],
5.0
);
else
break;
IdleFuelConsTimer = SetTimer("UpdateIdleFuelCons", 7500, true);
ActiveFuelConsTimer = SetTimer("UpdateActiveFuelCons", 250, true);
return 1;
}
public OnFilterScriptExit()
{
KillTimer(IdleFuelConsTimer);
KillTimer(ActiveFuelConsTimer);
return 1;
}
public OnPlayerEnterDynamicCP(playerid, checkpointid)
{
for(new i; i < sizeof(GasStations); i++)
{
if(checkpointid == GasStations[i])
{
if(IsPlayerInAnyVehicle(playerid) == 1)
{
ShowPlayerDialog(
playerid,
DIALOG_GAS,
DIALOG_STYLE_LIST,
"{FF00FF}[{6C6C6C}TMS - Gas Station{FF00FF}]", "{FF00FF}[{6C6C6C}Fill fuel tank [1000$]{FF00FF}]",
"Select",
"Close"
);
TogglePlayerControllable(playerid, 1);
}
}
}
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == DIALOG_GAS)
{
if(response)
{
switch(listitem)
{
case 0:
{
new vehicleid = GetPlayerVehicleID(playerid);
if(VehicleGasLevel[vehicleid] == 100)
{
SendClientMessage(playerid, COLOR_WHITE, "{FF0000}[{6C6C6C}Your fuel tank is already full!{FF0000}]");
TogglePlayerControllable(playerid, 1);
}
else
{
VehicleGasLevel[vehicleid] = 100;
}
}
}
}
else
{
TogglePlayerControllable(playerid, 1);
}
}
return 0;
}
public UpdateIdleFuelCons()
{
new
engine,
lights,
alarm,
doors,
bonnet,
boot,
objective
;
for(new i; i < MAX_VEHICLES; ++i)
{
GetVehicleParamsEx(
i,
engine,
lights,
alarm,
doors,
bonnet,
boot,
objective
);
if(engine)
VehicleGasLevel[i] -= 0.25;
if(VehicleGasLevel[i] <= 0)
{
VehicleGasLevel[i] = 0;
SetVehicleParamsEx(
i,
false,
lights,
alarm,
doors,
bonnet,
boot,
objective
);
}
}
}
public UpdateActiveFuelCons()
{
new
vehicleid,
engine,
lights,
alarm,
doors,
bonnet,
boot,
objective
;
for(new i; i < MAX_PLAYERS; ++i)
{
if(IsPlayerInAnyVehicle(i))
{
vehicleid = GetPlayerVehicleID(i);
GetVehicleParamsEx(
vehicleid,
engine,
lights,
alarm,
doors,
bonnet,
boot,
objective
);
if(engine)
VehicleGasLevel[vehicleid] -= (GetSpeed(i) / 500.0);
if(VehicleGasLevel[vehicleid] <= 0)
{
VehicleGasLevel[vehicleid] = 0;
SetVehicleParamsEx(
vehicleid,
false,
lights,
alarm,
doors,
bonnet,
boot,
objective
);
}
}
}
}
CMD:mygas(playerid, params[])
{
#pragma unused params
new ret[MAX_STRING];
if(!IsPlayerInAnyVehicle(playerid))
return SendClientMessage(playerid, COLOR_RED, "[ERROR] You aren't in any vehicle!");
format(ret, sizeof(ret), "Your fuel tank is %.0f/100 full.", VehicleGasLevel[GetPlayerVehicleID(playerid)]);
return SendClientMessage(playerid, COLOR_GREEN, ret);
}
stock GetSpeed(playerid) // We have this defined in "includes/TMS/PlayerData" -- John_Brown
{
new Float:ST[3];
GetVehicleVelocity(GetPlayerVehicleID(playerid),ST[0],ST[1],ST[2]);
return floatround(1.61*floatsqroot(floatpower(floatabs(ST[0]), 2.0) + floatpower(floatabs(ST[1]), 2.0) + floatpower(floatabs(ST[2]), 2.0)) * 100.3);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment