Pular para o conteúdo principal

PlayerTextDrawSetString

Descrição

Altere o texto de um player-textdraw.

NomeDescrição
playeridO ID do jogador cuja string textdraw deve ser definida
PlayerText:textidO ID do textdraw a ser alterado
const format[]A nova string para TextDraw
OPEN_MP_TAGS:...Número indefinido de argumentos de qualquer tag.

Retornos

Esta função não retorna nenhum valor específico.

Exemplos

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

public OnPlayerStateChange(playerid, PLAYER_STATE:newstate, PLAYER_STATE:oldstate)
{
if (newstate == PLAYER_STATE_DRIVER) // Entrou em um veículo como motorista
{
pVehicleHealthTD[playerid] = CreatePlayerTextDraw(playerid, 320.0, 240.0, " ");
PlayerTextDrawShow(playerid, pVehicleHealthTD[playerid]);

// Defina um cronômetro para atualizar o textdraw a cada segundo
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); // <<< Atualize o texto para mostrar a saúde do veículo

// DICA PROFISSIONAL: Você não precisa de `format` em open.mp
PlayerTextDrawSetString(playerid, pVehicleHealthTD[playerid], "Vehicle Health: %.0f", health);
return 1;
}

/* NOTA: Este exemplo é apenas para fins de demonstração, não é garantido que funcione no jogo. É apenas para mostrar o uso da função PlayerTextDrawSetString. */

Notas

dica

Você não precisa mostrar TextDraw novamente para aplicar as alterações.

aviso

Existem limites para o comprimento das strings textdraw! Consulte Limites para obter mais informações.

Funções Relacionadas