Converting a global Variable TD to a PTD - 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)
+--- Thread: Converting a global Variable TD to a PTD (
/showthread.php?tid=612436)
Converting a global Variable TD to a PTD -
marley - 17.07.2016
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.
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;
}
//-------------------------------------------------------
Re: Converting a global Variable TD to a PTD -
UltraScripter - 17.07.2016
You don't need arrays for ptd just use settimerex instead of settimer
no need PlayerText

peedo[MAX_PLAYERS]
you can do PlayerText

peedo
Re: Converting a global Variable TD to a PTD -
UltraScripter - 17.07.2016
PHP код:
/*-------------------------------------------------------
Basic Speed'o'Meter & Health'o'Meter Script By Pmk1
-------------------------------------------------------*/
#define FILTERSCRIPT
//-------------------------------------------------------
#include <a_samp>
//-------------------------------------------------------
new stimer[MAX_PLAYERS];
new PlayerText:SPEEDOS
//-------------------------------------------------------
forward Speedometer(playerid);
//-------------------------------------------------------
//-------------------------------------------------------
public OnPlayerConnect(playerid)
{
stimer[playerid] = SetTimerEx("Speedometer", 100, true, "i", playerid);
SPEEDOS = CreatePlayerTextDraw(playerid, 10.0,200.0," ");
PlayerTextDrawShow(playerid,SPEEDOS);
return 1;
}
Public OnPlayerDisconnect(playerid)
{
KillTimer(stimer[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);
PlayerTextDrawSetString(playerid, SPEEDOS, speed_string);
string);
}
else
{
PlayerTextDrawSetString(playerid, SPEEDOS, " ");
}
return 1;
}
//-------------------------------------------------------
Hare I've done it for you