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.