Need help with Speedometer!
#1

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
Reply
#2

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

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


Forum Jump:


Users browsing this thread: 1 Guest(s)