Textdraw scoore shows score of someone else
#1

guys my problem is that the score textdraw shows the score of player that has highest score.So i want every player to have his own textdraw Score.
heres my code

At top
pawn Код:
new Text:Textdraw1;//Score TextDraw Hud
On gamemod init
pawn Код:
Textdraw1 = TextDrawCreate(498.000000, 101.000000, "~g~score~w~:0000");
    TextDrawBackgroundColor(Textdraw1, 255);
    TextDrawFont(Textdraw1, 3);
    TextDrawLetterSize(Textdraw1, 0.500000, 0.799999);
    TextDrawSetOutline(Textdraw1, 0);
    TextDrawSetProportional(Textdraw1, 1);
    TextDrawSetShadow(Textdraw1, 1);
    SetTimer("scoretimer", 1000, true);//Score textdraw Timer update
On player spawn
pawn Код:
new score[128];//Score textdraw string
TextDrawShowForPlayer(playerid,Textdraw1);
format(score,sizeof(score),"~g~Score~w~:%d",GetPlayerScore(playerid));
TextDrawSetString(Textdraw1,score);
and finally i made a loop but it doesnt show the score of player but shows the highest score of a random guy
pawn Код:
forward scoretimer(playerid);
public scoretimer()
{
    for(new i = 1; i>0; i++)
    {
        if(IsPlayerConnected(i))
        {
            new score[128];
            format(score, sizeof(score), "~g~Score~w~:%d",GetPlayerScore(i));
            TextDrawSetString(Textdraw1, score);
        }
    }
    return 1;
}
Reply
#2

Try These
pawn Код:
new Text:Textdraw1[MAX_PLAYERS];

//OnGameModeInit
for (new i = 0; i < MAX_PLAYERS; i++)
{
    Textdraw1[i] = TextDrawCreate(498.000000, 101.000000, "~g~score~w~:0000");
    TextDrawBackgroundColor(Textdraw1[i], 255);
    TextDrawFont(Textdraw1[i], 3);
    TextDrawLetterSize(Textdraw1[i], 0.500000, 0.799999);
    TextDrawSetOutline(Textdraw1[i], 0);
    TextDrawSetProportional(Textdraw1[i], 1);
    TextDrawSetShadow(Textdraw1[i], 1);
}

SetTimer("scoretimer", 1000, true);//Score textdraw Timer update


forward scoretimer();//Put it anywhere
public scoretimer()
{
    for (new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            new score[128];
            PScore = GetPlayerScore(i);
            format(score, sizeof(score), "~g~Score~w~:%d",PScore);
            TextDrawShowForPlayer(playerid, Textdraw1[i]);
            TextDrawSetString(Textdraw1, score);
        }
    }
    return 1;
}
PS - Hope You will enjoy it
Reply
#3

Don't use a timer...use OnPlayerUpdate to set each player's TextDraw
Reply
#4

Quote:
Originally Posted by alinategh
Посмотреть сообщение
Don't use a timer...use OnPlayerUpdate to set each player's TextDraw
It doesn't really matter, to be honest.
Reply
#5

Quote:
Originally Posted by alinategh
Посмотреть сообщение
Don't use a timer...use OnPlayerUpdate to set each player's TextDraw
I would prefer using a timer that it's called once every 1-2 seconds than using OnPlayerUpdate and gets called 30 times a second.
Reply
#6

Don't use OnPlayerUpdate for that, it will update each movement you make wether you're walking or changing your camera view.

I suggest you to only update a players textdraw when their score actually changed for example: OnPlayerDeath.

If you want to update it each second for individual player you should go with pds2012's code.
Reply
#7

Do what xFuTuRe told you, hook SetPlayerScore and update the textdraw in it because thats the only place where it could change

pawn Код:
// somewhere over the functions / publics or in a include file

stock hSetPlayerScore(playerid, score) {
    static
        tmp[32] = "~g~Score~w~: "
    ;
    valstr(tmp[13], score, false);
    TextDrawSetString(Textdraw1[playerid], score);
    return SetPlayerScore(playerid, score);
}
#if defined _ALS_SetPlayerScore
    #undef SetPlayerScore
#else
    #define _ALS_SetPlayerScore
#endif
#define SetPlayerScore hSetPlayerScore
Reply
#8

You can use my include for that: OnPlayerScoreStateChange. See under my Sig.
Reply
#9

i got error this
pawn Код:
D:\SAMP STUFF\SAMP HOST\gamemodes\battlefieldbetaclasssystem.pwn(1806) : error 035: argument type mismatch (argument 2)
D:\SAMP STUFF\SAMP HOST\gamemodes\battlefieldbetaclasssystem.pwn(1808) : error 035: argument type mismatch (argument 1)
Line 1806:
pawn Код:
TextDrawShowForPlayer(playerid,Textdraw1);
Line 1808:
pawn Код:
TextDrawSetString(Textdraw1,score);
Also these 2 errors
(3922) : error 017: undefined symbol "playerid"
(3923) : error 035: argument type mismatch (argument 1)
Line 3922:
pawn Код:
TextDrawShowForPlayer(playerid, Textdraw1[i]);
line 3923:
pawn Код:
TextDrawSetString(Textdraw1, score);
overall code for line 3922 and 3923 is:
pawn Код:
forward scoretimer();//Put it anywhere
public scoretimer()
{
    for (new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            new score[128];
            score = GetPlayerScore(i);
            format(score, sizeof(score), "~g~Score~w~:%d",score);
            TextDrawShowForPlayer(playerid, Textdraw1[i]);
            TextDrawSetString(Textdraw1, score);
        }
    }
    return 1;
}
Reply
#10

Replace every Textdraw1 with Textdraw1[i] under the scoretimer.
All the others with Textdraw1[playerid]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)