[Tutorial] Making your own rank system!
#1


(banner by: Jansish)
Introduction

Welcome!
Well, yea I'm unbanned
So ahm... I'm going to do a tutorial, explaining how to do your own rank system!

Basically, ranks define what position you/others are compared to others.
So its easy to see who's the best at a certain skill.

Scripting

For this tutorial, I'm not going to require any "add-ons" such as sscanf and so.

So, I'm going to base this rank system, on scores.
This means, we will see if a person has a certain amount of score, making him rank up or not.

Lets make some defines!
pawn Код:
#define RANK_NEWBIE 0
#define RANK_COOL 1
#define RANK_OMGVAMPIRE 2
We're assigning them to certain numbers.
So like that, it will be easier to manage the ranks, instead of using 0, 1 and 2, we can simply use RANK_NEWBIE and such.
Q: Why are we using defines and not a normal variable?
A: Well, defines, most of the times is faster and easier to use.
Imagine, assigning a variable with another variable, would take more time than assigning a variable with the ... lets call it compiler language? Because using defines, we're messing around with raw information, causing it to change the compiler information, thats why when we're using macros (defines or other # information) its mainly faster than messing with variables.


Lets create the variables!
pawn Код:
new pRank[MAX_PLAYERS];
So, that variable, will be to store the current rank of the player, allowing us to use it each time we want to,
Instead of calling a function each time we want to know, that would include making calculations and such.

Under OnPlayerConnect put:
pawn Код:
pRank[playerid] = RANK_NEWBIE;
That means, each time the player connects, it will reset his rank back to newbie. (unless you use a register/login system to save and load his rank)
You can also use it under OnPlayerDisconnect, but IMHO its better to use it under OnPlayerConnect, but in this case it doesnt really matter, as we're assigning RANK_NEWBIE to 0, and since the pRank variable, when created, its being automatically assigned to 0, it doesn't really matter, but we'd assign RANK_NEWBIE to 1 and the player had never connected and we we're assigning the pRank variable to RANK_NEWBIE under OnPlayerDisconnect, some information could go wrong.
So IMHO, put it under OnPlayerConnect.


Lets make a function, thats calculates whats the rank the player is!
So, right in the bottom of your script, you should make something like this:
pawn Код:
forward CheckPlayerRank(playerid);
public CheckPlayerRank(playerid)
{
new iScore = GetPlayerScore(playerid);
switch(iScore)
{
case 0..100:
{
pRank[playerid] = RANK_NEWBIE;
//Rest of the information here.
}
case 101..200:
{
pRank[playerid] = RANK_COOL;
//Rest of the information here.
}
default:
{
pRank[playerid] = RANK_OMGVAMPIRE;
//Rest of the information here.
}
}
return 1;
}
So, first of all, we're storing the players score, making it easier for the managment of the players score (if you want to use it furtheron)

After that, we're checking if the player's score is within one of the statements, that is:
If its within 0 and 100 it will set his rank to RANK_NEWBIE
If its within 101 and 200 it will set his rank to RANK_COOL
If its nether of those (higher or lower than those numbers) it will set his rank to RANK_OMGVAMPIRE.
Thats what default is for (mainly), if its none of the values checked, it will go to the default sub-function.

In theses cases, using switch is more... cleaner? Not faster nor more efficient, it just makes the script more organised, instead of doing if..else if... else if... else.
Get what I mean?

So, if you want to make this according to kills (if you have linked the kills variable to the score), you can just do something like:
pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
SetPlayerScore(playerid, GetPlayerScore(playerid)-1);
CheckPlayerRank(playerid);

if(IsPlayerConnected(killerid))
{
SetPlayerScore(killerid, GetPlayerScore(killerid)+1);
CheckPlayerRank(killerid);
}
return 1;
}
What we are doing is, when a player dies he will lose 1 of score.
After that, we're checking if the killerid is connect.
If the killerid was not connected (could be a death by collision), we're setting the score of a player that is not connected, and if you have crash detect it will appear an error.
So, after checking if the killerid is connected, we're setting giving him +1 score.
Then we're checking his rank.
If the killers id score would be 101 it would make his score to RANK_COOL.


You could make a textdraw showing the players rank!

The end

Well I hope you liked it!
If you have any questions/critics, be sure to post them here, so we can discuss about it.
jnfag pls
Reply
#2

OMG i didn't know you are unbanned mate welcome back :P and good tutorial (even though i didn't read it)
Reply
#3

Nice TUT FireCat :P I needed this For My New Project
Reply
#4

Quote:
Originally Posted by Glint
Посмотреть сообщение
OMG i didn't know you are unbanned mate welcome back :P and good tutorial (even though i didn't read it)
Hum, thanks?

Edit: Deron, no problem!
Reply
#5

Nice work! Welcome back Fireslut! Now shhh :P!
Reply
#6

Quote:
Originally Posted by DoctorRapist
Посмотреть сообщение
Nice work! Welcome back Fireslut! Now shhh :P!
((( thanks, hehe
Reply
#7

Welcome back FireCat,although I'm the first who greeted you for getting unbanned .


On: Great explnation finally found a tutorial which explains a 15 letter code,I'm going to use this!
Reply
#8

Quote:
Originally Posted by James_Nick
Посмотреть сообщение
Welcome back FireCat,although I'm the first who greeted you for getting unbanned .


On: Great explnation finally found a tutorial which explains a 15 letter code,I'm going to use this!
I'm glad I helped!
Reply
#9

omg ty so much so helpful i can make my own rp server now ty!!! firecat welcome back ur unbanned1!
Reply
#10

Quote:
Originally Posted by Jansish
Посмотреть сообщение
omg ty so much so helpful i can make my own rp server now ty!!! firecat welcome back ur unbanned1!
gf edit + refunds 127.0.1.0 pls

Lol, thanks!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)