17.07.2016, 21:22
Hey,
I've followed a tutorial made by PMK_1 about implementing a simple speedo into the server. This worked however due to it using a global variable, it only appears for player id 0. I'm aware that this is the issue and that I need to convert the code into using the newer PlayerTextDraws as the speedo is unique to each player. However I've no idea how to do this, depsite looking at various topics via the search function, any help would be appreciated.
I've followed a tutorial made by PMK_1 about implementing a simple speedo into the server. This worked however due to it using a global variable, it only appears for player id 0. I'm aware that this is the issue and that I need to convert the code into using the newer PlayerTextDraws as the speedo is unique to each player. However I've no idea how to do this, depsite looking at various topics via the search function, any help would be appreciated.
pawn Код:
/*-------------------------------------------------------
Basic Speed'o'Meter & Health'o'Meter Script By Pmk1
-------------------------------------------------------*/
#define FILTERSCRIPT
//-------------------------------------------------------
#include <a_samp>
//-------------------------------------------------------
new Text:SPEEDOS[MAX_PLAYERS];
//-------------------------------------------------------
forward Speedometer(playerid);
//-------------------------------------------------------
public OnGameModeInit()
{
SetTimer("Speedometer", 100, true);
return 1;
}
//-------------------------------------------------------
public OnPlayerConnect(playerid)
{
SPEEDOS[playerid] = TextDrawCreate(10.0,200.0," ");
TextDrawShowForPlayer(playerid,SPEEDOS[playerid]);
return 1;
}
//-------------------------------------------------------
public Speedometer(playerid)
{
new vehicleid,Float:speed_x,Float:speed_y,Float:speed_z,Float:final_speed,speed_string[256],final_speed_int;
vehicleid = GetPlayerVehicleID(playerid);
if(vehicleid != 0)
{
GetVehicleVelocity(vehicleid,speed_x,speed_y,speed_z);
final_speed = floatsqroot(((speed_x*speed_x)+(speed_y*speed_y))+(speed_z*speed_z))*250.666667; // 250.666667 = kmph // 199,4166672= mph
final_speed_int = floatround(final_speed,floatround_round);
format(speed_string,256,"Speed: %i",final_speed_int);
TextDrawSetString(SPEEDOS[playerid], speed_string);
}
else
{
TextDrawSetString(SPEEDOS[playerid], " ");
}
return 1;
}
//-------------------------------------------------------