Reading From Y_INI Files
#1

Hello, I'm trying to get an Admins command working, but I'd like to be able to /setlevel and to be able to view online Administrators.

So far, I've got this command that causes errors in my gamemode, I've had a look around and I'm just confusing myself with probably, for most a very simple task. If someone could take a look at my code I'd greatly appreciate that.

Код:
cmd(admins, playerid, params[])
{
    if(IsPlayerConnected(playerid))
    {
        SendClientMessage(playerid, COLOR_ADMIN, "Online Staff Members:");

        new count; new ID; new admtext[64];
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            if(IsPlayerConnected(i))
            {
                new sendername[MAX_PLAYER_NAME];
                switch(Player_LoadInt("AdminLevel");
                        case 1: format(admtext, 64, "{10F441}Beta Tester");
                        case 2: format(admtext, 64, "{10F441}Moderator");
                        case 3: format(admtext, 64, "{33AA33}Administrator");
                        case 4: format(admtext, 64, "{FF0000}Senior Administrator");
                        case 1337: format(admtext, 64, "{FF0000}Head Administrator");
                        default: continue;
                    }

                GetPlayerName(i, sendername, sizeof(sendername));
                new tstr[128];
                format(tstr, 128, "%s(%d) - %s", sendername, ID, admtext);
                SendClientMessage(playerid, -1, tstr);
                format(admtext, 64, "");
                count++;
            }
            if(count == 0)
			{
			    SendClientMessage(playerid, COLOR_ERROR, "No online administrators found.");
				return 1;
			}
        }
    }
    return 1;
}
It also kicks out these errors:
Код:
C:\Users\Tom\Desktop\SAMP Server\gamemodes\newgm.pwn(363) : error 017: undefined symbol "Player_LoadInt"
C:\Users\Tom\Desktop\SAMP Server\gamemodes\newgm.pwn(363) : error 001: expected token: ")", but found ";"
C:\Users\Tom\Desktop\SAMP Server\gamemodes\newgm.pwn(364) : error 014: invalid statement; not in switch
C:\Users\Tom\Desktop\SAMP Server\gamemodes\newgm.pwn(364) : warning 215: expression has no effect
C:\Users\Tom\Desktop\SAMP Server\gamemodes\newgm.pwn(364) : error 001: expected token: ";", but found ":"
C:\Users\Tom\Desktop\SAMP Server\gamemodes\newgm.pwn(364) : error 029: invalid expression, assumed zero
C:\Users\Tom\Desktop\SAMP Server\gamemodes\newgm.pwn(364) : fatal error 107: too many error messages on one line
Thanks in advance to those who help.
Reply
#2

Update: I think I'm getting somewhere, I've got the errors down a little but not sure if I'm going the right way?


Код:
cmd(admins playerid, params[])
{
    if(IsPlayerConnected(playerid))
    {
        SendClientMessage(playerid, COLOR_ADMIN, "Online Staff Members:");

        new count; new ID; new admtext[64];
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            if(IsPlayerConnected(i))
            {
                new sendername[MAX_PLAYER_NAME];
                switch(PlayerInfo[i][pAdminLevel])
                        case 1: format(admtext, 64, "{10F441}Beta Tester");
                        case 2: format(admtext, 64, "{10F441}Moderator");
                        case 3: format(admtext, 64, "{33AA33}Administrator");
                        case 4: format(admtext, 64, "{FF0000}Senior Administrator");
                        case 1337: format(admtext, 64, "{FF0000}Head Administrator");
                        default: continue;
                    }

                GetPlayerName(i, sendername, sizeof(sendername));
                new tstr[128];
                format(tstr, 128, "%s(%d) - %s", sendername, ID, admtext);
                SendClientMessage(playerid, -1, tstr);
                format(admtext, 64, "");
                count++;
            }
            if(count == 0)
			{
			    SendClientMessage(playerid, COLOR_ERROR, "No online administrators found.");
				return 1;
			}
        }
    }
    return 1;
}
That's what I've changed now and it's returning this error:
Код:
C:\Users\Tom\Desktop\SAMP Server\gamemodes\newgm.pwn(373) : error 001: expected token: "{", but found "case"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Error.
Reply
#3

please quote the lines.
Reply
#4

Quote:
Originally Posted by SkillNasr
Посмотреть сообщение
please quote the lines.
I think this is what you mean?

Код:
if(IsPlayerConnected(i))
            {
                new sendername[MAX_PLAYER_NAME];
                switch(PlayerInfo[i][pAdminLevel])
                        case 1: format(admtext, 64, "{10F441}Beta Tester");
                        case 2: format(admtext, 64, "{10F441}Moderator");
                        case 3: format(admtext, 64, "{33AA33}Administrator");
                        case 4: format(admtext, 64, "{FF0000}Senior Administrator");
                        case 1337: format(admtext, 64, "{FF0000}Head Administrator");
                        default: continue;
                    }
I'm not finding the admin levels and printing them to the client.

For Example:
Admin Level 1 = Case 1 = Beta Tester
Admin Level 2 = Case 2 = Moderator

Hope you understand where I'm going with this. I created this with a different user system before but I was told to change to Y_INI instead.
Reply
#5

You forgot a bracket at the beginning of the switch statement.

pawn Код:
if(IsPlayerConnected(i))
            {
                new sendername[MAX_PLAYER_NAME];
                switch(PlayerInfo[i][pAdminLevel])
                { //Just add this.
                        case 1: format(admtext, 64, "{10F441}Beta Tester");
                        case 2: format(admtext, 64, "{10F441}Moderator");
                        case 3: format(admtext, 64, "{33AA33}Administrator");
                        case 4: format(admtext, 64, "{FF0000}Senior Administrator");
                        case 1337: format(admtext, 64, "{FF0000}Head Administrator");
                        default: continue;
                    }
Reply
#6

Quote:
Originally Posted by DTV
Посмотреть сообщение
You forgot a bracket at the beginning of the switch statement.

pawn Код:
if(IsPlayerConnected(i))
            {
                new sendername[MAX_PLAYER_NAME];
                switch(PlayerInfo[i][pAdminLevel])
                { //Just add this.
                        case 1: format(admtext, 64, "{10F441}Beta Tester");
                        case 2: format(admtext, 64, "{10F441}Moderator");
                        case 3: format(admtext, 64, "{33AA33}Administrator");
                        case 4: format(admtext, 64, "{FF0000}Senior Administrator");
                        case 1337: format(admtext, 64, "{FF0000}Head Administrator");
                        default: continue;
                    }
This worked and removed all the errors, but when there's an Administrator in-game it doesn't actually show up when you type /admins - Is there something wrong somewhere else in this code or should it just be [AdminLevel]?

Thank's for the help.
Reply
#7

Anyone got any ideas? - This was on the second page of the help section not sure if anyone's reading there, sorry for the double post if it's not allowed.
Reply
#8

This should work.
Код:
cmd(admins playerid, params[])
{
    SendClientMessage(playerid, COLOR_ADMIN, "Online Staff Members:");

    new count, string[62], aname[24];
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(!IsPlayerConnected(i))
            continue;
        
        string[0] = EOS;
        switch(PlayerInfo[i][pAdminLevel])
        {
            case 1: strcat(string, "{10F441}Beta Tester");
            case 2: strcat(string, "{10F441}Moderator");
            case 3: strcat(string, "{33AA33}Administrator");
            case 4: strcat(string, "{FF0000}Senior Administrator");
            case 1337: strcat(string, "{FF0000}Head Administrator");
            default: continue;
        }

        GetPlayerName(i, aname, 24);
        format(string, sizeof (string), "%s(%d) - %s", aname, i, string);
        SendClientMessage(playerid, -1, string);
        count++;
    }
    if(count == 0)
        return SendClientMessage(playerid, COLOR_ERROR, "No online administrators found.");
    return 1;
}
If it doesn't, then there's probably something wrong with PlayerInfo[i][pAdminLevel].
Reply
#9

Quote:
Originally Posted by Stinged
Посмотреть сообщение
This should work.

- Snip

If it doesn't, then there's probably something wrong with PlayerInfo[i][pAdminLevel].
Yep, doesn't work - Something is wrong somewhere else, I'll just re-work my system and see what I can do.

Thanks everyone who helped
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)