SA-MP Forums Archive
Need help with Speedometer! - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Need help with Speedometer! (/showthread.php?tid=153686)



Need help with Speedometer! - Cameltoe - 10.06.2010

Okei, so i managed to script a nice little Speedometer.. the only problem is that the speedometer can only be used with one person ..
means like if one person is driving the speedometer will be enabled with the speed of the person driving for all other players driving..

Heres my code:

Top of script:
Код:
forward Speedometer(playerid);
Make the Text varible:
Код:
new Text:SpeedoText;
On Gm init:
Код:
    SpeedoText = TextDrawCreate(250.0, 405.0, "SpeedoText");
	TextDrawSetShadow(SpeedoText, 1);
	TextDrawSetOutline(SpeedoText, 2);
	TextDrawLetterSize(SpeedoText,0.60,2.0);
	TextDrawFont(SpeedoText, 3);
	TextDrawBoxColor(SpeedoText,0x000000AA);
OnPlayerStateChange:
Код:
public OnPlayerStateChange(playerid,newstate,oldstate)
{
  if(newstate==PLAYER_STATE_DRIVER)
  {
	  TextDrawShowForPlayer(playerid,SpeedoText);
  }else{
    TextDrawHideForPlayer(playerid,SpeedoText);
  }
  return 1;
}
The speedo function:
Код:
//// GetPlayer Speed
forward GetPlayerSpeed(playerid);
stock GetPlayerSpeed(playerid)
{
  new Float:ST[4];
  if(IsPlayerInAnyVehicle(playerid)) GetVehicleVelocity(GetPlayerVehicleID(playerid),ST[0],ST[1],ST[2]); else GetPlayerVelocity(playerid,ST[0],ST[1],ST[2]);
  ST[3] = floatsqroot(floatpower(floatabs(ST[0]), 2.0) + floatpower(floatabs(ST[1]), 2.0) + floatpower(floatabs(ST[2]), 2.0)) * 200;
  return floatround(ST[3]);
}
//// Speedoupdate
forward Speedometer(playerid);
public Speedometer(playerid)
{
	new string[256];
 	new speed = GetPlayerSpeed(playerid);
	format(string,sizeof(string),"~g~ Speed: ~w~ %d KP/h",speed);
	TextDrawSetString(SpeedoText, string);
}
Help is really apprectiated!! thx


Re: Need help with Speedometer! - Cameltoe - 10.06.2010

Worked it out.. Solution: Espeed, easy to understand!


Re: Need help with Speedometer! - Tim_Ethen - 02.11.2010

Take a look at my tutorial. http://forum.sa-mp.com/showthread.ph...109#post895109