Portal SAMP
[Ajuda] formatar para textdraw - Versão de Impressão

+- Portal SAMP (https://portalsamp.com)
+-- Fórum: SA-MP (https://portalsamp.com/forumdisplay.php?fid=5)
+--- Fórum: Área de suporte (https://portalsamp.com/forumdisplay.php?fid=6)
+--- Tópico: [Ajuda] formatar para textdraw (/showthread.php?tid=4901)



formatar para textdraw - André Santos - 17/10/2024

galera como eu posso na textdraw7 em saude queria colocar para mostrar para o player a porcentagem d vida que ele tem eu nao sei como faz aq esta meu codigo 

Código:
#include a_samp

new PlayerText:Textdraw0;
new PlayerText:Textdraw1;
new PlayerText:Textdraw2;
new PlayerText:Textdraw3;
new PlayerText:Textdraw4;
new PlayerText:Textdraw5;
new PlayerText:Textdraw6;
new PlayerText:Textdraw7;


public OnPlayerConnect(playerid)
{
    SetTimer("vitals",1000,1);
    // Criando TextDraws
    Textdraw0 = CreatePlayerTextDraw(playerid,510.000000, 240.000000, "Player:");
    PlayerTextDrawBackgroundColor(playerid,Textdraw0, 255);
    PlayerTextDrawFont(playerid,Textdraw0, 2);
    PlayerTextDrawLetterSize(playerid,Textdraw0, 0.300000, 1.000000);
    PlayerTextDrawColor(playerid, Textdraw0, -1);
    PlayerTextDrawSetOutline(playerid, Textdraw0, 0);
    PlayerTextDrawSetProportional(playerid, Textdraw0, 1);
    PlayerTextDrawSetShadow(playerid, Textdraw0, 1);

    Textdraw1 = CreatePlayerTextDraw(playerid,510.000000, 250.000000, "Grana:");
    PlayerTextDrawBackgroundColor(playerid,Textdraw1, 255);
    PlayerTextDrawFont(playerid, Textdraw1, 2);
    PlayerTextDrawLetterSize(playerid, Textdraw1, 0.300000, 1.000000);
    PlayerTextDrawColor(playerid, Textdraw1, -1);
    PlayerTextDrawSetOutline(playerid, Textdraw1, 0);
    PlayerTextDrawSetProportional(playerid, Textdraw1, 1);
    PlayerTextDrawSetShadow(playerid, Textdraw1, 1);

    Textdraw2 = CreatePlayerTextDraw(playerid,510.000000, 260.000000, "Score:");
    PlayerTextDrawBackgroundColor(playerid,Textdraw2, 255);
    PlayerTextDrawFont(playerid, Textdraw2, 2);
    PlayerTextDrawLetterSize(playerid, Textdraw2, 0.300000, 1.000000);
    PlayerTextDrawColor(playerid, Textdraw2, -1);
    PlayerTextDrawSetOutline(playerid, Textdraw2, 0);
    PlayerTextDrawSetProportional(playerid, Textdraw2, 1);
    PlayerTextDrawSetShadow(playerid, Textdraw2, 1);

    Textdraw3 = CreatePlayerTextDraw(playerid,510.000000, 270.000000, "Arma id:");
    PlayerTextDrawBackgroundColor(playerid, Textdraw3, 255);
    PlayerTextDrawFont(playerid, Textdraw3, 2);
    PlayerTextDrawLetterSize(playerid, Textdraw3, 0.300000, 1.000000);
    PlayerTextDrawColor(playerid, Textdraw3, -1);
    PlayerTextDrawSetOutline(playerid, Textdraw3, 0);
    PlayerTextDrawSetProportional(playerid, Textdraw3, 1);
    PlayerTextDrawSetShadow(playerid, Textdraw3, 1);

    // Criando as novas Textdraws para ping, jogadores online e kills
    Textdraw4 = CreatePlayerTextDraw(playerid,510.000000, 280.000000, "Ping:");
    PlayerTextDrawBackgroundColor(playerid, Textdraw4, 255);
    PlayerTextDrawFont(playerid, Textdraw4, 2);
    PlayerTextDrawLetterSize(playerid, Textdraw4, 0.300000, 1.000000);
    PlayerTextDrawColor(playerid, Textdraw4, -1);
    PlayerTextDrawSetOutline(playerid, Textdraw4, 0);
    PlayerTextDrawSetProportional(playerid, Textdraw4, 1);
    PlayerTextDrawSetShadow(playerid, Textdraw4, 1);

    Textdraw5 = CreatePlayerTextDraw(playerid,510.000000, 290.000000, "Players Online:");
    PlayerTextDrawBackgroundColor(playerid, Textdraw5, 255);
    PlayerTextDrawFont(playerid, Textdraw5, 2);
    PlayerTextDrawLetterSize(playerid, Textdraw5, 0.300000, 1.000000);
    PlayerTextDrawColor(playerid, Textdraw5, -1);
    PlayerTextDrawSetOutline(playerid, Textdraw5, 0);
    PlayerTextDrawSetProportional(playerid, Textdraw5, 1);
    PlayerTextDrawSetShadow(playerid, Textdraw5, 1);

    Textdraw6 = CreatePlayerTextDraw(playerid,510.000000, 300.000000, "skin:");
    PlayerTextDrawBackgroundColor(playerid, Textdraw6, 255);
    PlayerTextDrawFont(playerid, Textdraw6, 2);
    PlayerTextDrawLetterSize(playerid, Textdraw6, 0.300000, 1.000000);
    PlayerTextDrawColor(playerid, Textdraw6, -1);
    PlayerTextDrawSetOutline(playerid, Textdraw6, 0);
    PlayerTextDrawSetProportional(playerid, Textdraw6, 1);
    PlayerTextDrawSetShadow(playerid, Textdraw6, 1);

    Textdraw7 = CreatePlayerTextDraw(playerid,510.000000, 310.000000, "saude");
PlayerTextDrawBackgroundColor(playerid,Textdraw7, 255);
PlayerTextDrawFont(playerid,Textdraw7, 2);
PlayerTextDrawLetterSize(playerid,Textdraw7, 0.300000, 1.000000);
PlayerTextDrawColor(playerid,Textdraw7, -1);
PlayerTextDrawSetOutline(playerid,Textdraw7, 0);
PlayerTextDrawSetProportional(playerid,Textdraw7, 1);
PlayerTextDrawSetShadow(playerid,Textdraw7, 1);

    AtualizarTextdraws(playerid); // Chama a função para atualizar os valores dinâmicos
}
forward GetPlayerCount();
public GetPlayerCount()
{
    new count = 0;
    for (new i = 0; i < MAX_PLAYERS; i++)
{
        if (IsPlayerConnected(i))
{
            count++;
        }
    }
    return count;
}
forward AtualizarTextdraws(playerid);
public AtualizarTextdraws(playerid)
{
    new nome[MAX_PLAYER_NAME];
    new grana[32], score[32], arma_id[32], players_online[32], ping[32], skin_id[32], saude[32];

    GetPlayerName(playerid, nome, sizeof(nome));
    format(nome, sizeof(nome), "Nome: %s(%d)", nome, playerid);
    format(grana, sizeof(grana), "Grana: %d", GetPlayerMoney(playerid));
    format(score, sizeof(score), "Score: %d", GetPlayerScore(playerid));
    format(arma_id, sizeof(arma_id), "Arma id: %d", GetPlayerWeapon(playerid));
    format(ping, sizeof(ping), "Ping: %d", GetPlayerPing(playerid));
    format(players_online, sizeof(players_online), "Online:%d", GetPlayerCount()); // Corrigido para usar GetPlayerCount()
    format(skin_id, sizeof(skin_id), "Skin ID: %d", GetPlayerSkin(playerid)); // Obtenha o ID da skin do jogador
   //colocar aq para formata a saude do player

    PlayerTextDrawSetString(playerid, Textdraw0, nome);          // Nome do jogador
    PlayerTextDrawSetString(playerid, Textdraw1, grana);          // Grana do jogador
    PlayerTextDrawSetString(playerid, Textdraw2, score);          // Score do jogador
    PlayerTextDrawSetString(playerid, Textdraw3, arma_id);        // ID da arma do jogador
    PlayerTextDrawSetString(playerid, Textdraw4, ping);          // Ping do jogador
    PlayerTextDrawSetString(playerid, Textdraw5, players_online); // Número de jogadores online
    PlayerTextDrawSetString(playerid, Textdraw6, skin_id);        // ID da skin do jogado
    PlayerTextDrawSetString(playerid, Textdraw7, saude);

    // Mostrar os TextDraws ao jogador
    PlayerTextDrawShow(playerid, Textdraw0);
    PlayerTextDrawShow(playerid, Textdraw1);
    PlayerTextDrawShow(playerid, Textdraw2);
    PlayerTextDrawShow(playerid, Textdraw3);
    PlayerTextDrawShow(playerid, Textdraw4);
    PlayerTextDrawShow(playerid, Textdraw5);
    PlayerTextDrawShow(playerid, Textdraw6);
    PlayerTextDrawShow(playerid, Textdraw7);
}

public OnPlayerSpawn(playerid)
{
    SetTimerEx("AtualizarTextdraws", 1000, true, "i", playerid);
}



RE: formatar para textdraw - BitSain - 17/10/2024

A função é essa: https://www.open.mp/docs/scripting/functions/GetPlayerHealth

Código:
new Float:health;
GetPlayerHealth(playerid, health);

"Embora a saúde possa ser definida para valores quase infinitos no lado do servidor, os clientes individuais só relatarão valores até 255. Qualquer valor maior será encapsulado; 256 se torna 0, 257 se torna 1, etc. A saúde é obtida arredondada para números inteiros: defina 50,15, mas obtenha 50,0"

Para calcular a porcentagem de vida de acordo com a informação acima seria:
Código:
// 0 à 100%
new Float:percentHealth = (health / 255.0) * 100.0;