SA-MP Forums Archive
/admins Command. - 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: /admins Command. (/showthread.php?tid=568180)



/admins Command. - TuSheng - 20.03.2015

I Type /admins It Just Show 1 Admin Online , Even The Server Have More Admins Online , But It Just Show 1 Admin Name , Someone Know How To Fix It? I Already Found Some Same Problem Threads , But Noone's /admins Same/Match With Me. If You Guys Know How To Fix It Please Help Me , Thanks !

Sorry About My Bad English.

PHP Code:
CMD:admins(playeridparams[])
{
    new 
id;
    new 
n[MAX_PLAYER_NAME];
    new 
count 0string19[256];
    
GetPlayerName(id,n,sizeof(n));
    for(new 
0MAX_PLAYERS++)
    {
    if(
IsPlayerConnected(i))
    {
    if(
pInfo[id][Adminlevel] == 1)
    {
    
format(string19sizeof(string19), "Trial Moderator : %s (%i)",,playerid);
    
count++;
    }
    if(
pInfo[id][Adminlevel] == 2)
    {
    
format(string19sizeof(string19), "Moderator : %s (%i)",,playerid);
    
count++;
    }
    if(
pInfo[id][Adminlevel] == 3)
    {
    
format(string19sizeof(string19), "Admin : %s (%i)",,playerid);
    
count++;
    }
    if(
pInfo[id][Adminlevel] == 4)
    {
    
format(string19sizeof(string19), "Server Manager : %s (%i)",,playerid);
    
count++;
    }
    if(
pInfo[id][Adminlevel] == 5)
    {
    
format(string19sizeof(string19), "Server Owner : %s (%i)",,playerid);
    
count++;
    }
    }
    }
    if(
count == 0)
    {
    
SendClientMessage(playeridCOLOR_GREEN"");
    
SendClientMessage(playeridCOLOR_GREEN"|======== Online Admins =======|");
    
SendClientMessage(playeridCOLOR_WHITE"- No Admins Online at Time!");
    
SendClientMessage(playeridCOLOR_GREEN"|==============================|");
    
SendClientMessage(playeridCOLOR_GREEN"");
    }
    else
    {
    
SendClientMessage(playeridCOLOR_GREEN"");
    
SendClientMessage(playeridCOLOR_GREEN"|======== Online Admins =======|");
    
SendClientMessage(playeridCOLOR_WHITEstring19);
    
SendClientMessage(playeridCOLOR_GREEN"|==============================|");
    
SendClientMessage(playeridCOLOR_GREEN"");
    }
    return 
1;




Re: .:[Help]:. /admins Command. - CalvinC - 20.03.2015

You should format and SendClientMessage for every admin, like:
pawn Code:
if(pInfo[id][Adminlevel] == 5)
{
    format(string19, sizeof(string19), "Server Owner : %s (%i)",n ,playerid);
    SendClientMessage(playerid, COLOR_WHITE, string19);
    count++;
}
And same with the rest.


Re: .:[Help]:. /admins Command. - iZN - 20.03.2015

There were mistakes with playerid, the loop's variable 'i' should be the playerid, not variable 'id'. Your variable 'id' would only show player ID 0 since the default variable value is 0. You CAN use playerid parameter. I also did some changes with admin level checks, switch() statement is better than using many if-else statements. String size doesn't needs to be 256, I've lowered it to 128, and I'm sure that's even higher too.

pawn Code:
CMD:admins(playerid, params[])
{
    new n[MAX_PLAYER_NAME+1];
    new count = 0, string19[128];

    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            GetPlayerName(i, n, sizeof(n));
            switch(pInfo[i][Adminlevel])
            {
                case 1:
                {
                    format(string19, sizeof(string19), "Trial Moderator : %s (%i)", n , i);
                    count++;
                }
                case 2:
                {
                    format(string19, sizeof(string19), "Moderator : %s (%i)", n , i);
                    count++;
                }
                case 3:
                {
                    format(string19, sizeof(string19), "Admin : %s (%i)", n , i);
                    count++;
                }
                case 4:
                {
                    format(string19, sizeof(string19), "Server Manager : %s (%i)", n , i);
                    count++;
                }
                case 5:
                {
                    format(string19, sizeof(string19), "Server Owner : %s (%i)", n , i);
                    count++;
                }
            }
        }
    }
    if(!count)
    {
        SendClientMessage(playerid, COLOR_GREEN, "");
        SendClientMessage(playerid, COLOR_GREEN, "|======== Online Admins =======|");
        SendClientMessage(playerid, COLOR_WHITE, "- No Admins Online at Time!");
        SendClientMessage(playerid, COLOR_GREEN, "|==============================|");
        SendClientMessage(playerid, COLOR_GREEN, "");
    }
    else
    {
        SendClientMessage(playerid, COLOR_GREEN, "");
        SendClientMessage(playerid, COLOR_GREEN, "|======== Online Admins =======|");
        SendClientMessage(playerid, COLOR_WHITE, string19);
        SendClientMessage(playerid, COLOR_GREEN, "|==============================|");
        SendClientMessage(playerid, COLOR_GREEN, "");
    }
    return true;
}



Re: /admins Command. - FOTIS6 - 20.03.2015

Should work.

Code:
CMD:admins(playerid, params[]) 
{ 
    new count = 0, string19[256]; 
    SendClientMessage(playerid, COLOR_GREEN, ""); 
    SendClientMessage(playerid, COLOR_GREEN, "|======== Online Admins =======|");  
    for(new i = 0; i < MAX_PLAYERS; i ++) 
    { 
    if(IsPlayerConnected(i)) 
    { 
    if(pInfo[i][Adminlevel] == 1) 
    {
    format(string19, sizeof(string19), "Trial Moderator : %s (%i)",GetName(i), i); 
    SendClientMessage(playerid, COLOR_WHITE, string19); 
    count++; 
    } 
    if(pInfo[i][Adminlevel] == 2) 
    { 
    format(string19, sizeof(string19), "Moderator : %s (%i)",GetName(i), i);
    SendClientMessage(playerid, COLOR_WHITE, string19);  
    count++; 
    } 
    if(pInfo[i][Adminlevel] == 3) 
    { 
    format(string19, sizeof(string19), "Admin : %s (%i)",GetName(i), i);
    SendClientMessage(playerid, COLOR_WHITE, string19); 
    count++; 
    } 
    if(pInfo[i][Adminlevel] == 4) 
    { 
    format(string19, sizeof(string19), "Server Manager : %s (%i)",GetName(i), i);
    SendClientMessage(playerid, COLOR_WHITE, string19); 
    count++; 
    } 
    if(pInfo[i][Adminlevel] == 5) 
    { 
    format(string19, sizeof(string19), "Server Owner : %s (%i)",GetName(i), i); 
    SendClientMessage(playerid, COLOR_WHITE, string19);
    count++; 
    } 
    } 
    } 
    if(count == 0) 
    SendClientMessage(playerid, COLOR_WHITE, "- No Admins Online at this Time!"); 
    SendClientMessage(playerid, COLOR_GREEN, "|==============================|"); 
    SendClientMessage(playerid, COLOR_GREEN, ""); 
    return 1; 
}  

stock GetName(playerid)
{
     new pname[MAX_PLAYER_NAME];
     GetPlayerName(playerid, pname, MAX_PLAYER_NAME);
     return pname;
}



Re: /admins Command. - IzadorO - 20.03.2015

Code:
// Variables
enum pInfo
{
    AdminRank,
};

// Stock - Setting out the Administration ranks
stock GetAdminRank(playerid)
{
     new adminrank[128];
     for(new i = 0; i < MAX_PLAYERS; i++)
     {
         switch(pInfo[I][AdminLevel]
         {
               case 0: "";
               case 1: //designated Admin rank here 
               case 2: //designated Admin rank here
               case 3: //designated Admin rank here
               case 4: //designated Admin rank here
               case 5: // designated Admin rank here
          }
          return adminrank;
}

CMD:admins(playerid, params[])
{
     format(string, sizeof(string), "[%s] %s [%d]", GetAdminRank(playerid), n, playerid);
     SendClientMessage(playerid, colour, string);
     return 1;
}
You should be able to sort out everything by yourself, based off this code.

Also, do you use MySQL or dini for saving?


Re: /admins Command. - fuckingcruse - 20.03.2015

Try this admin code , i just made one new one ...

Code:
enum pInfo
{
    pPass,
    pCash,
    pAdmin,
    pSkin,
    pKills,
    pDeaths
}
new PlayerInfo[MAX_PLAYERS][pInfo];
CMD:setadmin(playerid, params[])
{
    new pID, value;
    if(!IsPlayerAdmin(playerid)) return 0;
    else if(sscanf(params, "ui", pID, value)) return SendClientMessage(playerid, -1, "Usage: /setadmin (id) (level)");
    else if(value < 0 || value > 5) return SendClientMessage(playerid, -1, "Only levels 0-5");
    else if(pID == INVALID_PLAYER_ID) return SendClientMessage(playerid, -1, "Player Is Not Currently Connected");
    else
    {
        new string[128], string1[128], target[MAX_PLAYER_NAME], pName[MAX_PLAYER_NAME];
		GetPlayerName(playerid, pName, sizeof(pName));
		GetPlayerName(pID, target, sizeof(target));
        format(string, sizeof(string), "You have set %s Admin level to %i", target, value);
        SendClientMessage(playerid, -1, string);
        format(string, sizeof(string), "Your Admin level has been set to %i by %s", value, pName);
        SendClientMessage(pID, -1, string1);
        PlayerInfo[pID][pAdmin] = value;
    }
    return 1;
}
#define DIALOG_MSG 2
CMD:admins(playerid, params[])
{
    #pragma unused params
    //..
    new string[41*12], name[24], sformat[41], admins; // string[41*12] = max 12 admins show in dialog.
    //..
    for(new i; i != MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            if(PlayerInfo[i][pAdmin] >= 1)
            {
                GetPlayerName(i, name, sizeof(name));
                format(sformat, sizeof(sformat), "* %s Level %d.\n", name, PlayerInfo[i][pAdmin]);
                strcat(string, sformat);
                admins = admins+1;
            }
        }
    }
    if(admins < 1)
        ShowPlayerDialog(playerid, DIALOG_MSG, DIALOG_STYLE_MSGBOX, "Info admins", "There are no administrators connected.", "Close", "");
    else if(admins >= 1)
        ShowPlayerDialog(playerid, DIALOG_MSG, 0, "Info admins", string, "Close", "");
    return true;
}



Re: /admins Command. - Glossy42O - 20.03.2015

Why the heck u people give him it fixed? Tell him HOW to fix it.

If you just give him the cmd he won't learn shit.


Re: .:[Help]:. /admins Command. - TuSheng - 20.03.2015

Quote:
Originally Posted by iZN
View Post
There were mistakes with playerid, the loop's variable 'i' should be the playerid, not variable 'id'. Your variable 'id' would only show player ID 0 since the default variable value is 0. You CAN use playerid parameter. I also did some changes with admin level checks, switch() statement is better than using many if-else statements. String size doesn't needs to be 256, I've lowered it to 128, and I'm sure that's even higher too.

pawn Code:
CMD:admins(playerid, params[])
{
    new n[MAX_PLAYER_NAME+1];
    new count = 0, string19[128];
    GetPlayerName(playerid, n, sizeof(n));

    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            switch(pInfo[i][Adminlevel])
            {
                case 1:
                {
                    format(string19, sizeof(string19), "Trial Moderator : %s (%i)", n , i);
                    count++;
                }
                case 2:
                {
                    format(string19, sizeof(string19), "Moderator : %s (%i)", n , i);
                    count++;
                }
                case 3:
                {
                    format(string19, sizeof(string19), "Admin : %s (%i)", n , i);
                    count++;
                }
                case 4:
                {
                    format(string19, sizeof(string19), "Server Manager : %s (%i)", n , i);
                    count++;
                }
                case 5:
                {
                    format(string19, sizeof(string19), "Server Owner : %s (%i)", n , i);
                    count++;
                }
            }
        }
    }
    if(!count)
    {
        SendClientMessage(playerid, COLOR_GREEN, "");
        SendClientMessage(playerid, COLOR_GREEN, "|======== Online Admins =======|");
        SendClientMessage(playerid, COLOR_WHITE, "- No Admins Online at Time!");
        SendClientMessage(playerid, COLOR_GREEN, "|==============================|");
        SendClientMessage(playerid, COLOR_GREEN, "");
    }
    else
    {
        SendClientMessage(playerid, COLOR_GREEN, "");
        SendClientMessage(playerid, COLOR_GREEN, "|======== Online Admins =======|");
        SendClientMessage(playerid, COLOR_WHITE, string19);
        SendClientMessage(playerid, COLOR_GREEN, "|==============================|");
        SendClientMessage(playerid, COLOR_GREEN, "");
    }
    return true;
}
Thanks For Editing , But Only Show 1 Admin Name Again , And If Player(He Isn't Admin) Type /admins , He Name Will In The Admin List , But He Isn't Admin , Is This A Bug Or? I Want That /admins We Can See More Admins Online , No Only 1. If You Understand Me , Thanks.

Quote:
Originally Posted by CalvinC
View Post
You should format and SendClientMessage for every admin, like:
pawn Code:
if(pInfo[id][Adminlevel] == 5)
{
    format(string19, sizeof(string19), "Server Owner : %s (%i)",n ,playerid);
    SendClientMessage(playerid, COLOR_WHITE, string19);
    count++;
}
And same with the rest.
Yes , I Tried But No Working , Same Problem Like iZN's Replied. The Problem Is : You're Not Admin But You Name Still In The Admin List. Thanks For You Replied Too. I Just Want That /admins Can Show More Admins Online , And Non-Admin Player's Name No On The Admin List Too.

Sorry About My Bad English.


Re: .:[Help]:. /admins Command. - iZN - 20.03.2015

Quote:
Originally Posted by TuSheng
View Post
Thanks For Editing , But Only Show 1 Admin Name Again , And If Player(He Isn't Admin) Type /admins , He Name Will In The Admin List , But He Isn't Admin , Is This A Bug Or? I Want That /admins We Can See More Admins Online , No Only 1. If You Understand Me , Thanks.



Yes , I Tried But No Working , Same Problem Like iZN's Replied. The Problem Is : You're Not Admin But You Name Still In The Admin List. Thanks For You Replied Too. I Just Want That /admins Can Show More Admins Online , And Non-Admin Player's Name No On The Admin List Too.

Sorry About My Bad English.
Oh I just edited my code above, please re-check it. There was one mistake made by you (and yeah, I didn't see that aswell) you have to put "GetPlayerName(playerid, n, sizeof(n));" in that player-loop with the loop variable 'i' instead of 'playerid'!

@FOTIS6: I already posted the fixed above.
@fuckingcruse: yes I believe in you, you really made that code.

Quote:
Originally Posted by IzadorO
View Post
Code:
.....
You should be able to sort out everything by yourself, based off this code.

Also, do you use MySQL or dini for saving?
What MySQL or dini has to do with the related code? There's a player variable which does the job, don't make things complex.

Quote:
Originally Posted by CalvinC
View Post
You're trying to check if playerid 0 is an admin at all times, since you declared "id" to use, which is set to 0 by default.
Delete "id", and use "i" from the loop instead.
No need to explain what I already did.


Re: .:[Help]:. /admins Command. - CalvinC - 20.03.2015

Quote:
Originally Posted by iZN
View Post
No need to explain what I already did.
I just mentioned it for him again, as he apparently ignored your post.
For explanations, both iZN and i already gave you.