20.11.2012, 15:43
As the title says, the speedometer ONLY displays to the FIRST person that joins the server. The fuel gauge however, displays for everyone!
So it's like this:
for the first person.
SPEED : 0 MPH
FUEL: 100%
If someone else joins and enters a vehicle it's like this:
FUEL: 100%
It's been killing me for ages trying to figure it out. Could someone help me or make any suggestions? Or advise a better way to code it?
CODE:
(Forwards)
Publics.
Fuel Save
OnPlayerStateChange
Timers
If you feel any piece of code will assist that isn't here, I will post it!
So it's like this:
for the first person.
SPEED : 0 MPH
FUEL: 100%
If someone else joins and enters a vehicle it's like this:
FUEL: 100%
It's been killing me for ages trying to figure it out. Could someone help me or make any suggestions? Or advise a better way to code it?
CODE:
(Forwards)
pawn Код:
forward SpeedoUpdate(playerid);
forward FuelUpdate(playerid);
new Text:speed[MAX_PLAYERS],Text:fuel[MAX_PLAYERS];
pawn Код:
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.");
}
}
}
}
}
}
pawn Код:
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");
}
}
}
}
OnPlayerStateChange
pawn Код:
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]);
}
pawn Код:
SpeedoSysTimer[playerid] = SetTimerEx("SpeedoUpdate", 300, true, "i", playerid);
printf("speedotimer");
FuelSysTimer[playerid] = SetTimerEx("FuelUpdate", 30000, true, "i", playerid);
If you feel any piece of code will assist that isn't here, I will post it!