Need a working speedo
#6

Would this give a realistic kmh speedo

Code:
#define SLOTS 200

enum SavePlayerPosEnum {
Float:LastX,
Float:LastY,
Float:LastZ
}

new SavePlayerPos[SLOTS][SavePlayerPosEnum];
new Text:Speedo[SLOTS];
new UpdateSeconds;

forward UpdateSpeed();
Code:
SetTimer("UpdateSpeed",1000, 1);
Code:
public UpdateSpeed()
{
	new Float:x,Float:y,Float:z;
	new Float:distance,value; //string[256];
	//new Float:health;
	for(new i=0; i<SLOTS; i++)
	{
		if(IsPlayerConnected(i) && IsPlayerInAnyVehicle(i))
		{
			TextDrawDestroy(Speedo[i]);
		}
	}

	for(new i=0; i<SLOTS; i++)
	{
		if(IsPlayerConnected(i) && IsPlayerInAnyVehicle(i))
		{
			GetPlayerPos(i, x, y, z);
			distance = floatsqroot(floatpower(floatabs(floatsub(x,SavePlayerPos[i][LastX])),2)+floatpower(floatabs(floatsub(y,SavePlayerPos[i][LastY])),2)+floatpower(floatabs(floatsub(z,SavePlayerPos[i][LastZ])),2));
			value = floatround(distance * 5000);
			if(UpdateSeconds > 1)
			{
				value = floatround(value / UpdateSeconds);
			}
			format(string,sizeof(string),"~r~KM/H:%d",floatround(value/1600));
			Speedo[i] = TextDrawCreate(560, 380,string);
			TextDrawFont(Speedo[i], 1);
			TextDrawColor(Speedo[i],COLOR_GREEN);
			TextDrawSetShadow(Speedo[i],1);
			TextDrawAlignment(Speedo[i],1);
			TextDrawShowForPlayer (i, Speedo[i]);
		  TextDrawSetOutline(Speedo[i],1);
	    TextDrawBackgroundColor(Speedo[i],COLOR_BLACK);
		}
		SavePlayerPos[i][LastX] = x;
		SavePlayerPos[i][LastY] = y;
		SavePlayerPos[i][LastZ] = z;
	}
}
Code:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
	if(newstate == PLAYER_STATE_ONFOOT)
	{
  TextDrawHideForPlayer(playerid, Speedo[playerid]);
	}
	return 1;
}
Reply


Messages In This Thread
Need a working speedo - by Bearfist - 27.04.2009, 21:27
Re: Need a working speedo - by miokie - 27.04.2009, 21:31
Re: Need a working speedo - by Bearfist - 27.04.2009, 21:39
Re: Need a working speedo - by ferriswheel - 27.04.2009, 21:42
Re: Need a working speedo - by Joe Staff - 27.04.2009, 21:48
Re: Need a working speedo - by Bearfist - 27.04.2009, 21:52
Re: Need a working speedo - by Joe Staff - 27.04.2009, 21:55
Re: Need a working speedo - by Bearfist - 27.04.2009, 21:57
Re: Need a working speedo - by ferriswheel - 27.04.2009, 22:00
Re: Need a working speedo - by Bearfist - 27.04.2009, 22:11

Forum Jump:


Users browsing this thread: 1 Guest(s)