stock ShowSpeedo(playerid) { PlayerTextDrawShow(playerid, SpeedoText0); PlayerTextDrawShow(playerid, SpeedoText1); PlayerTextDrawShow(playerid, SpeedoText2); PlayerTextDrawShow(playerid, SpeedoText3); PlayerTextDrawShow(playerid, SpeedoText4); PlayerTextDrawSetString(playerid,SpeedoText0,"~b~SPEED:~n~~w~0 MPH~n~~g~GAS: ~w~100.00"); PlayerInfo[playerid][pSpeedoOn] =1; } stock HideSpeedo(playerid) { PlayerTextDrawHide(playerid, SpeedoText0); PlayerTextDrawHide(playerid, SpeedoText1); PlayerTextDrawHide(playerid, SpeedoText2); PlayerTextDrawHide(playerid, SpeedoText3); PlayerTextDrawHide(playerid, SpeedoText4); PlayerInfo[playerid][pSpeedoOn] =0; }
public OnPlayerStateChange(playerid, newstate, oldstate) { if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER) { ShowSpeedo(playerid); } if(oldstate == PLAYER_STATE_DRIVER && newstate == PLAYER_STATE_ONFOOT) { HideSpeedo(playerid); } return 1; }
stock ShowSpeedo(playerid)
{
PlayerTextDrawSetString(playerid,SpeedoText0,"~b~SPEED:~n~~w~0 MPH~n~~g~GAS: ~w~100.00");
PlayerTextDrawShow(playerid, SpeedoText0);
PlayerTextDrawShow(playerid, SpeedoText1);
PlayerTextDrawShow(playerid, SpeedoText2);
PlayerTextDrawShow(playerid, SpeedoText3);
PlayerTextDrawShow(playerid, SpeedoText4);
PlayerInfo[playerid][pSpeedoOn] =1;
}
You shouldn't solely rely on the player changing from PLAYER_STATE_DRIVER to PLAYER_STATE_ONFOOT. For instance, what if someone dies while in a vehicle? Their new state certainly won't be onfoot but PLAYER_STATE_WASTED.
The simplest answer would be to when updating the textdraw, check if they are still driving a vehicle. |