Add textdraw to show rank.
#1

I need a text draw to appear just right below the wanted stars.

I just wanted it to appear as "Rank: Generel" or whatever.




This is the rank variable.
pawn Код:
RankName(playerid)


Rank stock.
pawn Код:
stock Rank(playerid)
{
    new rank;
    if     (GetPlayerScore(playerid) >= 0 && GetPlayerScore(playerid) < RANK2) rank = 1;
    else if(GetPlayerScore(playerid) >= RANK2 && GetPlayerScore(playerid) < RANK3) rank = 2;
    else if(GetPlayerScore(playerid) >= RANK3 && GetPlayerScore(playerid) < RANK4) rank = 3;
    else if(GetPlayerScore(playerid) >= RANK4 && GetPlayerScore(playerid) < RANK5) rank = 4;
    else if(GetPlayerScore(playerid) >= RANK5 && GetPlayerScore(playerid) < RANK6) rank = 5;
    else if(GetPlayerScore(playerid) >= RANK6 && GetPlayerScore(playerid) < RANK7) rank = 6;
    else if(GetPlayerScore(playerid) >= RANK7 && GetPlayerScore(playerid) < RANK8) rank = 7;
    else if(GetPlayerScore(playerid) >= RANK8 && GetPlayerScore(playerid) < RANK9) rank = 8;
    else if(GetPlayerScore(playerid) >= RANK9 && GetPlayerScore(playerid) < RANK10) rank = 9;

    else if(GetPlayerScore(playerid) >= RANK10 && GetPlayerScore(playerid) < RANK11) rank = 10;
    else if(GetPlayerScore(playerid) >= RANK11 && GetPlayerScore(playerid) < RANK12) rank = 11;
    else if(GetPlayerScore(playerid) >= RANK12 && GetPlayerScore(playerid) < RANK13) rank = 12;
    else if(GetPlayerScore(playerid) >= RANK13 && GetPlayerScore(playerid) < RANK14) rank = 13;
    else if(GetPlayerScore(playerid) >= RANK14 && GetPlayerScore(playerid) < RANK15) rank = 14;

    return rank;
}
Reply
#2

You may also need these too.


(These are the scores that each level require)
pawn Код:
#define RANK1               0
#define RANK2               100
#define RANK3               300
#define RANK4               1000
#define RANK5               2500
#define RANK6               4000
#define RANK7               6500
#define RANK8               10000
#define RANK9               15000
#define RANK10              30000
#define RANK11              45000
#define RANK12              60000
#define RANK13              75000
#define RANK14              100000
#define RANK15              150000

These are the rank names.
pawn Код:
#define RANK1NAME           "Private"
#define RANK2NAME           "Private First Class"
#define RANK3NAME           "Corporal"
#define RANK4NAME           "Sergeant"
#define RANK5NAME           "Sergeant First Class"
#define RANK6NAME           "Master Sergeant"
#define RANK7NAME           "First Sergeant"
#define RANK8NAME           "Sergeant Major"
#define RANK9NAME           "Second Lietenant"
#define RANK10NAME          "First Lieutenant"
#define RANK11NAME          "Captain"
#define RANK12NAME          "Major"
#define RANK13NAME          "Colonel"
#define RANK14NAME          "General"
#define RANK15NAME          "Master of War"
Reply
#3

where is textdraw u created..........
Reply
#4

This.

pawn Код:
// On top of script:
new Text:Rank50;

// In OnGameModeInit
Rank50 = TextDrawCreate(413 ,112 , "Rank:");
TextDrawFont(Rank50 , 1);
TextDrawLetterSize(Rank50 , 1, 7);
TextDrawColor(Rank50 , 0xffffffFF);
TextDrawSetOutline(Rank50 , false);
TextDrawSetProportional(Rank50 , true);
TextDrawSetShadow(Rank50 , 1);
Reply
#5

At the bottom of the Rank() function, just before the return, add the following code:

pawn Код:
new szString[50];
format(szString, sizeof(szString), "%d", rank);
TextDrawSetString(Rank50, szString);
Reply
#6

Quote:
Originally Posted by RealCop228
Посмотреть сообщение
At the bottom of the Rank() function, just before the return, add the following code:

pawn Код:
new szString[50];
format(szString, sizeof(szString), "%d", rank);
TextDrawSetString(Rank50, szString);
I added it below, but OnPlayerRequestSpawn started playing up (Disabled text draws)

I added it in OnPlayerConnect as
pawn Код:
new szString[50];
    format(szString, sizeof(szString), "%d", RankName(playerid));
    TextDrawSetString(RankStars, szString);
.. no luck.
Reply
#7

I did the below, but it stopped other textdraws from closing like they should in OnPlayerConnect.


pawn Код:
stock Rank(playerid)
{
    new rank;
    if     (GetPlayerScore(playerid) >= 0 && GetPlayerScore(playerid) < RANK2) rank = 1;
    else if(GetPlayerScore(playerid) >= RANK2 && GetPlayerScore(playerid) < RANK3) rank = 2;
    else if(GetPlayerScore(playerid) >= RANK3 && GetPlayerScore(playerid) < RANK4) rank = 3;
    else if(GetPlayerScore(playerid) >= RANK4 && GetPlayerScore(playerid) < RANK5) rank = 4;
    else if(GetPlayerScore(playerid) >= RANK5 && GetPlayerScore(playerid) < RANK6) rank = 5;
    else if(GetPlayerScore(playerid) >= RANK6 && GetPlayerScore(playerid) < RANK7) rank = 6;
    else if(GetPlayerScore(playerid) >= RANK7 && GetPlayerScore(playerid) < RANK8) rank = 7;
    else if(GetPlayerScore(playerid) >= RANK8 && GetPlayerScore(playerid) < RANK9) rank = 8;
    else if(GetPlayerScore(playerid) >= RANK9 && GetPlayerScore(playerid) < RANK10) rank = 9;

    else if(GetPlayerScore(playerid) >= RANK10 && GetPlayerScore(playerid) < RANK11) rank = 10;
    else if(GetPlayerScore(playerid) >= RANK11 && GetPlayerScore(playerid) < RANK12) rank = 11;
    else if(GetPlayerScore(playerid) >= RANK12 && GetPlayerScore(playerid) < RANK13) rank = 12;
    else if(GetPlayerScore(playerid) >= RANK13 && GetPlayerScore(playerid) < RANK14) rank = 13;
    else if(GetPlayerScore(playerid) >= RANK14 && GetPlayerScore(playerid) < RANK15) rank = 14;

        new szString[50];
    format(szString, sizeof(szString), "Rank: {FFFFFF}%d", Rank);
    TextDrawSetString(RankStars, szString);
    return rank;
}
Reply
#8

Can you show the code that you have under OnPlayerRequestSpawn(), then? The code I've given you should work just fine...

By the way, you could use a switch statement in your Rank() function!

pawn Код:
stock RankName(playerid)
{
    switch(GetPlayerScore(playerid))
    {
        case RANK1 .. RANK2-1: rank = 1;
        case RANK2 .. RANK3-1: rank = 2;
        case RANK3 .. RANK4-1: rank = 3;
        case RANK4 .. RANK5-1: rank = 4;
        case RANK5 .. RANK6-1: rank = 5;
        case RANK6 .. RANK7-1: rank = 6;
        case RANK7 .. RANK8-1: rank = 7;
        case RANK8 .. RANK9-1: rank = 8;
        case RANK9 .. RANK10-1: rank = 9;
        case RANK10 .. RANK11-1: rank = 10;
        case RANK11 .. RANK12-1: rank = 11;
        case RANK12 .. RANK13-1: rank = 12;
        case RANK13 .. RANK14-1: rank = 13;
        case RANK14 .. RANK15-1: rank = 14;
        case RANK15: rank = 15;
    }
    return rank;
}
^^ should work fine, but it's untested obviously
Reply
#9

Unfortunately not.

I remember you gave me the same thing last time, got the exact same errors/warnings.

pawn Код:
C:\Users\tommy\Desktop\BillionareGaming\gamemodes\cod.pwn(6192) : error 017: undefined symbol "rank"
C:\Users\tommy\Desktop\BillionareGaming\gamemodes\cod.pwn(6192) : error 036: empty statement
C:\Users\tommy\Desktop\BillionareGaming\gamemodes\cod.pwn(6193) : error 014: invalid statement; not in switch
C:\Users\tommy\Desktop\BillionareGaming\gamemodes\cod.pwn(6193) : warning 215: expression has no effect
C:\Users\tommy\Desktop\BillionareGaming\gamemodes\cod.pwn(6193) : error 001: expected token: ";", but found ".."
C:\Users\tommy\Desktop\BillionareGaming\gamemodes\cod.pwn(6193) : error 029: invalid expression, assumed zero
C:\Users\tommy\Desktop\BillionareGaming\gamemodes\cod.pwn(6193) : fatal error 107: too many error messages on one line
Reply
#10

Hm, okay. Either way, could you show your OnPlayerRequestSpawn code?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)