[HELP]how to get /admins info
#1

This is my /setadmin script..

Quote:

enum pInfo
{
pPass,
pCash,
pAdmin,
pSkin,
pKills,
pDeaths
}
new PlayerInfo[MAX_PLAYERS][pInfo];
CMDetadmin(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;
}

How can i get /admins .. Which shows a dialog box of the admins ONLINE?
Reply
#2

pawn Code:
CMD:admins(playerid) {
    new string[128+MAX_PLAYER_NAME], plName[MAX_PLAYER_NAME];
    foreach(Player, i) {
        if(PlayerInfo[i][pAdmin] != 0) {
            GetPlayerName(i, plName, sizeof plName);
            format(string, sizeof string, "%sAdmin: %s(%d)\n", string, plName, i);
        }
        ShowPlayerDialog(playerid, DIALOG_ID, DIALOG_STYLE_MSGBOX, "Admins Online", string, "Okay, "");
    }
    return 1;  
}
Should work.
Reply
#3

You have to use strcat, otherwise it can only show 1 admin at a time.
Reply
#4

It shouldn't with the way I have done it, it'll show the previous string then the new string.
Reply
#5

This will work:
PHP Code:
CMD:admins(playerid) {
    new 
string[256], tempstring[56], plName[MAX_PLAYER_NAME];
    foreach(
Playeri) {
        if(
PlayerInfo[i][pAdmin] != 0) {
            
GetPlayerName(iplNamesizeof plName);
            
format(tempstringsizeof tempstring"Admin: %s(%d), Rank:%d\n"plNameiPlayerInfo[i][pAdmin]);
            
strcat(stringtempstringsizeof(string));
        }
        
ShowPlayerDialog(playeridDIALOG_IDDIALOG_STYLE_MSGBOX"Admins Online"string"Okay, "");
    }
    return 1;    

Reply
#6

Quote:
Originally Posted by ATGOggy
View Post
This will work:
PHP Code:
CMD:admins(playerid) {
    new 
string[256], tempstring[56], plName[MAX_PLAYER_NAME];
    foreach(
Playeri) {
        if(
PlayerInfo[i][pAdmin] != 0) {
            
GetPlayerName(iplNamesizeof plName);
            
format(tempstringsizeof tempstring"Admin: %s(%d), Rank:%d\n"plNameiPlayerInfo[i][pAdmin]);
            
strcat(stringtempstringsizeof(string));
        }
        
ShowPlayerDialog(playeridDIALOG_IDDIALOG_STYLE_MSGBOX"Admins Online"string"Okay, "");
    }
    return 1;    

You've just copied my code and added strcat. I've nothing wrong with that, but, I really don't see the point. Also, you haven't read ******' tutorial about using 256 sized strings, which is why I used a string size of 128 and added the MAX_PLAYER_NAME size which is 24.
Reply
#7

Quote:
Originally Posted by Luis-
View Post
You've just copied my code and added strcat. I've nothing wrong with that, but, I really don't see the point. Also, you haven't read ******' tutorial about using 256 sized strings.
With your code, it will show only one admin at a time. I used 256 sized string because if there are more admins, their name should fit in the string.
Reply
#8

Quote:
Originally Posted by Luis-
View Post
Should work...
This will show only an administrator, what he said Calvin is correct, you'll need to use "strcat".

Quote:
Originally Posted by ATGOggy
View Post
This will work:
Your code might only show 4 or 5 administrators and although there is no connected administrators will display the dialog without information about this.


PHP Code:
CMD:admins(playeridparams[])
{
    
#pragma unused params
    //..
    
new string[41*12], name[24], sformat[41], admins// string[41*12] = max 12 admins show in dialog.
    //..
    
for(new i!= MAX_PLAYERSi++)
    {
        if(
IsPlayerConnected(i))
        {
            if(
PlayerInfo[i][pAdmin] >= 1)
            {
                
GetPlayerName(inamesizeof(name));
                
format(sformatsizeof(sformat), "* %s Level %d.\n"namePlayerInfo[i][pAdmin]);
                
strcat(stringsformat);
                
admins admins+1;
            }
        }
    }
    if(
admins 1)
        
ShowPlayerDialog(playeriddialogidDIALOG_STYLE_MSGBOX"Info admins""There are no administrators connected.""accept""exit");
    else if(
admins >= 1)
        
ShowPlayerDialog(playeriddialogidDIALOG_STYLE_MGSBOX"Info admins"string"accept""exit");
    return 
true;

This will show maximum 12 administrators, if you want to add more simply change this.

PHP Code:
new string[41*12]; // (12) 
Reply
#9

My code would show all the admins that are online.

pawn Code:
format(string, sizeof string, "%sAdmin: %s(%d)\n", string, plName, i);
That line would pretty much format the string, then reformat it using the string it previously formatted but adding a new line each time it formats it, probably not the best way to do it, but it will still work.
Reply
#10

Quote:
Originally Posted by Luis-
View Post
My code would show all the admins that are online.

pawn Code:
format(string, sizeof string, "%sAdmin: %s(%d)\n", string, plName, i);
That line would pretty much format the string, then reformat it using the string it previously formatted but adding a new line each time it formats it, probably not the best way to do it, but it will still work.
Oh, I didn't notice that "%s, string". Sorry.
Reply
#11

Juan stone ? Why there is a need of a dialog box? And accept button at the same time?
Reply
#12

Try this:
PHP Code:
CMD:admins(playeridparams[]) 

    
#pragma unused params 
    //.. 
    
new string[41*12], name[24], sformat[41], admins// string[41*12] = max 12 admins show in dialog. 
    //.. 
    
for(new i!= MAX_PLAYERSi++) 
    { 
        if(
IsPlayerConnected(i)) 
        { 
            if(
PlayerInfo[i][pAdmin] >= 1
            { 
                
GetPlayerName(inamesizeof(name)); 
                
format(sformatsizeof(sformat), "* %s Level %d.\n"namePlayerInfo[i][pAdmin]); 
                
strcat(stringsformat); 
                
admins admins+1
            } 
        } 
    } 
    if(
admins 1
        
ShowPlayerDialog(playeriddialogidDIALOG_STYLE_MSGBOX"Info admins""There are no administrators connected.""Close"""); 
    else if(
admins >= 1
        
ShowPlayerDialog(playeriddialogidDIALOG_STYLE_MGSBOX"Info admins"string"Close"""); 
    return 
true

Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)