PDA

View Full Version : Make this more simple


Face9000
09/08/2013, 07:39 PM
Hello guys, i have this stock to promote a player when he gets enough EXP for the next rank. The problem is, I HAVE 45 RANKS, LOL. How i can make it more simple?

This is the current stock:


stock CheckForLevelUpdate(playerid)
{
if ( pInfo[playerid][Exp] >= 0 )
{
if( pInfo[playerid][Rank] < 1 )
{
PlayerPlaySound(playerid, 1150, 0, 0, 0);
SCM(playerid, COLOR_CON_GREEN,"** You reached the first rank!");
SCM(playerid, COLOR_CON_GREEN, "** You are a Private!");
pInfo[playerid][Rank] = 1;
pInfo[playerid][Cookies] += 1;
new pname[MAX_PLAYER_NAME];
GetPlayerName(playerid, pname, 24);
new msg[128],ok[128];
format(msg, sizeof(msg), "%s (%d) has been promoted to rank {F70505}%s {FFFFFF}({F70505}%d{FFFFFF})!", pname,playerid,RankName(playerid),pInfo[playerid][Rank]);
format(ok, sizeof(ok), "03,2%s (%d) has been promoted to rank %s (%d)!",pname,playerid,RankName(playerid),pInfo[playerid][Rank]);
SCMTA(COLOR_LIGHTBLUE, msg);
IRC_Say(gGroupID, IRC_CHANNEL, ok);
SetRank3DText(playerid);
}
}
}


I have already the stock for rank names, if are necessary.

Cypress
09/08/2013, 08:23 PM
As I understand you have 45 ranks and you have 45 checks for all of the 45 ranks, correct me if I'm wrong.


stock CheckForLevelUpdate(playerid)
{
if ( pInfo[playerid][Exp] >= 0 )
{
if( pInfo[playerid][Rank] < 45 )
{
new string[128];

PlayerPlaySound(playerid, 1150, 0, 0, 0);
pInfo[playerid][Rank]++;
pInfo[playerid][Cookies] += 1;
format(string, sizeof(string), "** You have reacher rank %d!", pInfo[playerid][Rank]);
SCM(playerid, COLOR_CON_GREEN, string);
new pname[MAX_PLAYER_NAME];
GetPlayerName(playerid, pname, 24);
new msg[128],ok[128];
format(msg, sizeof(msg), "%s (%d) has been promoted to rank {F70505}%s {FFFFFF}({F70505}%d{FFFFFF})!", pname,playerid,RankName(playerid),pInfo[playerid][Rank]);
format(ok, sizeof(ok), "03,2%s (%d) has been promoted to rank %s (%d)!",pname,playerid,RankName(playerid),pInfo[playerid][Rank]);
SCMTA(COLOR_LIGHTBLUE, msg);
IRC_Say(gGroupID, IRC_CHANNEL, ok);
SetRank3DText(playerid);
}
}
}

BullseyeHawk
09/08/2013, 11:03 PM
enum rankInfo
{
rEXP
}

new EXPRankInfo[45][rankInfo] =
{
{0}, // Level 0 <== FIRST LEVEL ON REGISTER.
{300}, // Level 1
{600}, // Level 2
.. // And onward.
};

stock CheckForLevelUpdate(playerid)
{
new nextRank = pInfo[playerid][Rank] + 1;
if ( pInfo[playerid][Exp] >= EXPRankInfo[nextRank][rEXP])
{
if( pInfo[playerid][Rank] < 45 )
{
new string[128];

PlayerPlaySound(playerid, 1150, 0, 0, 0);
pInfo[playerid][Rank]++;
pInfo[playerid][Cookies] += 1;
format(string, sizeof(string), "** You have reacher rank %d!", pInfo[playerid][Rank]);
SCM(playerid, COLOR_CON_GREEN, string);
new pname[MAX_PLAYER_NAME];
GetPlayerName(playerid, pname, 24);
new msg[128],ok[128];
format(msg, sizeof(msg), "%s (%d) has been promoted to rank {F70505}%s {FFFFFF}({F70505}%d{FFFFFF})!", pname,playerid,RankName(playerid),pInfo[playerid][Rank]);
format(ok, sizeof(ok), "03,2%s (%d) has been promoted to rank %s (%d)!",pname,playerid,RankName(playerid),pInfo[playerid][Rank]);
SCMTA(COLOR_LIGHTBLUE, msg);
IRC_Say(gGroupID, IRC_CHANNEL, ok);
SetRank3DText(playerid);
}
}
}



That should do it, it's alot simpler if you use like that.
You just need to setup all of the level exp's.

Face9000
10/08/2013, 07:41 PM
Oh yeah <3 Thanks both, @Bullseye i already have the rank exp so this will be easy, thanks.

Face9000
10/08/2013, 09:28 PM
EDIT: I get this error:
(136) : error 052: multi-dimensional arrays must be fully initialized
At this line:


new EXPRankInfo[45][rankInfo] =
{
{0},
{300},
{600}
};


Line:
};

Kyle1
10/08/2013, 09:30 PM
Good Job

Face9000
10/08/2013, 09:34 PM
I fixed, i had to add all 45 ranks.