[Tutorial] How to make a score textdraw!
#1

Hello guys, I will now be showing you how to make a textdraw that shows your score!
It's pretty simple actually, but it's a special request and it could help alot of you guys, so I'll just teach you how to do it!
Let's get started!

First, let's call it ScoreTextdraw, we must add the following on the top of our script:
pawn Code:
new Text:ScoreTextdraw[MAX_PLAYERS];
OnGameModeInIt, we will be making a timer, let's add this:
pawn Code:
SetTimer("scoretimer", 1000, true);
We called our timer scoretimer, which we will use later.

Now we're done with that, let's move on to OnPlayerConnect.
We will here create the textdraw and how it works, and the position of it and everything.
I will now post a code and put comments so you understand it.
pawn Code:
new score[128];

    format(score, sizeof(score), "Score:%d",GetPlayerScore(playerid)); //So our textdraw will show Score: Yourscorehere, the %d is used for GetPlayerScore, which will get the player's score and show it here.
    ScoreTextdraw[playerid] = TextDrawCreate(498.000000, 118.000000, score); // we created the textdraw under the health and money thing, you can change the position though.
    TextDrawColor(ScoreTextdraw[playerid], 0x33AA33AA); // The color, you can put anything. I made it green here
    TextDrawAlignment(ScoreTextdraw[playerid],0); //This is the text alignment
    TextDrawFont(ScoreTextdraw[playerid], 2); // We chose a normal font, you can change it, check the samp wiki..
    TextDrawShowForPlayer(playerid, ScoreTextdraw[playerid]); // we are showing him the textdraw that we created
    TextDrawSetOutline(ScoreTextdraw[playerid],1); // We set the text's outline to 1
    TextDrawSetProportional(ScoreTextdraw[playerid],1); // Appears to scale text spacing to a proportional ratio
    TextDrawSetShadow(ScoreTextdraw[playerid],1); // Shadow size 1
Okay, we're done! But wait, one more thing! Now OnPlayerDisconnect we must hide the textdraw using:
pawn Code:
TextDrawDestroy(ScoreTextdraw[playerid]);
Aren't we forgetting something? Of course yes! The timer that we put OnGameModeInIt!
Let's do this now:
pawn Code:
forward scoretimer(playerid);
public scoretimer()
{
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            new score[128];
            format(score, sizeof(score), "Score:%d",GetPlayerScore(i));
            TextDrawSetString(ScoreTextdraw[i], score);
        }
    }
    return 1;
}
Don't worry, this is pretty simple.
As you can see above, we did a loop, we checked that if the player is online, it will update his Score Textdraw every second(scoretimer, 1000 OnGameModeInIt, this means every 1 second).

Okay guys, we're done! This was easy, wasn't it?
I hope I helped you somehow, and if you need more tutorials, feel free to request!
Thank you!

Oh, by the way, I made it simply just score so you get the idea of it, you can also make it for money, kills, deaths, etc..
Reply
#2

Another great job.
Reply
#3

Nice one.
Reply
#4

Good Job Man!
Reply
#5

Good work, sir. I admire the way you explained everything.

Amazing output!
Reply
#6

Thank you all for your comments
Reply
#7

nice, This explained me alot more about textdraws (didn't really understood them)
Reply
#8

Why not using Player TextDraws?

https://sampwiki.blast.hk/wiki/CreatePlayerTextDraw

It's good tutorial but I would still use Player Textdraws.
Reply
#9

Well I thought it would be better to make it a textdraw for everyone with score changing for every player, that's why I made a timer for that.
Anyway, good idea too, it can be done both ways
Reply
#10

Simple but amazing, well done.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)