Enum help
#1

Hello all.

I am trying to understand how to effectively use enumeration in my script. This is my current enumeration:
pawn Код:
enum PlayerInfo
{
    AdminLevel,
}
new pinfo[MAX_PLAYERS][PlayerInfo];
So, i'm trying to create a command which shows what level you are
pawn Код:
CMD:mypermissions(playerid, params[])
{
    if(pinfo[playerid][AdminLevel] == 0) return MESSAGE(cwhite, "You have level 0 permissions. (Player)");
    if(pinfo[playerid][AdminLevel] == 1) return MESSAGE(cyellow, "You have level 1 permissions. (VIP)");
    if(pinfo[playerid][AdminLevel] == 2) return MESSAGE(clightblue, "You have level 2 permissions. (Jr. Mod)");
    if(pinfo[playerid][AdminLevel] == 3) return MESSAGE(clightblue, "You have level 3 permissions. (Moderator)");
    if(pinfo[playerid][AdminLevel] == 4) return MESSAGE(cred, "You have level 4 permissions. (Admin)");
    return 1;
}
BUT, when I type it in-game, it shows that I only have level 0 permissions, even though I have level 2 permissions (set in my MySQL database). I know I am doing something wrong, I just need some help to identify what it is i'm doing wrong. (Still trying to learn how to properly use if/switch statements)

Thanks
Reply
#2

You have only the bug with level 2 or? Because i did test it for you, and it works for me in my mysql server.
Make sure you did edit your user file, because if you did change it and you did /rcon gmx then he reset his adminlevel, make sure you did stop the server and start it again (homehost) because i had the same problem
Reply
#3

Quote:
Originally Posted by sjvt
Посмотреть сообщение
You have only the bug with level 2 or?
Whatever level I am, not just level 2
Reply
#4

Do you load the level from MySQL database to pinfo[playerid][AdminLevel] ?
Reply
#5

Quote:
Originally Posted by MadeMan
Посмотреть сообщение
Do you load the level from MySQL database to pinfo[playerid][AdminLevel] ?
Yep, I do this when the player logs in:
pawn Код:
new level;
pinfo[playerid][AdminLevel] = level;
mysql_fetch_field_row(savingstring, "AdminLevel");  level = strval(savingstring);
//Then I have it show me my admin level, and it shows it perfectly
FM(fString2, sizeof(fString2), "Your admin level: %d", level);
MESSAGE(cyellow, fString2);
Reply
#6

Try with this

pawn Код:
FM(fString2, sizeof(fString2), "Your admin level: %d", pinfo[playerid][AdminLevel]);
Reply
#7

Quote:
Originally Posted by MadeMan
Посмотреть сообщение
Try with this

pawn Код:
FM(fString2, sizeof(fString2), "Your admin level: %d", pinfo[playerid][AdminLevel]);
Ah it shows me that im level 0 now with that
Reply
#8

Change the order: first get from database, then save to enum

pawn Код:
mysql_fetch_field_row(savingstring, "AdminLevel");  level = strval(savingstring);
pinfo[playerid][AdminLevel] = level;
Reply
#9

Quote:
Originally Posted by MadeMan
Посмотреть сообщение
Change the order: first get from database, then save to enum

pawn Код:
mysql_fetch_field_row(savingstring, "AdminLevel");  level = strval(savingstring);
pinfo[playerid][AdminLevel] = level;
Ah its fixed! Thanks so much! +rep
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)