跳到主要内容

PlayerTextDrawSetString

描述

修改玩家文本绘图的文本内容

参数名说明
playerid要设置文本的玩家 ID
PlayerText:textid要修改的玩家文本绘图的 ID
const format[]新的格式化字符串
OPEN_MP_TAGS:...可变参数(支持任意标签的参数)

返回值

该函数不返回特定值。

示例

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

public OnPlayerStateChange(playerid, PLAYER_STATE:newstate, PLAYER_STATE:oldstate)
{
if (newstate == PLAYER_STATE_DRIVER) // 以驾驶员身份进入车辆
{
pVehicleHealthTD[playerid] = CreatePlayerTextDraw(playerid, 320.0, 240.0, " ");
PlayerTextDrawShow(playerid, pVehicleHealthTD[playerid]);

// 设置每秒更新文本绘图的计时器
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), "车辆耐久: %.0f", health);
PlayerTextDrawSetString(playerid, pVehicleHealthTD[playerid], string); // <<< 更新显示车辆耐久度

// 专业建议:open.mp中可直接使用以下简化写法
PlayerTextDrawSetString(playerid, pVehicleHealthTD[playerid], "车辆耐久: %.0f", health);
return 1;
}

/*
注意:本示例仅用于演示目的,实际游戏中使用需进行额外验证和错误处理
*/

注意事项

提示

修改文本内容后无需重新调用 PlayerTextDrawShow 即可生效

注意

文本字符串长度存在限制,详见系统限制

相关函数