Raised This Month: $ Target: $400
 0% 

[MENU]Loop thru players and get info about them


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
BlackRaven
Member
Join Date: Jun 2012
Location: Latvia
Old 02-05-2013 , 17:59   [MENU]Loop thru players and get info about them
Reply With Quote #1

Hello.
I want to get info about players from the loop list. (like ip,rank and stuff)
So when you select player from the list,opens another menu in which is info about player.
I made everything,but info in menu about the player is wrong.
Looped thru players:
PHP Code:
    new players[32], pnumtempid;
    new 
szName[32], szTempid[10];
    
    
get_players(playerspnum);
    
    for( new 
ii<pnumi++ )
    {
    
tempid players[i];

    
get_user_name(tempidszNamecharsmax(szName));
    
num_to_str(tempidszTempidcharsmax(szTempid));

    
menu_additem(menunameszNameszTempid0); 
Made that when selects player opens menu:
PHP Code:
    new data[6], szName[64];
    new 
accesscallback;
    
menu_item_getinfo(stmenuitemaccessdata,charsmax(data), szName,charsmax(szName), callback);

    new 
key str_to_num(data);

    switch(
key)
    {
        case 
.. 32:
        {
            
MenuName(id);
        }
    } 
PHP Code:
MenuName(id)
{
                
// making menu for info,blah blah.
                // and in the end get info from the player that was selected


So i need to get id from the player that was selected,but can someone tell me how?

Last edited by BlackRaven; 02-05-2013 at 19:07.
BlackRaven is offline
OvidiuS
Chillaxin'
Join Date: Dec 2009
Location: Serbia
Old 02-05-2013 , 20:54   Re: [MENU]Loop thru players and get info about them
Reply With Quote #2

Code:
/* Returns index. */ native get_user_index( const Name[ ] );

Last edited by OvidiuS; 02-05-2013 at 20:55.
OvidiuS is offline
Send a message via Skype™ to OvidiuS
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 02-06-2013 , 00:25   Re: [MENU]Loop thru players and get info about them
Reply With Quote #3

Quote:
Originally Posted by OvidiuS View Post
Code:
/* Returns index. */ native get_user_index( const Name[ ] );
Unnecessary.

Quote:
Originally Posted by BlackRaven View Post
Looped thru players:
PHP Code:
    new players[32], pnumtempid;
    new 
szName[32], szTempid[10];
    
    
get_players(playerspnum);
    
    for( new 
ii<pnumi++ )
    {
    
tempid players[i];

    
get_user_name(tempidszNamecharsmax(szName));
    
num_to_str(tempidszTempidcharsmax(szTempid));

    
menu_additem(menunameszNameszTempid0); 
Made that when selects player opens menu:
PHP Code:
    new data[6], szName[64];
    new 
accesscallback;
    
menu_item_getinfo(stmenuitemaccessdata,charsmax(data), szName,charsmax(szName), callback);

    new 
key str_to_num(data);

    switch(
key)
    {
        case 
.. 32:
        {
            
MenuName(id);
        }
    } 
So i need to get id from the player that was selected,but can someone tell me how?
The string variable "data" contains the player's id, that's the way you coded it.
__________________

Last edited by fysiks; 02-06-2013 at 00:26.
fysiks is offline
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
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 02-06-2013 , 00:58   Re: [MENU]Loop thru players and get info about them
Reply With Quote #5

Quote:
Originally Posted by ConnorMcLeod View Post
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.
Ah right, I should have mentioned this but I just answered the question literally.
__________________
fysiks is offline
BlackRaven
Member
Join Date: Jun 2012
Location: Latvia
Old 02-06-2013 , 10:29   Re: [MENU]Loop thru players and get info about them
Reply With Quote #6

Thank you guys!
BlackRaven is offline
Reply


Thread Tools
Display Modes

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