SA-MP Forums Archive
Speedo - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Speedo (/showthread.php?tid=567942)



Speedo - MrCallum - 17.03.2015

I get into my car, my speedo does not show up?

Код:
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;
}



Re: Speedo - SickAttack - 18.03.2015

You should set the string before you show it:
pawn Код:
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;
}



Re: Speedo - Abagail - 18.03.2015

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.


Re: Speedo - SickAttack - 18.03.2015

Quote:
Originally Posted by Abagail
Посмотреть сообщение
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.
Well, that's done when updating the speedometer's info, so there isn't really something to worry about.