Raised This Month: $51 Target: $400
 12% 

Showing admins in hudmessage list?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
colby
Senior Member
Join Date: Jun 2005
Location: NC
Old 07-30-2006 , 22:53   Showing admins in hudmessage list?
Reply With Quote #1

Warning: Might be a long post ahead.

My friend requested that I make a plugin that will list the current admins in the server in a HUD message, and it's a little trickier than I thought.
I was looking at this plugin (Screenshot) for reference, but I can't seem to understand exactly how it works.


The code:
Code:
#include <amxmodx>

/*---------------EDIT ME------------------*/
#define ADMIN_CHECK ADMIN_KICK

static const COLOR[] = "^x04" //green
static const CONTACT[] = ""
/*---------------------------------------------*/

new maxplayers
new gmsgSayText

public plugin_init() {
    register_plugin("Admin Check", "1.51", "OneEyed")
    maxplayers = get_maxplayers()
    gmsgSayText = get_user_msgid("SayText")
    register_clcmd("say", "handle_say")
    register_cvar("amx_contactinfo", CONTACT, FCVAR_SERVER)
}

public handle_say(id) {
    new said[192]
    read_args(said,192)
    if( ( containi(said, "who") != -1 && containi(said, "admin") != -1 ) || contain(said, "/admin") != -1 )
        set_task(0.1,"print_adminlist",id)
    return PLUGIN_CONTINUE
}

public print_adminlist(user) 
{
    new adminnames[33][32]
    new message[256]
    new contactinfo[256], contact[112]
    new id, count, x, len
    
    for(id = 1 ; id <= maxplayers ; id++)
        if(is_user_connected(id))
            if(get_user_flags(id) & ADMIN_CHECK)
                get_user_name(id, adminnames[count++], 31)

    len = format(message, 255, "%s ADMINS ONLINE: ",COLOR)
    if(count > 0) {
        for(x = 0 ; x < count ; x++) {
            len += format(message[len], 255-len, "%s%s ", adminnames[x], x < (count-1) ? ", ":"")
            if(len > 96 ) {
                print_message(user, message)
                len = format(message, 255, "%s ",COLOR)
            }
        }
        print_message(user, message)
    }
    else {
        len += format(message[len], 255-len, "No admins online.")
        print_message(user, message)
    }
    
    get_cvar_string("amx_contactinfo", contact, 63)
    if(contact[0])  {
        format(contactinfo, 111, "%s Contact Server Admin -- %s", COLOR, contact)
        print_message(user, contactinfo)
    }
}

print_message(id, msg[]) {
    message_begin(MSG_ONE, gmsgSayText, {0,0,0}, id)
    write_byte(id)
    write_string(msg)
    message_end()
}
Now, looking at the print_adminlist function:
Code:
     new adminnames[33][32]
    new message[256]
    new contactinfo[256], contact[112]
    new id, count, x, len
    
    for(id = 1 ; id <= maxplayers ; id++)
        if(is_user_connected(id))
            if(get_user_flags(id) & ADMIN_CHECK)
                get_user_name(id, adminnames[count++], 31)
* Ok, maxplayers = get_maxplayers() so if there were 32 slots, maxplayers would equal 32.
* id = 1, and as long as id is less than or equal to maxplayers (which is 32), id will go up by 1, essentially looping the proceeding code 32 times.
Now here is my question: How are you able to check if id is connected/get it's flags if it is simply a number? Does the number represent a player index?


This is where I get confused:
Code:
   len = format(message, 255, "%s ADMINS ONLINE: ",COLOR)
    if(count > 0) {
        for(x = 0 ; x < count ; x++) {
            len += format(message[len], 255-len, "%s%s ", adminnames[x], x < (count-1) ? ", ":"")
            if(len > 96 ) {
                print_message(user, message)
                len = format(message, 255, "%s ",COLOR)
            }
        }
        print_message(user, message)
    }
* If the count (number of admins) is greater than 0
* So, if there were 4 admins: x = 0 and as long as x is less than 4, x goes up by 1, looping the proceeding code 4 times, right?
* The line of code in bold I don't understand at all.
* The if(len > 96) blah blah is for printing the message out on a second line if the length of the message goes over 96, but i don't really care about that because I want this list to show up as a HUD message.


Also, for more than one HUD message to show up on the screen at one time, they each must be a different channel and at a different location (since we are making a list). How would I go about doing that? I know there would be some kind of loop that would, say, have the channel start at a number and go up by 1 while having the y position start at a number and go up by 0.03, I just don't know how I should go about coding it.
colby is offline
Send a message via AIM to colby
XxAvalanchexX
Veteran Member
Join Date: Oct 2004
Location: abort73.com
Old 07-30-2006 , 23:10   Re: Showing admins in hudmessage list?
Reply With Quote #2

Here's a (I hope) working script, overflowing with comments. Let me know if you don't understand any of this.

Code:
#include <amxmodx> #include <amxmisc> public show_admins(id) {     // create a variable that will hold our string     new adminlist[2048];     adminlist = "ADMINS:^n"; // ^n creates a new line     // collect all the players in the game     new players[32], num;     get_players(players,num);     // initialize some variables outside of the loop     new i, name[32], temp[64];     // go through all of our connected players     for(i=0;i<num;i++)     {         // if this player is an admin         if(is_user_admin(players[i]))         {             // get their name and add it to our string             get_user_name(players[i],name,31);             // compile a new string to add to the old one             // we do this in two parts because the add function doesn't support string formatting             format(temp,63,"- %s^n",name);             add(adminlist,2048,temp);         }     }     // if we did not find any admins (no "-" indicator)     if(strfind(adminlist,"-") == -1)         add(adminlist,2048,"- None");     // setup our hudmessage and display it     set_hudmessage(); // modify this one yourself     show_hudmessage(id,adminlist); }

For configuring set_hudmessage, see this page.

Other users will advocate not using the add function. I'll just let them do it since they can explain it better than I can.
__________________
No longer around. Thanks your support, everyone! As always:
THIS ONES FOR YOU
3000 PTS

Last edited by XxAvalanchexX; 07-30-2006 at 23:13.
XxAvalanchexX is offline
colby
Senior Member
Join Date: Jun 2005
Location: NC
Old 07-30-2006 , 23:43   Re: Showing admins in hudmessage list?
Reply With Quote #3

Wow, I can't believe I didn't think of it that way, so easy. Thanks a lot for your help.

Edit:
For anyone who's interested (tested, but not extensively):
PHP Code:
#include <amxmodx>
#include <amxmisc>


public plugin_init() {
    
register_plugin("Admin HUD List","1.0","Avalanche")
    
register_clcmd("say /admins","clcmd_admins",-1," - Shows online admins")
}

public 
clcmd_admins(id) {    
    new 
adminlist[2048] = "ADMINS:^n"

    
new temp[64],adminnames[32],players[32],num,player,i
    get_players
(players,num)
    
    for(
0;num;i++) {
        
player players[i]
        if(
is_user_connected(player) && is_user_admin(player)) {
            
get_user_name(player,adminnames,31)
            
format(temp,63,"-  %s^n",adminnames)
            
add(adminlist,2047,temp)
        }
    }

    if(
strfind(adminlist,"-") == -1) {
        
add(adminlist,2047,"-  None")
    }

    
set_hudmessage(0,255,0,0.08,0.08,_,_,_,_,_,79)
    
show_hudmessage(id,adminlist)
    return 
PLUGIN_HANDLED


Last edited by colby; 07-31-2006 at 00:27.
colby is offline
Send a message via AIM to colby
XxAvalanchexX
Veteran Member
Join Date: Oct 2004
Location: abort73.com
Old 07-31-2006 , 15:24   Re: Showing admins in hudmessage list?
Reply With Quote #4

I see you caught my mistake and changed it from 2048 to 2047 in the adds. I didn't think about it until I was falling asleep last night. Good work!
__________________
No longer around. Thanks your support, everyone! As always:
THIS ONES FOR YOU
3000 PTS
XxAvalanchexX is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 19:56.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode