Rank help
#1

I made a rank system, everything works, im just having some problems with saving and loading.

This is the rank variable:

Код:
new const gRank[][e_RANK] =
{
	{"Private",				0,		MAX_HEALTH,	0.0},
	{"Private First Class",	50,		MAX_HEALTH,	0.0},
	{"Specialist",			100,	75.0,	0.0},
	{"Corporal",			500,	MAX_HEALTH,	5.0},
	{"Sergeant",			1000,	MAX_HEALTH,	5.0},
	{"Staff Sergeant",		1500,	MAX_HEALTH,	15.0},
	{"Master Sergeant",		2500,	MAX_HEALTH,	15.0},
	{"Sergeant Major",		4500,	MAX_HEALTH,	40.0},
	{"Officer",				6000,	MAX_HEALTH,	50.0},
	{"Warrant Officer",		7500,	MAX_HEALTH,	60.0},
	{"Chief Warrant Officer",9000,	MAX_HEALTH,	70.0},
	{"Lieutenant",			10000,	MAX_HEALTH,	70.0},
	{"First Lieutenant",	12500,	MAX_HEALTH,	85.0},
	{"Second Lieutenant",	15000,	MAX_HEALTH,	MAX_ARMOUR},
	{"Captain",	 			20000,	MAX_HEALTH,	MAX_ARMOUR},
	{"Major",				25000,	MAX_HEALTH,	MAX_ARMOUR},
	{"Colonel",				30000,	MAX_HEALTH,	MAX_ARMOUR},
	{"Marshall",			33000,	MAX_HEALTH,	MAX_ARMOUR},
	{"Field Marshall",		37000,	MAX_HEALTH,	MAX_ARMOUR},
	{"General",				40000,	MAX_HEALTH,	MAX_ARMOUR},
	{"Brigadier General",	45000,	MAX_HEALTH,	MAX_ARMOUR},
	{"Major General",		50000,	MAX_HEALTH,	MAX_ARMOUR},
	{"Master Of War",		60000,	MAX_HEALTH,	MAX_ARMOUR},
	{"God Of War",			9999999,MAX_HEALTH,	MAX_ARMOUR}
};
This is what i do to load the rank after the login:

Код:
cache_get_value_int(0, "Rank", Player[playerid][Rank]);
And this is what i do after the player quits and i save the data:

Код:
UpdatePlayerData(playerid)
{
	if (Player[playerid][IsLoggedIn] == false) return 0;
	new query[180];
	mysql_format(g_SQL, query, sizeof query, "UPDATE `players` SET `Kills` = %d,`Deaths` = %d,`Score` = %i,`Money` = %i, `Level` = %d,`Cookies` = %d, `Warns`, `Vip` = %d, `Banned` = %d, `Rank` = %s WHERE `id` = %d LIMIT 1",
	Player[playerid][Kills],
	Player[playerid][Deaths],
	GetPlayerScore(playerid),
	GetPlayerMoney(playerid),
	Player[playerid][Level],
	Player[playerid][Cookies],
	Player[playerid][Warns],
	Player[playerid][Vip],
	Player[playerid][Banned],
	gRank[rankName],
	Player[playerid][ID]);
	mysql_tquery(g_SQL, query);
	return 1;
}
Everything ^ from code above works, except from saving and loading ranks.

I want to save the rankname variable in the Player[playerid][Rank].

Yes, i already made the row "Ranks" in mysql as varchar.
Reply
#2

Код:
mysql_format(g_SQL, query, sizeof query, "UPDATE `players` SET `Kills` = %d,`Deaths` = %d,`Score` = %i,`Money` = %i, `Level` = %d,`Cookies` = %d, `Warns` = %d, `Vip` = %d, `Banned` = %d, `Rank` = '%s' WHERE `id` = %d LIMIT 1",
	Player[playerid][Kills],
	Player[playerid][Deaths],
	GetPlayerScore(playerid),
	GetPlayerMoney(playerid),
	Player[playerid][Level],
	Player[playerid][Cookies],
	Player[playerid][Warns],
	Player[playerid][Vip],
	Player[playerid][Banned],
	gRank[rankName],
	Player[playerid][ID]);
There's a mistake and you have to enclose string in your query.
Reply
#3

I don't get your answer. What's wrong?
Reply
#4

I marked them with red colors.
The first mistake is in:
Код:
`Cookies` = %d, `Warns`, `Vip` = %d
which should be:
Код:
`Cookies` = %d, `Warns` = %d, `Vip` = %d
And the second one is:
Код:
`Rank` = %s
which should be
Код:
`Rank` = '%s'
Reply
#5

Ok seems fine, one problem. In the "rank" row in mysql, it shows always "Private" (the 1st rank), doesn't matter even i'm Specialist or another rank.

How to fix this?
Reply
#6

You have to provide array index of gRank, in this line:
Код:
	Player[playerid][Banned],
	gRank[rankName],
	Player[playerid][ID]);
And also, i don't get it why do you save player's rank as varchar and load them as an integer?
Reply
#7

What array index should i provide?
Reply
#8

Quote:
Originally Posted by Face9000
Посмотреть сообщение
What array index should i provide?
I don't wanna get wrong but that would be something like this:

Код:
new PlayerDataRank[MAX_PLAYERS][gRank];
Код:
PlayerDataRank[playerid][rankName];
Reply
#9

Put this somewhere in your script:
Код:
GetRankIndex(str[])
{
	static size = sizeof(gRank);
	for(new i; i < size; i++)
	{
		if(!strcmp(str, gRank[i][rankName]))
			return i;
	}
	return 0;
}
And use this to load player's rank:
Код:
new str[56];
cache_get_value(0, "Rank", str, 56); // Rank column is varchar, so load them as string
Player[playerid][Rank] = GetRankIndex(str); // Player[playerid][Rank] = index of gRank array.
Player[playerid][Rank] is now index of gRank, so if you want to increase player's rank you can simply increase its value. And you can use this variable as an array index of gRank in mysql_format inside UpdatePlayerData function.
Код:
Player[playerid][Banned],
gRank[Player[playerid][Rank]][rankName],
Player[playerid][ID]);
Reply
#10

To increase it's value you mean to do, when a player ranks up, Player[playerid][Rank] ++; right?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)