| ConnorMcLeod |
02-06-2013 00:53 |
Re: [MENU]Loop thru players and get info about them
Between the time you display menu and time when player select a player in that menu, some players can be disconnected, so it's better to use userId and then check if a player with that unique userid is still on the server.
PHP Code:
#include <amxmodx> #include <amxmisc>
#define PLUGIN "Players Infos Menu" #define VERSION "0.0.1"
enum ( <<= 1 ) { PLMENU_OBEY_IMMUNITY = 1, PLMENU_ALLOW_SELF, PLMENU_ONLY_ALIVE, PLMENU_NO_BOTS }
public plugin_init() { register_plugin( PLUGIN, VERSION, "ConnorMcLeod" )
register_clcmd("say /players", "ClCmd_Menu", ADMIN_RCON) }
public ClCmd_Menu(id, lvl, cid) { if( cmd_access(id, lvl, cid, 0) ) { new iMenu = MakePlayerMenu(id, "Players Infos Menu", "PlayersInfosMenuHandler", PLMENU_ALLOW_SELF | PLMENU_NO_BOTS) menu_setprop(iMenu, MPROP_NUMBER_COLOR, "\y") menu_display(id, iMenu) } return PLUGIN_HANDLED }
MakePlayerMenu(id, const szMenuTitle[], const szMenuHandler[], iFlags = PLMENU_OBEY_IMMUNITY) { new iMenu = menu_create(szMenuTitle, szMenuHandler) new bool:bIsSuperAdmin if( iFlags & PLMENU_OBEY_IMMUNITY ) { bIsSuperAdmin = !!(get_user_flags(id) & ADMIN_RCON) }
new iPlayers[32], iNum, iPlayer, szPlayerName[32], szUserId[32] new szFlags[4] = "h" if( iFlags & PLMENU_ONLY_ALIVE ) { szFlags[++iNum] = 'a' } if( flags & PLMENU_NO_BOTS ) { szFlags[++iNum] = 'c' }
get_players(iPlayers, iNum, szFlags)
for(--iNum; iNum>=0; iNum--) { iPlayer = iPlayers[iNum] get_user_name(iPlayer, szPlayerName, charsmax(szPlayerName))
if( iFlags & PLMENU_OBEY_IMMUNITY && !bIsSuperAdmin && ( (get_user_flags(iPlayer) & ADMIN_IMMUNITY) && ((iFlags & PLMENU_ALLOW_SELF) ? (id != iPlayer) : true) ) ) { menu_addtext(iMenu, szPlayerName) } else { formatex(szUserId, charsmax(szUserId), "%d", get_user_userid(iPlayer)) menu_additem(iMenu, szPlayerName, szUserId, 0) } }
return iMenu }
public PlayersInfosMenuHandler(id, iMenu, iItem) { if( iItem == MENU_EXIT ) { menu_destroy(iMenu) return PLUGIN_HANDLED }
new szUserId[32], szPlayerName[32], iPlayer menu_item_getinfo(iMenu, iItem, iCRAP, szUserId, charsmax(szUserId), szPlayerName, charsmax(szPlayerName), iPlayer /* tip */)
if( (iPlayer = find_player("k", str_to_num(szUserId))) ) { // new szName[32] // get_user_name(iPlayer, szName, charsmax(szName)) // client_print(id, print_chat, "You have chosen #%s %s %s", szUserId, szPlayerName, szName)
// Retrieve and display info (rank, ip, etc...) there } else { client_print(id, print_chat, "Player %s<%s> seems to be disconnected", szPlayerName, szAuthid) } menu_destroy(iMenu) return PLUGIN_HANDLED }
|