SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 22/03/2017, 12:58 AM   #1
Face9000
Banned
 
Join Date: Jan 2010
Location: Pigland
Posts: 3,351
Reputation: 190
Default Rank help

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

This is the rank variable:

Code:
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:

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

Code:
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.
Face9000 is offline   Reply With Quote
Old 22/03/2017, 01:14 AM   #2
X337
Gangsta
 
Join Date: Sep 2014
Location: Indonesia
Posts: 877
Reputation: 291
Default Re: Rank help

Code:
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.
__________________
viva la sa-mp
X337 is offline   Reply With Quote
Old 22/03/2017, 01:24 AM   #3
Face9000
Banned
 
Join Date: Jan 2010
Location: Pigland
Posts: 3,351
Reputation: 190
Default Re: Rank help

I don't get your answer. What's wrong?
Face9000 is offline   Reply With Quote
Old 22/03/2017, 01:31 AM   #4
X337
Gangsta
 
Join Date: Sep 2014
Location: Indonesia
Posts: 877
Reputation: 291
Default Re: Rank help

I marked them with red colors.
The first mistake is in:
Code:
`Cookies` = %d, `Warns`, `Vip` = %d
which should be:
Code:
`Cookies` = %d, `Warns` = %d, `Vip` = %d

And the second one is:
Code:
`Rank` = %s
which should be
Code:
`Rank` = '%s'
__________________
viva la sa-mp
X337 is offline   Reply With Quote
Old 22/03/2017, 01:42 AM   #5
Face9000
Banned
 
Join Date: Jan 2010
Location: Pigland
Posts: 3,351
Reputation: 190
Default Re: Rank help

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?
Face9000 is offline   Reply With Quote
Old 22/03/2017, 01:52 AM   #6
X337
Gangsta
 
Join Date: Sep 2014
Location: Indonesia
Posts: 877
Reputation: 291
Default Re: Rank help

You have to provide array index of gRank, in this line:
Code:
	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?
__________________
viva la sa-mp
X337 is offline   Reply With Quote
Old 22/03/2017, 09:00 PM   #7
Face9000
Banned
 
Join Date: Jan 2010
Location: Pigland
Posts: 3,351
Reputation: 190
Default Re: Rank help

What array index should i provide?
Face9000 is offline   Reply With Quote
Old 23/03/2017, 01:47 AM   #8
Flamehaze7
Big Clucker
 
Flamehaze7's Avatar
 
Join Date: Feb 2016
Posts: 133
Reputation: 10
Default Re: Rank help

Quote:
Originally Posted by Face9000 View Post
What array index should i provide?
I don't wanna get wrong but that would be something like this:

Code:
new PlayerDataRank[MAX_PLAYERS][gRank];
Code:
PlayerDataRank[playerid][rankName];
Flamehaze7 is offline   Reply With Quote
Old 23/03/2017, 03:07 AM   #9
X337
Gangsta
 
Join Date: Sep 2014
Location: Indonesia
Posts: 877
Reputation: 291
Default Re: Rank help

Put this somewhere in your script:
Code:
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:
Code:
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.
Code:
Player[playerid][Banned],
gRank[Player[playerid][Rank]][rankName],
Player[playerid][ID]);
__________________
viva la sa-mp
X337 is offline   Reply With Quote
Old 23/03/2017, 10:12 AM   #10
Face9000
Banned
 
Join Date: Jan 2010
Location: Pigland
Posts: 3,351
Reputation: 190
Default Re: Rank help

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

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Ajuda] Rank ! FalcaoNC Português/Portuguese 11 28/09/2016 08:16 AM
Rank Id's lramos15 Scripting Help 1 12/11/2013 03:03 AM
[Tutorial] Creating a rank system with textdraws for each rank + certain health/armour upon spawn. Strier Tutorials 10 07/03/2013 07:26 AM
How Do You Show "RANK UP" everytime a player reaches the rank? markjaysonpinoy Scripting Help 7 15/08/2012 01:19 PM
Rank SYstem With Rank Name in Up Head korzk7 Scripting Help 2 05/07/2012 06:08 AM


All times are GMT. The time now is 11:37 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.