Floats on a textdraw statbar, Pulls other players stats?
#1

ok, i made a stat bar, for health armour kills and deaths, floating them on a textdraw, but ingame, ID 0 see's ID 1's stats.


pawn Код:
forward stats();
public stats()
{
    for(new playerid; playerid < MAX_PLAYERS; playerid ++)
    {
        if(IsPlayerConnected(playerid))
        {
    new Float:pHealth, Float:pArmour, string[15];
    GetPlayerHealth(playerid,pHealth);
    format(string, sizeof(string), "Health:%.0f", pHealth);
    TextDrawSetString(Textdraw2, string);
   
    GetPlayerArmour(playerid,pArmour);
    format(string, sizeof(string), "Armour:%.0f", pArmour);
    TextDrawSetString(Textdraw3, string);
   
    format(string, sizeof(string), "Kills:%.0f", GetPlayerScore(playerid));
    TextDrawSetString(Textdraw4, string);
   
    format(string, sizeof(string), "Deaths:%.0f", GetPVarInt(playerid,"Deaths"));
    TextDrawSetString(Textdraw5, string);
        }
    }
}
Any ideas? I need this fixed as soon as possible, i have tryed EVERYTHING and still nothing.
Reply
#2

Why looping through all the players when you want to show the textdraw for a player only?

pawn Код:
forward stats(playerid);

public stats(playerid)
{
    new Float:pHealth, Float:pArmour, string[15];
    GetPlayerHealth(playerid,pHealth);
    format(string, sizeof(string), "Health:%.0f", pHealth);
    TextDrawSetString(Textdraw2, string);

    GetPlayerArmour(playerid,pArmour);
    format(string, sizeof(string), "Armour:%.0f", pArmour);
    TextDrawSetString(Textdraw3, string);

    format(string, sizeof(string), "Kills:%.0f", GetPlayerScore(playerid));
    TextDrawSetString(Textdraw4, string);

    format(string, sizeof(string), "Deaths:%.0f", GetPVarInt(playerid,"Deaths"));
    TextDrawSetString(Textdraw5, string);
}
Reply
#3

I beleive someone told me not to do it this way, but ill try it.

EDIT: Works, thanks .
Reply
#4

looping that way is for checking all players, not just one. Keep that in your mind
Reply
#5

Sure will, Someone told me to use
Код:
for(new playerid =0; playerid<MAX_PLAYERS; playerid++)
But all that did was lag then crash.
Reply
#6

The problem is, that you use same textdraws for all players. You should have textdraws for every player.
Reply
#7

Quote:
Originally Posted by [N
BL!nk ]
Sure will, Someone told me to use
Код:
for(new playerid =0; playerid<MAX_PLAYERS; playerid++)
But all that did was lag then crash.
If you use it correct; it will never crash
Reply
#8

Ok well.. i changed the look of the stat bar, and now it doesnt work anymore, all the other id's get id 0's stats.
Код:
public stats(playerid)
{
new Float:pHealth, Float:pArmour, string[15];
GetPlayerHealth(playerid,pHealth);
format(string, sizeof(string), "Health:%.0f", pHealth);
TextDrawSetString(Textdraw2, string);

GetPlayerArmour(playerid,pArmour);
format(string, sizeof(string), "Armour:%.0f", pArmour);
TextDrawSetString(Textdraw3, string);

format(string, sizeof(string), "Kills:%d", GetPlayerScore(playerid));
TextDrawSetString(Textdraw4, string);

format(string, sizeof(string), "Deaths:%d", GetPVarInt(playerid,"Deaths"));
TextDrawSetString(Textdraw5, string);

format(string, sizeof(string), "ID:%d", GetPlayerID(playerid));
TextDrawSetString(Textdraw6, string);
}
Reply
#9

Quote:
Originally Posted by MadeMan
The problem is, that you use same textdraws for all players. You should have textdraws for every player.
Reply
#10

I have also same problem that i only get stats from id 0

So how should it be fixed?
Reply
#11

Univited, i fixed this along time ago, use 1 textdraw.

Then use MAX_PLAYERS 1++ for it, then it works. hope i helped
Reply
#12

Please, help me. I dont understand what MAX_PLAYERS (i) do. When someone enters to the server the level textdraw should update. And that is what it does, I have this:
Quote:

public UpdateLevel()
{
new string[15];
format(string, sizeof(string), "%d", GetPVarInt(playerid, NIVELES));
TextDrawSetString(Textdraw1, string);
return 1;
}

So, this "UpdateLevel" happens when somebody level ups or when they spawn. For example I am level 10 and Im already in the server and then a level 50 spawns my textdraw also changes to 50.
Any solution? THANKS!
Reply
#13

Dude this is so old, i fixed this after i posted it
Reply
#14

May you help me? Thanks.
Reply
#15

yeah! the hole problem was, i was using two many textdraws with formated texts, Try to use 1 or two. and make a textdraw for everyplayer with a variable [MAX_PLAYERS].
Reply
#16

Could you explain me more detailed? I didnt understand anything. Can you give a pawn code of how can I fix what I previously posted? Thanks!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)