[Tutorial] Player Score
#1

Introduction
Today I will teach you how to use Player Score. The system we will use can benefit your server or hopefuly increase your scripting skills. Everthing will be fully explained.


Getting player score
First of all, each time we want to make something that includes the player score, we need to get it first, right? There is function called GetPlayerScore(playerid) inside the pawno, but the main question is how to use it. There are many ways to find out the player score and format it, depending on what you want to make.

Let's get normal example of how we can make /myscore command.

Код:
new string[128];
Making a string where we will store everything we want

Код:
format(string, sizeof(string), "Score: %i",GetPlayerScore(playerid));
We will format the message we want to send to the player. As you can see the i% is out actual score. That's where our score is held, basically the "%i" is our score. As you can see the other part of the format, we are formating the string that we previously made, and later on we are explaining what we want to do thru the GetPlayerScore.

Код:
SendClientMessage(playerid, 0x0000BBAA, string);
We are sending the formated message to the player. The "string" That we are sending him is the one that we used under the format. If you want, you can add more things into it.

As for now, we have entire thing, but we are missing something, arent we? We need the actual command.
For those that already learned some stuff in Pawno will know that great thing for making commands (ZCMD) should be used while scripting. So let's format the command.

PHP код:
CMD:myscore(playeridparams[]) //Formating the command
{
    new 
string[128]; //This is the place where we will store our score and the message we want to send.
    
format(stringsizeof(string), "Score: %i",GetPlayerScore(playerid)); //We are formating the message we want to send. The %i is our score.
    
SendClientMessage(playerid0x0000BBAAstring); //We are sending the message to the player that we formated using Format above. The 0x0000BBAA is our color! It's blue color.
    
return 1;


Score as ranks
We saw previously that GetPlayerScore is very handy. Well no matter what you made, level system or such, you can always use GetPlayerScore. The score is basicaly the numbers that are in the middle of the screen when you press button "tab" in game.
Now let's get back onto the scripting. What we want to make is to identify whenever player is score From to Point. Basicaly for example if the player score is 1 from 10 we will format certain message.


Код:
new Rank[2];
We are basicaly making maximum ranks by this. The 2 number inside the brackets is how much ranks we can define. As you raise that number, it will increase how much ranks we want to make.
Код:
switch(GetPlayerScore(playerid)) {
We are swtching now. What does that mean? Well since we already formated how much ranks we want to have, we will check the player score by this and we will start formating our ranks.

Код:
case 0 .. 10: format(Rank, sizeof(Rank),"[Rank1]");
What did we make here? First thing you gotta understand is the Case. The case basicaly says this. Case is rank 1, if the player score is from 0 to 10 we will send the folowing message. As you already saw previously, you will know what is format. We will format the message we want to send. We are not using the "string" this time, we are using the "Rank". Why? Well in the last code we made, we called the new variable "string" and now we are calling it rank. As you can see the following we are making sure that our rank is sizeof the new variable we made, and at the end we are opening quotes and giving the rank it's name.

Код:
new ChatText[128], Nameasd[MAX_PLAYER_NAME];
GetPlayerName(playerid, Nameasd, MAX_PLAYER_NAME);
format(ChatText, sizeof(ChatText),"{F3FF02}%s %s:{FFFFFF} %s", Rank, Nameasd, text);
SendClientMessageToAll(-1, ChatText);
return 0;
What we firstly made is another variable called ChatText. The chat text will be lenght of the message we want to send, in this case 128 letters. Nameasd is our variable to get player name. Afterwards, we are formating the message we want to send. How does it work? First we are getting PlayerRank, then we are getting the rank then the text. So if you want to change that, change the last few words inside the format. We are returning 0. Why? Well if you set it to 1, the message will be sent twice. Once it will be without our format and once with our format.

Setting and Giving player score
With the GetPlayerScore we also have custom thing called SetPlayerScore. What does it do? The SetPlayerScore(playerid, ammount) sets the player score to desider amount. If for example we want player score to be 10 we will just add
Код:
SetPlayerScore(playerid, 10);
But what we should do if we want to increase player score by 10?
Let's add a simple script that will give a killer +1 score when he kills someone.
Add under OnPlayerDeath
Код:
if(killerid != INVALID_PLAYER_ID) //If the killer exist we will continue. it determines if the player didnt die by falling etc.
    { //Opening the things
        SetPlayerScore(killerid, GetPlayerScore(killerid) + 1); //By this we are giving the killer +1 score
	} //Closing the stuff
Preety much self explaining. We are stting the player score, but before we actual set how much we want, we will get his score and just add into it. If we use SetPlayerScore(playerid, amount) it will just set the player score, but if we also get his score, we will "add" his score.

Using If
If we want to make something, we will always need the if. What is if? It basicaly means If(ThePlayerHasSomething == yes/no). Of course, if you compile this, your pawno willl get 1000 errors. I just gave an example of how it looks. Now let's make a command that will prevent player to use the command if he/she doesnt have enough score.

Код:
if(GetPlayerScore(playerid) >= 0 && GetPlayerScore(playerid) < 10)
By this, we are checking if the player score is greater than 0 and if it's lower than 10. If not we will add something that will prevent him from using it.
Код:
CMD:healz(playerid, params[]) //Making the command
{
    if(GetPlayerScore(playerid) >= 0 && GetPlayerScore(playerid) < 10)// score is greater than 0 and less than 10
    {
		SetPlayerArmour(playerid, 100); //Setting the armour
		return 1;
	}
	else
	{
		//What will it do if the player doesnt have score how much we want.
		SendClientMessage(playerid, COLOR_RED, "<!>NO!");
	}
	return 1;
}
Codes used
My score command
Код:
CMD:myscore(playerid, params[]) //Formating the command
{
    new string[128]; //This is the place where we will store our score and the message we want to send.
    format(string, sizeof(string), "Score: %i",GetPlayerScore(playerid)); //We are formating the message we want to send. The %i is our score.
    SendClientMessage(playerid, 0x0000BBAA, string); //We are sending the message to the player that we formated using Format above. The 0x0000BBAA is our color! It's blue color.
    return 1;
}
Ranks in chat
Код:
public OnPlayerText(playerid, text[])
{
	new Rank[20];
    switch(GetPlayerScore(playerid))
    {
        case 0 .. 10: format(Rank, sizeof(Rank),"[Rank 1]");
        case 11 .. 20: format(Rank, sizeof(Rank),"[Rank 2]");
	}
	new ChatText[128], Nameasd[MAX_PLAYER_NAME];
    GetPlayerName(playerid, Nameasd, MAX_PLAYER_NAME);
    format(ChatText, sizeof(ChatText),"{F3FF02}%s %s:{FFFFFF} %s", Rank, Nameasd, text);
    SendClientMessageToAll(-1, ChatText);
    return 0;
}
Heal command
Код:
CMD:healz(playerid, params[]) //Making the command
{
    if(GetPlayerScore(playerid) >= 0 && GetPlayerScore(playerid) < 10)// score is greater than 0 and less than 10
    {
		SetPlayerArmour(playerid, 100); //Setting the armour
		return 1;
	}
	else
	{
		//What will it do if the player doesnt have score how much we want.
		SendClientMessage(playerid, COLOR_RED, "<!>NO!");
	}
	return 1;
}
Credits
-Samp scripting team
-Zeex (zcmd)
-All people that ever helped me on samp.
Reply


Messages In This Thread
Player Score - by Pawnie - 05.04.2013, 02:23
Re: Player Score - by Battlezone - 18.10.2013, 19:11

Forum Jump:


Users browsing this thread: 1 Guest(s)