AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [MENU]Loop thru players and get info about them (https://forums.alliedmods.net/showthread.php?t=207703)

BlackRaven 02-05-2013 17:59

[MENU]Loop thru players and get info about them
 
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?

OvidiuS 02-05-2013 20:54

Re: [MENU]Loop thru players and get info about them
 
Code:
/* Returns index. */ native get_user_index( const Name[ ] );

fysiks 02-06-2013 00:25

Re: [MENU]Loop thru players and get info about them
 
Quote:

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

Unnecessary.

Quote:

Originally Posted by BlackRaven (Post 1887983)
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.

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 ( <<= )
{
    
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



fysiks 02-06-2013 00:58

Re: [MENU]Loop thru players and get info about them
 
Quote:

Originally Posted by ConnorMcLeod (Post 1888210)
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. :)

BlackRaven 02-06-2013 10:29

Re: [MENU]Loop thru players and get info about them
 
Thank you guys! :)


All times are GMT -4. The time now is 20:34.

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