跳至主要内容

PlayerTextDrawSetString

Description​

Change the text of a player-textdraw.

NameDescription
playeridThe ID of the player who's textdraw string to set
PlayerText:textidThe ID of the textdraw to change
const format[]The new string for the TextDraw
OPEN_MP_TAGS:...Indefinite number of arguments of any tag.

Returns​

This function does not return any specific values.

Examples​

new PlayerText:pVehicleHealthTD[MAX_PLAYERS];
new pVehicleHealthTimer[MAX_PLAYERS];

public OnPlayerStateChange(playerid, PLAYER_STATE:newstate, PLAYER_STATE:oldstate)
{
if (newstate == PLAYER_STATE_DRIVER) // Entered a vehicle as driver
{
pVehicleHealthTD[playerid] = CreatePlayerTextDraw(playerid, 320.0, 240.0, " ");
PlayerTextDrawShow(playerid, pVehicleHealthTD[playerid]);

// Set a timer to update the textdraw every second
pVehicleHealthTimer[playerid] = SetTimerEx("UpdateVehicleHealthTextDraw", 1000, true, "i", playerid);
}
if (oldstate == PLAYER_STATE_DRIVER)
{
KillTimer(pVehicleHealthTimer[playerid]);
PlayerTextDrawDestroy(playerid, pVehicleHealthTD[playerid]);
}
return 1;
}

forward UpdateVehicleHealthTextDraw(playerid);
public UpdateVehicleHealthTextDraw(playerid)
{
new
string[32],
vehicleid = GetPlayerVehicleID(playerid),
Float:health;

GetVehicleHealth(vehicleid, health);

format(string, sizeof(string), "Vehicle Health: %.0f", health);
PlayerTextDrawSetString(playerid, pVehicleHealthTD[playerid], string); // <<< Update the text to show the vehicle health

// PRO TIP: You don't need `format` in open.mp
PlayerTextDrawSetString(playerid, pVehicleHealthTD[playerid], "Vehicle Health: %.0f", health);
return 1;
}

/*
NOTE: This example is purely for demonstration purposes, it is not guaranteed to work in-game. It is merely to show the usage of the PlayerTextDrawSetString function.
*/

Notes​

提示

You don't have to show the TextDraw again in order to apply the changes.

注意

There are limits to the length of textdraw strings! See Limits for more info.