Converting a global Variable TD to a PTD
#1

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;
}
//-------------------------------------------------------
Reply
#2

You don't need arrays for ptd just use settimerex instead of settimer

no need PlayerTextpeedo[MAX_PLAYERS]

you can do PlayerTextpeedo
Reply
#3

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"100true"i"playerid);
    
SPEEDOS CreatePlayerTextDraw(playerid10.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(playeridSPEEDOSspeed_string);
string);
    
         }
    else
    {
        
PlayerTextDrawSetString(playeridSPEEDOS" ");
        
    }
    return 
1;
}
//------------------------------------------------------- 
Hare I've done it for you
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)