[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


Messages In This Thread
How to make a score textdraw! - by JimmyCh - 25.07.2013, 22:30
Re: How to make a score textdraw! - by Mckarlis - 25.07.2013, 22:30
Re: How to make a score textdraw! - by ThePhenix - 25.07.2013, 22:53
Re: How to make a score textdraw! - by Celebesgamer - 26.07.2013, 01:05
Re: How to make a score textdraw! - by MiFi - 26.07.2013, 05:45
Re: How to make a score textdraw! - by JimmyCh - 26.07.2013, 07:56
Re: How to make a score textdraw! - by ThaCrypte - 01.08.2013, 13:26
Re: How to make a score textdraw! - by [MG]Dimi - 21.08.2013, 17:52
Re: How to make a score textdraw! - by JimmyCh - 21.08.2013, 17:59
Re: How to make a score textdraw! - by DaniceMcHarley - 21.08.2013, 18:29

Forum Jump:


Users browsing this thread: 5 Guest(s)