[Ajuda] Ajuda com floats :S
#1

Bom, to tentando ler uma float pra mostrar atravйs de um textdraw assim:

pawn Код:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
    new Float:health;
    GetPlayerHealth(playerid,health);
    new lifemostrar[3];
    format(lifemostrar,sizeof(lifemostrar),"%i",health);
    TextDrawSetString(life,lifemostrar);
    return 1;
}
Mas nгo importa o dano tomado, a textdraw sempre vai parar em 11 '-'

Alguma luz? obg desde ja
Reply
#2

pawn Код:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
    new Float:health;
    GetPlayerHealth(playerid, health);

    new lifemostrar[16];
    format(lifemostrar, sizeof lifemostrar, "%f", health);

    TextDrawSetString(life, lifemostrar);
    return 1;
}
Reply
#3

pawn Код:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid) {
    static
        Float:health,
        lifemostrar[16];

    format(lifemostrar, sizeof(lifemostrar), "%.0f", (GetPlayerHealth(playerid, health), health));
    TextDrawSetString(life, lifemostrar);
    return 1;
}
Reply
#4

Victor, seu codigo e o meu funcionam iguais.
Arrumei, o certo й um "placeholder" %f (Para floats) e nгo %i/d (Integer)
A vida que mostrava agora era a vida anterior a perda, entгo eu coloquei para mostrar a vida - o dano, ai deu certo.

Mas agora surgiu um outro problema, se o dano tomado for 30 e a vida do jogador for 20, o jogador MORRE, mas vai mostrar que a vida dele й 10. Por que? 20 - 30, = -10. (mas nгo mostra o sinal de negativo na text)

Entгo eu tentei fazer o seguinte

pawn Код:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
    new Float:health;
    GetPlayerHealth(playerid,health);
    new lifemostrar[3];
    if(GetPlayerHealth(playerid,health) - amount < 0)
    {
        TextDrawSetString(life,"0");
        printf("A vida era menor que 0. [%f]",health - amount);
        return 1;
    }
    format(lifemostrar,sizeof(lifemostrar),"%f",health - amount);
    TextDrawSetString(life,lifemostrar);
    return 1;
}
Para seta pra 0 se a vida for menor que 0. Mas nгo deu resultado... Qualquer dano que toma, a text vira 0.
Reply
#5

Up... Problema ainda nгo resolvido
Reply
#6

pawn Код:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
    new Float:health;
    GetPlayerHealth(playerid,health);
    new lifemostrar[3];
    if(health - amount < 0)
    {
        TextDrawSetString(life,"0");
        printf("A vida era menor que 0. [%f]",health - amount);
        return 1;
    }
    format(lifemostrar,sizeof(lifemostrar),"%f",health - amount);
    TextDrawSetString(life,lifemostrar);
    return 1;
}
Ps: fiz aki no Quick Reply
Reply
#7

pawn Код:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
        if(IsPlayerConnected(playerid)
                && issuerid != 65535)
        {
                new dano[80];
                format(dano, sizeof(dano),"Perda: -%d", floatround(amount, floatround_round));
                TextDrawSetString(life,dano);
                 TextDrawShowForPlayer(playerid,  life);
        }
        return true;
}
Divirta-se.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)