SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 23/03/2017, 10:53 AM   #11
X337
Gangsta
 
Join Date: Sep 2014
Location: Indonesia
Posts: 872
Reputation: 291
Default Re: Rank help

Quote:
Originally Posted by Face9000 View Post
To increase it's value you mean to do, when a player ranks up, Player[playerid][Rank] ++; right?
Yes, but you have to add some check before increasing its value, so Player[playerid][Rank] won't be higher than the array size (gRank).
__________________
viva la sa-mp
X337 is offline   Reply With Quote
Old 23/03/2017, 10:54 AM   #12
Face9000
Banned
 
Join Date: Jan 2010
Location: Pigland
Posts: 3,351
Reputation: 190
Default Re: Rank help

What about this:

Code:
	new rank = GetPlayerRank(playerid);
	if (Player[playerid][Rank] > rank)
	{
	    new buf[150];
	    format(buf, sizeof(buf), "You ranked down to ~r~%s(%i)", gRank[rank][rankName], rank);
	    NotifyPlayer(playerid, buf, 5000);

	    format(buf, sizeof(buf), "You have just ranked down to \"%s (%i)\" from \"%s (%i)\".", gRank[rank][rankName], rank, gRank[Player[playerid][Rank]][rankName], Player[playerid][Rank]);
	    SendClientMessage(playerid, COLOR_TOMATO, buf);

	    SetPlayerScore(playerid, GetPlayerScore(playerid) - 5);

	    PlayerPlaySound(playerid, 1057, 0.0, 0.0, 0.0);

	    Player[playerid][Rank] = rank;
	}
	else if (Player[playerid][Rank] < rank)
	{
	    new buf[150];
	    format(buf, sizeof(buf), "You ranked up to ~g~%s(%i)", gRank[rank][rankName], rank);
	    NotifyPlayer(playerid, buf, 5000);

	    format(buf, sizeof(buf), "You have just ranked up to \"%s (%i)\" from \"%s (%i)\".", gRank[rank][rankName], rank, gRank[Player[playerid][Rank]][rankName], Player[playerid][Rank]);
	    SendClientMessage(playerid, COLOR_TOMATO, buf);
	    SendClientMessage(playerid, COLOR_GREEN, "+$10000 and +10 Score as your reward.");

	    SetPlayerScore(playerid, GetPlayerScore(playerid) + 10);
	    GivePlayerMoney(playerid, 10000);

	    PlayerPlaySound(playerid, 1057, 0.0, 0.0, 0.0);

	    Player[playerid][Rank] = rank;
	}
Face9000 is offline   Reply With Quote
Old 23/03/2017, 11:27 AM   #13
X337
Gangsta
 
Join Date: Sep 2014
Location: Indonesia
Posts: 872
Reputation: 291
Default Re: Rank help

Depends on the value your GetPlayerRank returns. If it's only returns value between 0 - gRank's size, so that code is okay. Otherwise, it'll trigger a runtime error about array index out of bounds if returned value lower than 0 or higher than gRank's size.
__________________
viva la sa-mp
X337 is offline   Reply With Quote
Old 23/03/2017, 11:41 AM   #14
Face9000
Banned
 
Join Date: Jan 2010
Location: Pigland
Posts: 3,351
Reputation: 190
Default Re: Rank help

Seems no problems since the rank is saved in the database row and gets loaded correctly.
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 06:45 AM.


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