forward SpeedoUpdate(playerid);
forward FuelUpdate(playerid);
new Text:speed[MAX_PLAYERS],Text:fuel[MAX_PLAYERS];
public SpeedoUpdate(playerid)
{
if(IsPlayerInAnyVehicle(playerid))
{
new Float:x,Float:y,Float:z,string[24],vehicleid = GetPlayerVehicleID(playerid);
GetVehicleVelocity(vehicleid,x,y,z);
format(string,sizeof(string),"~g~Speed: ~w~%d mph",floatround(floatsqroot(((x*x)+(y*y))+(z*z))*156.666667*0.641371192));
TextDrawSetString(speed[playerid],string);
format(string,sizeof(string),"~g~Fuel: ~w~%d%%",VehFuel[vehicleid]);
TextDrawSetString(fuel[playerid],string);
}
}
public FuelUpdate(playerid)
{
if(IsPlayerInAnyVehicle(playerid))
{
new pvehicle = GetPlayerVehicleID(playerid);
for(new i = 1;i<MAX_VEHICLES;i++)
{
if(GetVehicleModel(i))
{
GetVehicleParamsEx(i,engine,lights,alarm,doors,bonnet,boot,objective);
if(engine == 1)
{
if(VehFuel[i] > 0)
{
VehFuel[i]--;
Fuel = VehFuel[i];
}
else if(VehFuel[pvehicle] == 0)
{
KillTimer(FuelSysTimer[playerid]);
EngineStartStatus[i] = 0;
SetVehicleParamsEx(i,0,lights,alarm,doors,bonnet,boot,objective);
GameTextForPlayer(playerid, "~r~out of fuel", 3000, 5);
SendClientMessage(playerid, COLOUR_REALRED, "Your vehicle has run out of fuel.");
}
}
}
}
}
}
public FuelSave()
{
for(new i = 1;i<MAX_VEHICLES;i++)
{
if(GetVehicleModel(i))
{
GetVehicleParamsEx(i,engine,lights,alarm,doors,bonnet,boot,objective);
if(engine == 1)
{
Fuel = VehFuel[i];
new vehicleid = MySQL_GetValue(i, "id", "vehicles");
MySQL_SetInteger(vehicleid, "VehFuel", Fuel, "vehicles");
}
}
}
}
if(newstate == PLAYER_STATE_DRIVER && oldstate == PLAYER_STATE_ONFOOT)
{
TextDrawShowForPlayer(playerid,speed[playerid]);
TextDrawShowForPlayer(playerid,fuel[playerid]);
if(VehOwned[vehicleid] == 1)
{
if(strcmp(VehOwner[VehID], GetName(playerid), true))
{
RemovePlayerFromVehicle(playerid);
SendClientMessage(playerid, COLOUR_YELLOW, "This vehicle is owned by someone else.");
TextDrawDestroy(enginestring);
}
}
}
if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER && EngineStartStatus[vehicleid] == 1)
{
KillTimer(SpeedoSysTimer[playerid]);
KillTimer(FuelSysTimer[playerid]);
SpeedoSysTimer[playerid] = SetTimerEx("SpeedoUpdate", 300, true, "i", playerid);
FuelSysTimer[playerid] = SetTimerEx("FuelUpdate", 30000, true, "i", playerid);
TextDrawShowForPlayer(playerid,speed[playerid]);
TextDrawShowForPlayer(playerid,fuel[playerid]);
}
SpeedoSysTimer[playerid] = SetTimerEx("SpeedoUpdate", 300, true, "i", playerid);
printf("speedotimer");
FuelSysTimer[playerid] = SetTimerEx("FuelUpdate", 30000, true, "i", playerid);
speed[playerid] = TextDrawCreate(478,389,"_");
TextDrawLetterSize(speed[playerid],0.37,2.0);
TextDrawSetOutline(speed[playerid],1);
TextDrawFont(speed[playerid], 2);
fuel[playerid] = TextDrawCreate(478,413,"_");
TextDrawLetterSize(fuel[playerid],0.37,2.0);
TextDrawSetOutline(fuel[playerid],1);
TextDrawFont(fuel[playerid], 2);
Create a loop which creates the textdraws needed at OnGameModeInit.
|
public OnGameModeInit()
{
for(new i=0;i<MAX_PLAYERS;i++)
{
// your "TextDrawCreate" and "TextDrawSet..." things come here.
// replace playerid with i
}
return 1;
}
public OnGameModeInit()
{
for(new i=0;i<MAX_PLAYERS;i++)
{
speed[i] = TextDrawCreate(478,389,"_");
TextDrawLetterSize(speed[i],0.37,2.0);
TextDrawSetOutline(speed[i],1);
TextDrawFont(speed[i], 2);
fuel[i] = TextDrawCreate(478,413,"_");
TextDrawLetterSize(fuel[i],0.37,2.0);
TextDrawSetOutline(fuel[i],1);
TextDrawFont(fuel[i], 2);
}
return 1;
}