Raised This Month: $ Target: $400
 0% 

[MENU]Loop thru players and get info about them


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 02-06-2013 , 00:53   Re: [MENU]Loop thru players and get info about them
Reply With Quote #4

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 ( <<= )
{
    
PLMENU_OBEY_IMMUNITY 1,
    
PLMENU_ALLOW_SELF,
    
PLMENU_ONLY_ALIVE,
    
PLMENU_NO_BOTS
}

public 
plugin_init()
{
    
register_pluginPLUGINVERSION"ConnorMcLeod" )

    
register_clcmd("say /players""ClCmd_Menu"ADMIN_RCON)
}

public 
ClCmd_Menu(idlvlcid)
{
    if( 
cmd_access(idlvlcid0) )
    {
        new 
iMenu MakePlayerMenu(id"Players Infos Menu""PlayersInfosMenuHandler"PLMENU_ALLOW_SELF PLMENU_NO_BOTS)
        
menu_setprop(iMenuMPROP_NUMBER_COLOR"\y")
        
menu_display(idiMenu)
    }
    return 
PLUGIN_HANDLED
}

MakePlayerMenu(id, const szMenuTitle[], const szMenuHandler[], iFlags PLMENU_OBEY_IMMUNITY)
{
    new 
iMenu menu_create(szMenuTitleszMenuHandler)
    new 
bool:bIsSuperAdmin
    
if( iFlags PLMENU_OBEY_IMMUNITY )
    {
        
bIsSuperAdmin = !!(get_user_flags(id) & ADMIN_RCON)
    }

    new 
iPlayers[32], iNumiPlayerszPlayerName[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(iPlayersiNumszFlags)

    for(--
iNumiNum>=0iNum--)
    {
        
iPlayer iPlayers[iNum]
        
get_user_name(iPlayerszPlayerNamecharsmax(szPlayerName))

        if(    
iFlags PLMENU_OBEY_IMMUNITY && !bIsSuperAdmin
        
&&    ( (get_user_flags(iPlayer) & ADMIN_IMMUNITY) && 
            ((
iFlags PLMENU_ALLOW_SELF) ? (id != iPlayer) : true) )    )
        {
            
menu_addtext(iMenuszPlayerName)
        }
        else
        {
            
formatex(szUserIdcharsmax(szUserId), "%d"get_user_userid(iPlayer))
            
menu_additem(iMenuszPlayerNameszUserId0)
        }
    }

    return 
iMenu
}

public 
PlayersInfosMenuHandler(idiMenuiItem)
{
    if( 
iItem == MENU_EXIT )
    {
        
menu_destroy(iMenu)
        return 
PLUGIN_HANDLED
    
}

    new 
szUserId[32], szPlayerName[32], iPlayer
    menu_item_getinfo
(iMenuiItemiCRAPszUserIdcharsmax(szUserId), szPlayerNamecharsmax(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(idprint_chat"Player %s<%s> seems to be disconnected"szPlayerNameszAuthid)
    }
    
menu_destroy(iMenu)
    return 
PLUGIN_HANDLED

__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 02-06-2013 at 00:54.
ConnorMcLeod is offline
 



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 20:34.


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