Speedometer
#1

Hi, i made a speedometer and every thing works fine, but it show's not the players speed but all players speed, so while you are playing alone it works fine. I use:

pawn Код:
public Speed(playerid)
{
    new
    vehicleid = GetPlayerVehicleID(playerid);
   
    if(vehicleid != 0)
    {
            new string[64],string1[32];
            format(string1,sizeof(string1), "Fuel: %il", VehicleFuel[vehicleid]);
            format(string,sizeof(string), "Speed: %d km/h", GetPlayerSpeed(playerid,false));
            TextDrawSetString(textdraws[Textdraw0][playerid],string);
            TextDrawSetString(textdraws[Textdraw2][playerid],string1);
            return 1;
    }
    else
    {
            TextDrawSetString(textdraws[Textdraw0][playerid],"");
            TextDrawSetString(textdraws[Textdraw2][playerid],"");
    }
    return 1;
}
I don't have idea's what may be wrong.
Reply
#2

Could you show us the GetPlayerSpeed function?
public Speed is a timer, right? Do you use SetTimerEx?
Reply
#3

pawn Код:
forward Speed(playerid);
pawn Код:
stock GetPlayerSpeed(playerid,bool:kmh) // by misco
{
    new Float:Vx,Float:Vy,Float:Vz,Float:rtn;
    if(IsPlayerInAnyVehicle(playerid)) GetVehicleVelocity(GetPlayerVehicleID(playerid),Vx,Vy,Vz); else GetPlayerVelocity(playerid,Vx,Vy,Vz);
    rtn = floatsqroot(floatabs(floatpower(Vx + Vy + Vz,2)));
    return kmh?floatround(rtn * 100 * 1.61):floatround(rtn * 100);
}
pawn Код:
SetTimer("Speed",150,1);
Reply
#4

Код:
forward Speed();
public Speed()
{
	for(new playerid, p = GetMaxPlayers(); playerid < p; playerid++)
	{
		new
			vehicleid = GetPlayerVehicleID(playerid);
   
		if(vehicleid != 0)
		{
			new string[64],string1[32];
			format(string1,sizeof(string1), "Fuel: %il", VehicleFuel[vehicleid]);
			format(string,sizeof(string), "Speed: %d km/h", GetPlayerSpeed(playerid,false));
			TextDrawSetString(textdraws[Textdraw0][playerid],string);
			TextDrawSetString(textdraws[Textdraw2][playerid],string1);
			return 1;
		}
		else
		{		
			TextDrawSetString(textdraws[Textdraw0][playerid],"");
			TextDrawSetString(textdraws[Textdraw2][playerid],"");
		}
	}
	return 1;
}
Give it a try.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)