My stock code stalls out the compiler?
#9

Quote:
Originally Posted by jessejanssen
Посмотреть сообщение
After reading everything here I thought of something what would be much better in my opinion, I'll show you;
pawn Код:
#define MAX_RANKS 18

new RankNames[MAX_RANKS][22] = {
{"Private"},
{"Specialist"},
{"Corporal"},
{"Sergeant"},
{"Staff Sergeant"},
{"Master Sergeant"},
{"First Sergeant"},
{"Warrant Officer"},
{"Chief Warrant Officer"},
{"Second Lieutenant"},
{"First Lieutenant"},
{"Captain"},
{"Major"},
{"Lieutenant Colonel"},
{"Colonel"},
{"Brigadier General"},
{"General"},
{"General of the Army"}
};

new RankXP[MAX_RANKS] = {0, 28000, 68000, 120000, 179000, 247000, 323000, 405000, 537000, 832000, 1240000, 1756000, 2380000, 3112000,\
3952000, 4900000, 5956000, 6332000};

stock GetRankNameFromExp(playerid)
{
    new Exp = PData[playerid][pExp];
    for(new i = 0; i < MAX_RANKS; i++)
        {
        if(Exp >= RankXP[i] && Exp < RankXP[i+1]) { return RankNames[i]; }
        else if(i == MAX_RANKS-1 && Exp >= RankXP[MAX_RANKS-1]) { return RankNames[MAX_RANKS-1]; }
        else if(i == MAX_RANKS-1) { return RankNames[0]; }
        }
}
This way you can easily manage ranks (Adding them for example) without too much things to change, just change MAX_RANKS, add a rank name in 'RankNames', add the XP required to get them in 'RankXP' and voilla, done.

Best regards,
Jesse
I like it, It's nice and easily changeable, however, it throws warnings.

pawn Код:
warning 209: function "GetRankNameFromExp" should return a value
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)