SA-MP Forums Archive
is this correct? rank/exp help - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: is this correct? rank/exp help (/showthread.php?tid=478861)



is this correct? rank/exp help - Voxel - 01.12.2013

So i have a exp/rank system going but i am not sure if this is the best and correct way to do this.
note that the timer doesnt really work... when i set the exp using a command it doesnt work correctly and when another player joins his exp changes but not his rank, should i loop true all the players or how does this work?

pawn Код:
forward rankcheck(playerid);

//under ongamemodeinit
SetTimer("rankcheck", 500, true);

public rankcheck(playerid)
{
    if(User[playerid][USER_EXP] == 0) return User[playerid][USER_RANK] = 0;
    if(User[playerid][USER_EXP] == 500) return User[playerid][USER_RANK] = 1;
    if(User[playerid][USER_EXP] == 1000) return User[playerid][USER_RANK] = 2;
    if(User[playerid][USER_EXP] == 2000) return User[playerid][USER_RANK] = 3;
    if(User[playerid][USER_EXP] == 3500) return User[playerid][USER_RANK] = 4;
    if(User[playerid][USER_EXP] == 4000) return User[playerid][USER_RANK] = 5;
    if(User[playerid][USER_EXP] == 5000) return User[playerid][USER_RANK] = 6;
    if(User[playerid][USER_EXP] == 5500) return User[playerid][USER_RANK] = 7;
    if(User[playerid][USER_EXP] == 7000) return User[playerid][USER_RANK] = 8;
    if(User[playerid][USER_EXP] == 8500) return User[playerid][USER_RANK] = 9;
    if(User[playerid][USER_EXP] == 10000) return User[playerid][USER_RANK] = 10;

    if(User[playerid][USER_EXP] == 10500) return User[playerid][USER_RANK] = 11;
    if(User[playerid][USER_EXP] == 11000) return User[playerid][USER_RANK] = 12;
    if(User[playerid][USER_EXP] == 12000) return User[playerid][USER_RANK] = 13;
    if(User[playerid][USER_EXP] == 13500) return User[playerid][USER_RANK] = 14;
    if(User[playerid][USER_EXP] == 14000) return User[playerid][USER_RANK] = 15;
    if(User[playerid][USER_EXP] == 15000) return User[playerid][USER_RANK] = 16;
    if(User[playerid][USER_EXP] == 15500) return User[playerid][USER_RANK] = 17;
    if(User[playerid][USER_EXP] == 17000) return User[playerid][USER_RANK] = 18;
    if(User[playerid][USER_EXP] == 18500) return User[playerid][USER_RANK] = 19;
    if(User[playerid][USER_EXP] == 20000) return User[playerid][USER_RANK] = 20;

    if(User[playerid][USER_EXP] == 20500) return User[playerid][USER_RANK] = 21;
    if(User[playerid][USER_EXP] == 21000) return User[playerid][USER_RANK] = 22;
    if(User[playerid][USER_EXP] == 22000) return User[playerid][USER_RANK] = 23;
    if(User[playerid][USER_EXP] == 23500) return User[playerid][USER_RANK] = 24;
    if(User[playerid][USER_EXP] == 24000) return User[playerid][USER_RANK] = 25;
    if(User[playerid][USER_EXP] == 25000) return User[playerid][USER_RANK] = 26;
    if(User[playerid][USER_EXP] == 25500) return User[playerid][USER_RANK] = 27;
    if(User[playerid][USER_EXP] == 27000) return User[playerid][USER_RANK] = 28;
    if(User[playerid][USER_EXP] == 28500) return User[playerid][USER_RANK] = 29;
    if(User[playerid][USER_EXP] == 30000) return User[playerid][USER_RANK] = 30;

    if(User[playerid][USER_EXP] == 30500) return User[playerid][USER_RANK] = 31;
    if(User[playerid][USER_EXP] == 31000) return User[playerid][USER_RANK] = 32;
    if(User[playerid][USER_EXP] == 32000) return User[playerid][USER_RANK] = 33;
    if(User[playerid][USER_EXP] == 33500) return User[playerid][USER_RANK] = 34;
    if(User[playerid][USER_EXP] == 34000) return User[playerid][USER_RANK] = 35;
    if(User[playerid][USER_EXP] == 35000) return User[playerid][USER_RANK] = 36;
    if(User[playerid][USER_EXP] == 35500) return User[playerid][USER_RANK] = 37;
    if(User[playerid][USER_EXP] == 37000) return User[playerid][USER_RANK] = 38;
    if(User[playerid][USER_EXP] == 38500) return User[playerid][USER_RANK] = 39;
    if(User[playerid][USER_EXP] == 40000) return User[playerid][USER_RANK] = 40;

    if(User[playerid][USER_EXP] == 40500) return User[playerid][USER_RANK] = 41;
    if(User[playerid][USER_EXP] == 41000) return User[playerid][USER_RANK] = 42;
    if(User[playerid][USER_EXP] == 42000) return User[playerid][USER_RANK] = 43;
    if(User[playerid][USER_EXP] == 43500) return User[playerid][USER_RANK] = 44;
    if(User[playerid][USER_EXP] == 44000) return User[playerid][USER_RANK] = 45;
    if(User[playerid][USER_EXP] == 45000) return User[playerid][USER_RANK] = 46;
    if(User[playerid][USER_EXP] == 45500) return User[playerid][USER_RANK] = 47;
    if(User[playerid][USER_EXP] == 47000) return User[playerid][USER_RANK] = 48;
    if(User[playerid][USER_EXP] == 48500) return User[playerid][USER_RANK] = 49;
    if(User[playerid][USER_EXP] == 50000) return User[playerid][USER_RANK] = 50;

    if(User[playerid][USER_EXP] == 50500) return User[playerid][USER_RANK] = 51;
    if(User[playerid][USER_EXP] == 51000) return User[playerid][USER_RANK] = 52;
    if(User[playerid][USER_EXP] == 52000) return User[playerid][USER_RANK] = 53;
    if(User[playerid][USER_EXP] == 53500) return User[playerid][USER_RANK] = 54;
    if(User[playerid][USER_EXP] == 54000) return User[playerid][USER_RANK] = 55;
    if(User[playerid][USER_EXP] == 55000) return User[playerid][USER_RANK] = 56;
    if(User[playerid][USER_EXP] == 55500) return User[playerid][USER_RANK] = 57;
    if(User[playerid][USER_EXP] == 57000) return User[playerid][USER_RANK] = 58;
    if(User[playerid][USER_EXP] == 58500) return User[playerid][USER_RANK] = 59;
    if(User[playerid][USER_EXP] == 60000) return User[playerid][USER_RANK] = 60;
    return 1;
}
thanks


Re: is this correct? rank/exp help - SilentSoul - 01.12.2013

Move your codes to OnPlayerUpdate , and remove your timer that will also work according to the player update if he got the number of exp he will take his rank.


Re: is this correct? rank/exp help - Voxel - 01.12.2013

Quote:
Originally Posted by SilentSoul
Посмотреть сообщение
Move your codes to OnPlayerUpdate , and remove your timer.
I tried that at first but then everyone is paused


Re: is this correct? rank/exp help - SilentSoul - 01.12.2013

Ops sorry i didn't notice that you didn't create a loop through all players
pawn Код:
public rankcheck(i)
{
    for(new i=0; i<MAX_PLAYERS; i++)
    {
    if(User[i][USER_EXP] == 0) return User[i][USER_RANK] = 0;
    if(User[i][USER_EXP] == 500) return User[i][USER_RANK] = 1;
    if(User[i][USER_EXP] == 1000) return User[i][USER_RANK] = 2;
    if(User[i][USER_EXP] == 2000) return User[i][USER_RANK] = 3;
    if(User[i][USER_EXP] == 3500) return User[i][USER_RANK] = 4;
    if(User[i][USER_EXP] == 4000) return User[i][USER_RANK] = 5;
    if(User[i][USER_EXP] == 5000) return User[i][USER_RANK] = 6;
    if(User[i][USER_EXP] == 5500) return User[i][USER_RANK] = 7;
    if(User[i][USER_EXP] == 7000) return User[i][USER_RANK] = 8;
    if(User[i][USER_EXP] == 8500) return User[i][USER_RANK] = 9;
    if(User[i][USER_EXP] == 10000) return User[i][USER_RANK] = 10;

    if(User[i][USER_EXP] == 10500) return User[i][USER_RANK] = 11;
    if(User[i][USER_EXP] == 11000) return User[i][USER_RANK] = 12;
    if(User[i][USER_EXP] == 12000) return User[i][USER_RANK] = 13;
    if(User[i][USER_EXP] == 13500) return User[i][USER_RANK] = 14;
    if(User[i][USER_EXP] == 14000) return User[i][USER_RANK] = 15;
    if(User[i][USER_EXP] == 15000) return User[i][USER_RANK] = 16;
    if(User[i][USER_EXP] == 15500) return User[i][USER_RANK] = 17;
    if(User[i][USER_EXP] == 17000) return User[i][USER_RANK] = 18;
    if(User[i][USER_EXP] == 18500) return User[i][USER_RANK] = 19;
    if(User[i][USER_EXP] == 20000) return User[i][USER_RANK] = 20;

    if(User[i][USER_EXP] == 20500) return User[i][USER_RANK] = 21;
    if(User[i][USER_EXP] == 21000) return User[i][USER_RANK] = 22;
    if(User[i][USER_EXP] == 22000) return User[i][USER_RANK] = 23;
    if(User[i][USER_EXP] == 23500) return User[i][USER_RANK] = 24;
    if(User[i][USER_EXP] == 24000) return User[i][USER_RANK] = 25;
    if(User[i][USER_EXP] == 25000) return User[i][USER_RANK] = 26;
    if(User[i][USER_EXP] == 25500) return User[i][USER_RANK] = 27;
    if(User[i][USER_EXP] == 27000) return User[i][USER_RANK] = 28;
    if(User[i][USER_EXP] == 28500) return User[i][USER_RANK] = 29;
    if(User[i][USER_EXP] == 30000) return User[i][USER_RANK] = 30;

    if(User[i][USER_EXP] == 30500) return User[i][USER_RANK] = 31;
    if(User[i][USER_EXP] == 31000) return User[i][USER_RANK] = 32;
    if(User[i][USER_EXP] == 32000) return User[i][USER_RANK] = 33;
    if(User[i][USER_EXP] == 33500) return User[i][USER_RANK] = 34;
    if(User[i][USER_EXP] == 34000) return User[i][USER_RANK] = 35;
    if(User[i][USER_EXP] == 35000) return User[i][USER_RANK] = 36;
    if(User[i][USER_EXP] == 35500) return User[i][USER_RANK] = 37;
    if(User[i][USER_EXP] == 37000) return User[i][USER_RANK] = 38;
    if(User[i][USER_EXP] == 38500) return User[i][USER_RANK] = 39;
    if(User[i][USER_EXP] == 40000) return User[i][USER_RANK] = 40;

    if(User[i][USER_EXP] == 40500) return User[i][USER_RANK] = 41;
    if(User[i][USER_EXP] == 41000) return User[i][USER_RANK] = 42;
    if(User[i][USER_EXP] == 42000) return User[i][USER_RANK] = 43;
    if(User[i][USER_EXP] == 43500) return User[i][USER_RANK] = 44;
    if(User[i][USER_EXP] == 44000) return User[i][USER_RANK] = 45;
    if(User[i][USER_EXP] == 45000) return User[i][USER_RANK] = 46;
    if(User[i][USER_EXP] == 45500) return User[i][USER_RANK] = 47;
    if(User[i][USER_EXP] == 47000) return User[i][USER_RANK] = 48;
    if(User[i][USER_EXP] == 48500) return User[i][USER_RANK] = 49;
    if(User[i][USER_EXP] == 50000) return User[i][USER_RANK] = 50;

    if(User[i][USER_EXP] == 50500) return User[i][USER_RANK] = 51;
    if(User[i][USER_EXP] == 51000) return User[i][USER_RANK] = 52;
    if(User[i][USER_EXP] == 52000) return User[i][USER_RANK] = 53;
    if(User[i][USER_EXP] == 53500) return User[i][USER_RANK] = 54;
    if(User[i][USER_EXP] == 54000) return User[i][USER_RANK] = 55;
    if(User[i][USER_EXP] == 55000) return User[i][USER_RANK] = 56;
    if(User[i][USER_EXP] == 55500) return User[i][USER_RANK] = 57;
    if(User[i][USER_EXP] == 57000) return User[i][USER_RANK] = 58;
    if(User[i][USER_EXP] == 58500) return User[i][USER_RANK] = 59;
    if(User[i][USER_EXP] == 60000) return User[i][USER_RANK] = 60;
    }
    return 1;
}



AW: is this correct? rank/exp help - Nero_3D - 01.12.2013

You could simplify it if you used an array, also you should only call it if you changed the player earned exp not in a timer all 500 ms ...
pawn Код:
rankcheck(playerid) { // don't use this if you didn't understood what I said above
    static const
        cExpData[] = {
            // 0 - 10
            0,
            500,
            1000,
            2000,
            3500,
            4000,
            5000,
            5500,
            7000,
            8500,
            10000
            // and so on
        };
    new
        exp = User[playerid][USER_EXP],
        rank = User[playerid][USER_RANK]
    ;
    if(!(0 <= rank < sizeof cExpData)) {
        rank = 0;
    }
    while(exp >= cExpData[rank]) {
        rank++;
    }
    User[playerid][USER_RANK] = rank - 1;
}



Re: is this correct? rank/exp help - Pottus - 01.12.2013

Looping, arrays is not the way to go this this calls for a switch() obviously and has absolutely no good reason to be updating every 500ms you only need to check when a player receives experience to know if there is a rank change.


Re: is this correct? rank/exp help - Voxel - 01.12.2013

Alright thanks guys!


Re: is this correct? rank/exp help - Voxel - 02.12.2013

I'm still a bit confused, what would the switch look like? can someone please give me a example? thanks