Need help with /admins and another thing
#1

I want a command/admin which will show the online admins. I created enum using this tutorial.
https://sampforum.blast.hk/showthread.php?tid=273088
How can I create that command?

Another question.
pawn Код:
format(str, sizeof(str), “%s has set your admin level to %i", (GetPlayerName(playerid, aname, sizeof(aname))), level
When I type this ig, it shows “Users/Aru.ini has set your admin level to 7"
It shows “Users/Aru.ini " instead of “Aru
Reply
#2

for the admins command:
pawn Код:
CMD:admins(playerid,params[])
{
    for(new i=0; i < MAX_PLAYERS; i++)
    {
        if(PlayerInfo[i][pAdmin] > 0)
        {
        new string[128],name[MAX_PLAYER_NAME];
        GetPlayerName(i,name,MAX_PLAYER_NAME);
        format(string,128,"Administrator %s - Online",name);
        SendClientMessage(playerid,-1,string);
        }
    }
    return 1;
}
Something like that.

About the other question, try it like this:
pawn Код:
new aname[MAX_PLAYER_NAME],str[128];
GetPlayerName(playerid, aname, sizeof(aname));
format(str, sizeof(str), “%s has set your admin level to %i", aname, level);
Reply
#3

To make an /admins command, you will need to loop through all online players. This can be achieved by using a typical for-loop, a while-loop or in terms of easier approach, foreach by ****** will help you do this quite efficiently as well.

Then you will simply need to see if the player's level is not zero (meaning the player is an admin).
pawn Код:
for(new i = 0; i != MAX_PLAYERS; i++)
{
    if(PlayerInfo[i][pAdmin])
    {
        // Send message?
    }
}
(Note this loop would require you to reset the pAdmin variable in OnPlayerDisconnect as no connection check is involved here - I consider this variable check to already be considered a connection check)

Note that more sophisticated methods are available here. If you were to run a large server and had a large staff team and an /admins command on the server, in some cases, there would be more staff members online than lines to display (although this can be expanded up to 20 lines). Then you could use some clever string concatenation (strcat) and formatting to put not just one, but two or three admin names on one line.


The second question has a simple answer: what you're trying to do is put the return value of GetPlayerName into the string using the %s specifier. This will not give you the result you desire. To have a numeric representation of the return value of GetPlayerName, you'd need to use %i or %d.
But then again, that's not what you need, either. You will need to have the GetPlayerName line PRIOR to the format line, and have "aname" as the parameter, not the GetPlayerName function call.
pawn Код:
GetPlayerName(playerid, aname, sizeof(aname));
format(str, sizeof(str), "%s", aname);
Reply
#4

Ok do it this way
pawn Код:
new string[128],FinalStr[128],name[MAX_PLAYER_NAME];
for(new i=0; i< MAX_PLAYERS; i++)
    {
          if(PlayerInfo[i][pAdmin] > 0)
               {
                     GetPlayerName(i,name,MAX_PLAYER_NAME);
                     format(string,128,"%s/n",name);
                     strcat(FinalStr,string);
                }
     }
SendClientMessage(playerid,-6","Online Admins");
SendClientMessage(playerid,-1,FinalStr);
Note: using m phone so there might be mistakes but Yh..
Reply
#5

Ok, let me see if i can help.

I've cut and edited a bit from my script, it's fully made. No bugs as far as i know. You can use this or try and learn from it.

The basic format is

Example

Romas3110 - Level 7


If no admins are connected.

No Admins are connected in the server.


pawn Код:
CMD:admins(playerid, params[])
{
    new str[128];
    new OnAdmins = 0;
    SendClientMessage(playerid,-1,"-----------------------------------Admins Online-----------------------------------");
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            if(PlayerInfo[i][pAdmin] != 0)
            {
                GetPlayerName(i,Nam,MAX_PLAYER_NAME);
                if(PlayerInfo[i][pAdmin] == 7)
                {
                    format(str, sizeof(str), "{0074D9}%s {FFFFFF}Level 7",Nam);
                    SendClientMessage(playerid,-1,str);
                }
                if(PlayerInfo[i][pAdmin] == 6)
                {
                    format(str, sizeof(str), "{0074D9}%s {FFFFFF}Level 6",Nam);
                    SendClientMessage(playerid,-1,str);
                }
                if(PlayerInfo[i][pAdmin] == 5)
                {
                    format(str, sizeof(str), "{0074D9}%s {FFFFFF}Level 5",Nam);
                    SendClientMessage(playerid,-1,str);
                }
                if(PlayerInfo[i][pAdmin] == 4)
                {
                    format(str, sizeof(str), "{0074D9}%s {FFFFFF}Level 4",Nam);
                    SendClientMessage(playerid,-1,str);
                }
                if(PlayerInfo[i][pAdmin] == 3)
                {
                    format(str, sizeof(str), "{0074D9}%s {FFFFFF}Level 3",Nam);
                    SendClientMessage(playerid,-1,str);
                }
                if(PlayerInfo[i][pAdmin] == 2)
                {
                    format(str, sizeof(str), "{0074D9}%s {FFFFFF}Level 2",Nam);
                    SendClientMessage(playerid,-1,str);
                }
                if(PlayerInfo[i][pAdmin] == 1)
                {
                    format(str, sizeof(str), "{0074D9}%s {FFFFFF}Level 1",Nam);
                    SendClientMessage(playerid,-1,str);
                }
                OnAdmins ++;
            }
        }
    }
    if(OnAdmins == 0)
    {
        SendClientMessage(playerid,0xFF0000FF,"No Admins are connected in the server.");
    }
    return 1;
}
Reply
#6

The
pawn Код:
if(IsPlayerConnected(i))
        {
why is that needed in this loop, when the variables used is assigned to player-id's, and which is most likely resetted onplayerconnect?

Just wondering, never got any answers to that. Thanks.
Reply
#7

I use it as a Precautionary matter, in some cases if i did not add it, it would return random strings.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)