Crazy rank system.
#1

Hi there.

Iґm currently trying to create a rank system but somehow its fucked up. I dont know why. Can someone see a error here?

OnPlayerConnect -
Код:
	
    new pn[MAX_PLAYER_NAME], connect[48];
	GetPlayerName(playerid, pn, sizeof(pn));
	format(connect, sizeof(connect), "/userfiles/%s.ini", pn );
    number = dini_Int(connect,"kills");
	number = killzstats[playerid];
At OnPlayerDeath..

Код:
killzstats[killerid]++;
And in a timer called every 15 seconds:

Код:
public rankcheck()
{
  for(new i=0; i<MAX_PLAYERS; i++)
  {
  	new pn[MAX_PLAYER_NAME], connect[48];
	GetPlayerName(i, pn, sizeof(pn));
	format(connect, sizeof(connect), "/userfiles/%s.ini", pn );
	dini_IntSet(connect,"kills", killzstats[i]);
	if(killzstats[i] >= 0)
	{
	rank[i] = 0;
	TextDrawSetString(ranktext[i],"Rank: Private");
  }
  	else if(killzstats[i] > 19)
	{
	rank[i] = 1;
	TextDrawSetString(ranktext[i],"Rank: Soldier");
  }
  	else if(killzstats[i] > 49)
	{
	rank[i] = 2;
	TextDrawSetString(ranktext[i],"Rank: Sergeant");
  }
  	else if(killzstats[i] > 100)
	{
	rank[i] = 3;
	TextDrawSetString(ranktext[i],"Rank: General");
  }
	}
}
Whats wrong?
Reply
#2

You are setting the value of "number" twice. I dont know what "number" is exactly used for, but it seems that you are using killzstats[playerid] variable as the basis of the rank. So i left the number variable as you did, but changed the killzstats variable.

OnPlayerConnect:
pawn Код:
new pn[MAX_PLAYER_NAME], connect[48];
    GetPlayerName(playerid, pn, sizeof(pn));
    format(connect, sizeof(connect), "/userfiles/%s.ini", pn);
    number = dini_Int(connect,"kills");
    killzstats[playerid] = number; // not really necessary
pawn Код:
public rankcheck()
{
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        new pn[MAX_PLAYER_NAME], connect[48];
        GetPlayerName(i, pn, sizeof(pn));
        format(connect, sizeof(connect), "/userfiles/%s.ini", pn );
        dini_IntSet(connect,"kills", killzstats[i]);
        if(killzstats[i] >= 0)
        {
            rank[i] = 0;
            TextDrawSetString(ranktext[i],"Rank: Private");
        }
        else if(killzstats[i] >= 1 && killzstats[i] <= 19) // 1-19
        {
            rank[i] = 1;
            TextDrawSetString(ranktext[i],"Rank: Soldier");
        }
        else if(killzstats[i] > 20 && killzstats[i] <= 49) //20-49
        {
            rank[i] = 2;
            TextDrawSetString(ranktext[i],"Rank: Sergeant");
        }
        else if(killzstats[i] >= 50) //50+ (You had this missing) Only had 100+
        {
            rank[i] = 3;
            TextDrawSetString(ranktext[i],"Rank: General");
        }
    }
}
Note: You had Kills between 50-100 missing.

Hope that helps.
Reply
#3

Great thank you! At least the kills save now.

Another question

Код:
	if(strcmp(cmd, "/rankinfo", true) == 0)
	{
	new string1[48],string2[48],string3[48],string4[128],mstring[264];
	if(killzstats[playerid] < 20)
	{
		format(string1, sizeof string1, "Rank: Private");
		format(string2, sizeof string2, "Kills: %d",killzstats);
		format(string3, sizeof string3, "Kills needed: 20 For next rank: Soldier");
		format(string4, sizeof string4, "Vehicles: Patriot, Barracks, Sanchez, Rustler.");
		format(mstring, sizeof mstring, "%s\n%s\n%s\n%s", string1,string2,string3,string4);
	}
	else if(killzstats[playerid] > 19)
	{
		format(string1, sizeof string1, "Rank: Soldier");
		format(string2, sizeof string2, "Kills: %d",killzstats);
		format(string3, sizeof string3, "Kills needed: 50 For next rank: Sergeant");
		format(string4, sizeof string4, "Vehicles: Patriot,Barracks,Sanchez,Rustler,\nSeasparrow.");
		format(mstring, sizeof mstring, "%s\n%s\n%s\n%s", string1,string2,string3,string4);
	}
	else if(killzstats[playerid] > 49)
	{
		format(string1, sizeof string1, "Rank: Sergeant");
		format(string2, sizeof string2, "Kills: %d",killzstats);
		format(string3, sizeof string3, "Kills needed: 100 For next rank: General");
		format(string4, sizeof string4, "Vehicles: Patriot, Barracks, Sanchez, Rustler,\nSeasparrow, Rhino, Hydra.");
		format(mstring, sizeof mstring, "%s\n%s\n%s\n%s", string1,string2,string3,string4);
	}
	else if(killzstats[playerid] > 99)
	{
		format(string1, sizeof string1, "Rank: General");
		format(string2, sizeof string2, "Kills: %d",killzstats);
		format(string3, sizeof string3, "Kills needed: - For next rank: -");
		format(string4, sizeof string4, "Vehicles: Patriot, Barracks, Sanchez, Rustler,\nSeasparrow, Rhino, Hydra, Hunter");
		format(mstring, sizeof mstring, "%s\n%s\n%s\n%s", string1,string2,string3,string4);
	}
	ShowPlayerDialog(playerid,911,DIALOG_STYLE_MSGBOX,"Rank info",mstring,"Okay","Cancel");
	return 1;
  }
The wrong number of kills gets displayed here. Why?
Reply
#4

That is because you didn't set the killzstats rank checks properly. Here is the correct one in accordance to the original one i gave you:
pawn Код:
if(strcmp(cmd, "/rankinfo", true) == 0)
    {
        new string1[48],string2[48],string3[48],string4[128],mstring[264];
        if(killzstats[playerid] <= 0)
        {
            format(string1, sizeof string1, "Rank: Private");
            format(string2, sizeof string2, "Kills: %d",killzstats);
            format(string3, sizeof string3, "Kills needed: 20 For next rank: Soldier");
            format(string4, sizeof string4, "Vehicles: Patriot, Barracks, Sanchez, Rustler.");
            format(mstring, sizeof mstring, "%s\n%s\n%s\n%s", string1,string2,string3,string4);
        }
        else if(killzstats[playerid] >= 1 && killzstats[playerid] <= 19) // 1-19
        {
            format(string1, sizeof string1, "Rank: Soldier");
            format(string2, sizeof string2, "Kills: %d",killzstats);
            format(string3, sizeof string3, "Kills needed: 50 For next rank: Sergeant");
            format(string4, sizeof string4, "Vehicles: Patriot,Barracks,Sanchez,Rustler,\nSeasparrow.");
            format(mstring, sizeof mstring, "%s\n%s\n%s\n%s", string1,string2,string3,string4);
        }
        else if(killzstats[playerid] > 20 && killzstats[playerid] <= 49) //20-49
        {
            format(string1, sizeof string1, "Rank: Sergeant");
            format(string2, sizeof string2, "Kills: %d",killzstats);
            format(string3, sizeof string3, "Kills needed: 100 For next rank: General");
            format(string4, sizeof string4, "Vehicles: Patriot, Barracks, Sanchez, Rustler,\nSeasparrow, Rhino, Hydra.");
            format(mstring, sizeof mstring, "%s\n%s\n%s\n%s", string1,string2,string3,string4);
        }
        else if(killzstats[playerid] >= 50) //50+
        {
            format(string1, sizeof string1, "Rank: General");
            format(string2, sizeof string2, "Kills: %d",killzstats);
            format(string3, sizeof string3, "Kills needed: - For next rank: -");
            format(string4, sizeof string4, "Vehicles: Patriot, Barracks, Sanchez, Rustler,\nSeasparrow, Rhino, Hydra, Hunter");
            format(mstring, sizeof mstring, "%s\n%s\n%s\n%s", string1,string2,string3,string4);
        }
        ShowPlayerDialog(playerid,911,DIALOG_STYLE_MSGBOX,"Rank info",mstring,"Okay","Cancel");
        return 1;
    }
For your reference, the Ranks are:
Код:
0 or less: Rank: Private
1-19: Rank: Soldier
20- 49:Rank: Sergeant
50+: Rank: General
Note: I edited my first post - I realised a little error. Please update.
Reply
#5

Thank you so much! Just one bug: It still says "Rank: Private" even If I got 21 kills. Why?
Reply
#6

EDIT: After a server restart it says 0 kills in /rankinfo, but in the file thereґs 21. Q_Q
Reply
#7

Quote:
Originally Posted by Mo3
Thank you so much! Just one bug: It still says "Rank: Private" even If I got 21 kills. Why?
Which one is saying that you're rank is Private? The Textdraw or the /rankinfo?

If it isthe textdraw, then you are not showing the player his textdraw in the timer. Change the timer to this:

pawn Код:
public rankcheck()
{
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        new pn[MAX_PLAYER_NAME], connect[48];
        GetPlayerName(i, pn, sizeof(pn));
        format(connect, sizeof(connect), "/userfiles/%s.ini", pn );
        dini_IntSet(connect,"kills", killzstats[i]);
        if(killzstats[i] >= 0)
        {
            rank[i] = 0;
            TextDrawSetString(ranktext[i],"Rank: Private");
            TextDrawShowForPlayer(i, ranktext[i]);
        }
        else if(killzstats[i] >= 1 && killzstats[i] <= 19) // 1-19
        {
            rank[i] = 1;
            TextDrawSetString(ranktext[i],"Rank: Soldier");
            TextDrawShowForPlayer(i, ranktext[i]);
        }
        else if(killzstats[i] > 20 && killzstats[i] <= 49) //20-49
        {
            rank[i] = 2;
            TextDrawSetString(ranktext[i],"Rank: Sergeant");
            TextDrawShowForPlayer(i, ranktext[i]);
        }
        else if(killzstats[i] > ) //50+ (You had this missing) Only had 100+
        {
            rank[i] = 3;
            TextDrawSetString(ranktext[i],"Rank: General");
            TextDrawShowForPlayer(i, ranktext[i]);
        }
    }
}
EDIT:

Quote:
Originally Posted by Mo3
EDIT: After a server restart it says 0 kills in /rankinfo, but in the file thereґs 21. Q_Q
You didn't format the string correctly. Here is the fixed one:

pawn Код:
if(strcmp(cmd, "/rankinfo", true) == 0)
    {
        new string1[48],string2[48],string3[48],string4[128],mstring[264];
        if(killzstats[playerid] >= 0)
        {
            format(string1, sizeof string1, "Rank: Private");
            format(string2, sizeof string2, "Kills: %d",killzstats[playerid]);
            format(string3, sizeof string3, "Kills needed: 20 For next rank: Soldier");
            format(string4, sizeof string4, "Vehicles: Patriot, Barracks, Sanchez, Rustler.");
            format(mstring, sizeof mstring, "%s\n%s\n%s\n%s", string1,string2,string3,string4);
        }
        else if(killzstats[playerid] >= 1 && killzstats[playerid] <= 19) // 1-19
        {
            format(string1, sizeof string1, "Rank: Soldier");
            format(string2, sizeof string2, "Kills: %d",killzstats[playerid]);
            format(string3, sizeof string3, "Kills needed: 50 For next rank: Sergeant");
            format(string4, sizeof string4, "Vehicles: Patriot,Barracks,Sanchez,Rustler,\nSeasparrow.");
            format(mstring, sizeof mstring, "%s\n%s\n%s\n%s", string1,string2,string3,string4);
        }
        else if(killzstats[playerid] > 20 && killzstats[playerid] <= 49) //20-49
        {
            format(string1, sizeof string1, "Rank: Sergeant");
            format(string2, sizeof string2, "Kills: %d",killzstats[playerid]);
            format(string3, sizeof string3, "Kills needed: 100 For next rank: General");
            format(string4, sizeof string4, "Vehicles: Patriot, Barracks, Sanchez, Rustler,\nSeasparrow, Rhino, Hydra.");
            format(mstring, sizeof mstring, "%s\n%s\n%s\n%s", string1,string2,string3,string4);
        }
        else if(killzstats[playerid] >= 50) //50+
        {
            format(string1, sizeof string1, "Rank: General");
            format(string2, sizeof string2, "Kills: %d",killzstats[playerid]);
            format(string3, sizeof string3, "Kills needed: - For next rank: -");
            format(string4, sizeof string4, "Vehicles: Patriot, Barracks, Sanchez, Rustler,\nSeasparrow, Rhino, Hydra, Hunter");
            format(mstring, sizeof mstring, "%s\n%s\n%s\n%s", string1,string2,string3,string4);
        }
        ShowPlayerDialog(playerid,911,DIALOG_STYLE_MSGBOX,"Rank info",mstring,"Okay","Cancel");
        return 1;
    }
Reply
#8

After another restart, the server said for all 4 people testing with me: Kills: 30. WTF?
Reply
#9

Quote:
Originally Posted by Mo3
After another restart, the server said for all 4 people testing with me: Kills: 30. WTF?
PM me ur server IP, i'll be there.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)