SA-MP Forums Archive
a problem with my rank system - 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: a problem with my rank system (/showthread.php?tid=648738)



a problem with my rank system - MarkNelson - 27.01.2018

Hello everyone, i have faced a bug with my rank system i tried to fix it but i failed
idk what's going on.. here is the code:
Код HTML:
 if(GetPlayerScore(playerid) >= 0 && strcmp(AccData[playerid][pRank], "No Rank", true) < 50)
    {
        
        
        
        dini_Set(AddDirFile("users", GetName(playerid)), "rank", "Newbie");
        strcat(AccData[playerid][pRank],"Newbie");
    }
    else if(GetPlayerScore(playerid) >= 50 && strcmp(AccData[playerid][pRank], "Newbie", true) < 100)
    {
        
        
        
        dini_Set(AddDirFile("users", GetName(playerid)), "rank", "Pro");
        strcat(AccData[playerid][pRank],"Pro");
    }
    else if(GetPlayerScore(playerid) >= 100 && strcmp(AccData[playerid][pRank], "Pro", true) < 200)
    {
        
        
        
        dini_Set(AddDirFile("users", GetName(playerid)), "rank", "Chump");
        strcat(AccData[playerid][pRank],"Chump");
    }
    else if(GetPlayerScore(playerid) >= 200 && strcmp(AccData[playerid][pRank], "Chump", true) < 400)
    {
        
        
        
        dini_Set(AddDirFile("users", GetName(playerid)), "rank", "Killah");
        strcat(AccData[playerid][pRank],"Killah");
    }
    else if(GetPlayerScore(playerid) >= 400 && strcmp(AccData[playerid][pRank], "Killah", true) < 800)
    {
        
        
        
        dini_Set(AddDirFile("users", GetName(playerid)), "rank", "Serial Killah");
        strcat(AccData[playerid][pRank],"Serial Killah");
    }
    else if(GetPlayerScore(playerid) >= 800 && strcmp(AccData[playerid][pRank], "Serial Killah", true) < 1000)
    {
        
        
        
        dini_Set(AddDirFile("users", GetName(playerid)), "rank", "Advanced");
        strcat(AccData[playerid][pRank],"Advanced");
    }
    else if(GetPlayerScore(playerid) >= 1000 && strcmp(AccData[playerid][pRank], "Advanced", true) < 1500)
    {
        
        
        
        dini_Set(AddDirFile("users", GetName(playerid)), "rank", "Advanced Serial Killah");
        strcat(AccData[playerid][pRank],"Advanced Serial Killah");
    }
    else if(GetPlayerScore(playerid) >= 1500 && strcmp(AccData[playerid][pRank], "Advanced Serial Killah", true) < 2000)
    {
        
        
        
        dini_Set(AddDirFile("users", GetName(playerid)), "rank", "Blood Reaper");
        strcat(AccData[playerid][pRank],"Blood Reaper");
    }
    else if(GetPlayerScore(playerid) >= 2000 && strcmp(AccData[playerid][pRank], "Blood Reaper", true) < 2500)
    {
        
        
        
        dini_Set(AddDirFile("users", GetName(playerid)), "rank", "Advanced Blood Reaper");
        strcat(AccData[playerid][pRank],"Advanced Blood Reaper");
    }
    else if(GetPlayerScore(playerid) >= 2500 && strcmp(AccData[playerid][pRank], "Advanced Blood Reaper", true) < 3000)
    {
        
        
        
        dini_Set(AddDirFile("users", GetName(playerid)), "rank", "Blood Liner");
        strcat(AccData[playerid][pRank],"Blood Liner");
    }
    else if(GetPlayerScore(playerid) >= 3000 && strcmp(AccData[playerid][pRank], "Blood Liner", true) < 3500)
    {
        
        
        
        dini_Set(AddDirFile("users", GetName(playerid)), "rank", "Advanced Blood Liner");
        strcat(AccData[playerid][pRank],"Advanced Blood Liner");
    }
    else if(GetPlayerScore(playerid) >= 3500 && strcmp(AccData[playerid][pRank], "Advanced Blood Liner", true) < 4000)
    {
        
        
        
        dini_Set(AddDirFile("users", GetName(playerid)), "rank", "Death Reaper");
        strcat(AccData[playerid][pRank],"Death Reaper");
    }
    else if(GetPlayerScore(playerid) >= 4000 && strcmp(AccData[playerid][pRank], "Death Reaper", true) < 5000)
    {
        
        
        
        dini_Set(AddDirFile("users", GetName(playerid)), "rank", "Advanced Death Reaper");
        strcat(AccData[playerid][pRank],"Advanced Death Reaper");
    }
    else if(GetPlayerScore(playerid) >= 5000 && strcmp(AccData[playerid][pRank], "Advanced Death Reaper", true) < 6000)
    {
        
        
        
        dini_Set(AddDirFile("users", GetName(playerid)), "rank", "Head Seeker");
        strcat(AccData[playerid][pRank],"Head Seeker");
    }
    else if(GetPlayerScore(playerid) >= 6000 && strcmp(AccData[playerid][pRank], "Head Seeker", true) < 7000)
    {
        
        
        
        dini_Set(AddDirFile("users", GetName(playerid)), "rank", "Advanced Head Seeker");
        strcat(AccData[playerid][pRank],"Advanced Head Seeker");
    }
    else if(GetPlayerScore(playerid) >= 7000 && strcmp(AccData[playerid][pRank], "Advanced Head Seeker", true) < 8000)
    {
        
        
        
        dini_Set(AddDirFile("users", GetName(playerid)), "rank", "Monster");
        strcat(AccData[playerid][pRank],"Monster");
    }
    else if(GetPlayerScore(playerid) >= 8000 && strcmp(AccData[playerid][pRank], "Monster", true) < 9000)
    {
        
        
        
        dini_Set(AddDirFile("users", GetName(playerid)), "rank", "Hungry Monster");
        strcat(AccData[playerid][pRank],"Hungry Monster");
    }
    else if(GetPlayerScore(playerid) > 9000 && strcmp(AccData[playerid][pRank], "Hungry Monster", true) < 10000)
    {
        
        
        
        dini_Set(AddDirFile("users", GetName(playerid)), "rank", "God Like");
        strcat(AccData[playerid][pRank],"God Like");
    }
    else if(GetPlayerScore(playerid) >= 10000 && strcmp(AccData[playerid][pRank], "God Like", true) < 15000)
    {
        
        
        
        dini_Set(AddDirFile("users", GetName(playerid)), "rank", "God");
        strcat(AccData[playerid][pRank],"God");
    }
    else if(GetPlayerScore(playerid) >= 15000 && strcmp(AccData[playerid][pRank], "God", true) < 20000)
    {
        
        
        
        dini_Set(AddDirFile("users", GetName(playerid)), "rank", "God Of Death");
        strcat(AccData[playerid][pRank],"God Of Death");
    }
    else if(GetPlayerScore(playerid) >= 20000 && strcmp(AccData[playerid][pRank], "God Of Death", true) < 25000)
    {
        
        
        
        dini_Set(AddDirFile("users", GetName(playerid)), "rank", "Ultimate God Of Death");
        strcat(AccData[playerid][pRank],"Ultimate God Of Death");
    }
    else if(GetPlayerScore(playerid) >= 25000 && strcmp(AccData[playerid][pRank], "Ultimate God Of Death", true) < 30000)
    {
        
        
        
        dini_Set(AddDirFile("users", GetName(playerid)), "rank", "Advanced God Of Death");
        strcat(AccData[playerid][pRank],"Advanced God Of Death");
    }
    else if(GetPlayerScore(playerid) >= 30000 && strcmp(AccData[playerid][pRank], "Advanced God Of Death", true) < 55000)
    {
        
        
        
        dini_Set(AddDirFile("users", GetName(playerid)), "rank", "Super Advanced God Of Death");
        strcat(AccData[playerid][pRank],"Super Advanced God Of Death");
    }
    else if(GetPlayerScore(playerid) >= 55000 && strcmp(AccData[playerid][pRank], "Super Advanced God Of Death", true))
    {
        
        
        
        dini_Set(AddDirFile("users", GetName(playerid)), "rank", "Over God");
        strcat(AccData[playerid][pRank],"Over God");
    }
the problem is, the rank gets stuck with newbie even if i change my score and kill myself to respawn again the rank never changes.
So, can you tell me what is the issue?


Re: a problem with my rank system - Sew_Sumi - 27.01.2018

Why are you even doing it in this manner?

Why not have actual numerical ranks, use them, and simply have the rank names defined in defines?

Rather than storing the rank name itself as a string into the userfile. And do you even load the data from the userfile after you've actually changed rank, as usually you only save, you don't reload the user info from the ini file.

strcat...

concatenate

link (things) together in a chain or series.


Re: a problem with my rank system - Hrb - 27.01.2018

Try to do it like this if u want to repair your code:

EDIT: otherwise, do what Sew_Sumi writes, he is right.

Код:
if(strcmp(AccData[playerid][pRank], "No Rank", true))
{
    if(0 <= GetPlayerScore(playerid) < 50)
    {
        dini_Set(AddDirFile("users", GetName(playerid)), "rank", "Newbie");
        strcat(AccData[playerid][pRank],"Newbie");
    }
} else if(strcmp(AccData[playerid][pRank], "Newbie", true))
{
    if(50 <= GetPlayerScore(playerid) < 100)
    {
        dini_Set(AddDirFile("users", GetName(playerid)), "rank", "Pro");
        strcat(AccData[playerid][pRank],"Pro");
    }
} else if(...



Re: a problem with my rank system - Sew_Sumi - 27.01.2018

Код:
new string[40] = "Hello";
strcat(string, " World!");
 
// The string is now 'Hello World!'



Re: a problem with my rank system - MarkNelson - 28.01.2018

fixed it, thanks