Enum help -
DBan - 11.04.2012
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
Re: Enum help -
sjvt - 11.04.2012
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
Re: Enum help -
DBan - 11.04.2012
Quote:
Originally Posted by sjvt
You have only the bug with level 2 or?
|
Whatever level I am, not just level 2
Re: Enum help -
MadeMan - 11.04.2012
Do you load the level from MySQL database to pinfo[playerid][AdminLevel] ?
Re: Enum help -
DBan - 11.04.2012
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);
Re: Enum help -
MadeMan - 11.04.2012
Try with this
pawn Код:
FM(fString2, sizeof(fString2), "Your admin level: %d", pinfo[playerid][AdminLevel]);
Re: Enum help -
DBan - 11.04.2012
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
Re: Enum help -
MadeMan - 11.04.2012
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;
Re: Enum help -
DBan - 11.04.2012
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