AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Using connected players menu (https://forums.alliedmods.net/showthread.php?t=153752)

bibu 03-28-2011 16:19

Using connected players menu
 
In my plugin, I have some submenus where you can afterwards select a player, I've done it like that:

PHP Code:

public SomeMenu(id)
{
    new 
menu menu_create("something""menu_handler_something")
    
    new 
players[32], pnum
    
    
new szName[32], szTempid[10]
    
get_players(playerspnum)
    
    for(new 
ii<pnum;i++)
    {
        
tempid players[i]
        
        
get_user_name(tempidszName31)
        
num_to_str(tempidszTempid9)
        
menu_additem(menuszNameszTempid0)
    }
    
menu_display(idmenu0)


Now, is there a possibility to just use one menu like that, except, that I can change individual the title of the menu and also the key handler stuff for sure.

ConnorMcLeod 03-28-2011 16:47

Re: Using connected players menu
 
I'm using this when i have to make a player menu :

PHP Code:

/*    Formatright © 2010, ConnorMcLeod

    This plugin is free software;
    you can redistribute it and/or modify it under the terms of the
    GNU General Public License as published by the Free Software Foundation.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this plugin; if not, write to the
    Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/

#include <amxmodx>
#include <amxmisc>

#define VERSION "0.0.1"
#define PLUGIN "Players Menu Generic"

public plugin_init()
{
    
register_plugin(PLUGINVERSION"ConnorMcLeod")
    
register_clcmd("say /players""ClCmd_Menu"ADMIN_RCON)
}

public 
ClCmd_Menu(idlvlcid)
{
    if( 
cmd_access(idlvlcid0) )
    {
        return 
PLUGIN_HANDLED
    
}

    new 
bool:bIsSuperAdmin = !!(get_user_flags(id) & ADMIN_RCON)
    new 
iPlayers[32], iNumiPlayerszPlayerName[32], szAuthid[32]
    
get_players(iPlayersiNum)
    new 
iMenu menu_create("Players Menu Misc""PlayersMenuHandler")
    
menu_setprop(iMenuMPROP_NUMBER_COLOR"\y")
    for(new 
ii<iNumi++)
    {
        
iPlayer iPlayers[i]
        if( !
bIsSuperAdmin && get_user_flags(iPlayer) & ADMIN_IMMUNITY )
        {
            
menu_addtext(iMenuszPlayerName)
        }
        else
        {
            
get_user_name(iPlayerszPlayerNamecharsmax(szPlayerName))
            
get_user_authid(iPlayerszAuthidcharsmax(szAuthid))
            
menu_additem(iMenuszPlayerNameszAuthid0)
        }
    }
    
menu_display(idiMenu)
    return 
PLUGIN_HANDLED
}

public 
PlayersMenuHandler(idiMenuiItem)
{
    if( 
iItem )
    {
        
menu_destroy(iMenu)
        return 
PLUGIN_HANDLED
    
}

    new 
szAuthid[32], szPlayerName[32], iCRAP
    menu_item_getinfo
(iMenuiItemiCRAPszAuthidcharsmax(szAuthid), szPlayerNamecharsmax(szPlayerName), iCRAP)
    new 
iPlayer find_player("c"szAuthid)

    if( 
iPlayer )
    {
        new 
szName[32]
        
get_user_name(iPlayerszNamecharsmax(szName))
        
client_print(idprint_chat"You have chosen %s %s %s"szAuthidszPlayerNameszName)
    }
    else
    {
        
client_print(idprint_chat"Player %s<%s> seems to be disconnected"szPlayerNameszAuthid)
    }
    
menu_destroy(iMenu)
    return 
PLUGIN_HANDLED



fysiks 03-28-2011 18:53

Re: Using connected players menu
 
Quote:

Originally Posted by bibu (Post 1440834)
Now, is there a possibility to just use one menu like that, except, that I can change individual the title of the menu and also the key handler stuff for sure.

You can change the name and info of menu items and I think you can change the title with MPROP_TITLE but I don't see a way to change the handler function.

ConnorMcLeod 03-29-2011 02:20

Re: Using connected players menu
 
Something like this ?

PHP Code:

public SomeMenu(id)
{
    new 
menu MakePlayerMenu(id"something""menu_handler_something""ch"// ch don't collect bot and hltv

    
menu_display(idmenu0)
}

#define PLMENU_OBEY_IMMUNITY (1<<0)
#define PLMENU_ALLOW_SELF    (1<<1)
#define PLMENU_ONLY_ALIVE    (1<<2)
#define PLMENU_NO_BOTS        (1<<3)

MakePlayerMenu(id, const szMenuTitle[], const szMenuHandler[], flags PLMENU_OBEY_IMMUNITY|PLMENU_NO_BOTS)
{
    new 
menu menu_create(szMenuTitleszMenuHandler)
    
    new 
players[32], pnum
    
    
new szName[32], szTempid[10]
    new 
szFlags[4], pnum
    
if( flags PLMENU_ONLY_ALIVE )
    {
        
szFlags[pnum++] = 'a'
    
}
    if( 
flags PLMENU_NO_BOTS )
    {
        
szFlags[pnum++] = 'c'
    
}
    
szFlags[pnum++] = 'h'

    
get_players(playerspnumszFlags)
    
    for(new 
ii<pnum;i++)
    {
        
tempid players[i]
        if(    
flags PLMENU_OBEY_IMMUNITY
        
&&    ( (get_user_flags(player) & ADMIN_IMMUNITY) && 
            ((
flags PLMENU_ALLOW_SELF) ? (id != tempid) : true) )    )
        {
            continue
        }
        
get_user_name(tempidszName31)
        
num_to_str(tempidszTempid9)
        
menu_additem(menuszNameszTempid0)
    }
    return 
menu


Implemented with my previous version :
PHP Code:

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

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

#define PLMENU_OBEY_IMMUNITY (1<<0)
#define PLMENU_ALLOW_SELF    (1<<1)
#define PLMENU_ONLY_ALIVE    (1<<2)
#define PLMENU_NO_BOTS        (1<<3)

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], szAuthid[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
        {
            
get_user_authid(iPlayerszAuthidcharsmax(szAuthid))
            
menu_additem(iMenuszPlayerNameszAuthid0)
        }
    }

    return 
iMenu
}

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

    new 
szAuthid[32], szPlayerName[32], iPlayer
    menu_item_getinfo
(iMenuiItemiCRAPszAuthidcharsmax(szAuthid), szPlayerNamecharsmax(szPlayerName), iPlayer /* tip */)

    if( 
iPlayer find_player("ch"szAuthid) || (szAuthid[0] == 'B' && ( iPlayer find_player("ai"szPlayerName) )) )
    {
        new 
szName[32]
        
get_user_name(iPlayerszNamecharsmax(szName))
        
client_print(idprint_chat"You have chosen %s %s %s"szAuthidszPlayerNameszName)
    }
    else
    {
        
client_print(idprint_chat"Player %s<%s> seems to be disconnected"szPlayerNameszAuthid)
    }
    
menu_destroy(iMenu)
    return 
PLUGIN_HANDLED



bibu 04-06-2011 16:52

Re: Using connected players menu
 
Error: Argument type mismatch (argument 4)

for

new menu = MakePlayerMenu(id, "something", "menu_handler_something", "ch") // ch don't collect bot and hltv

Exolent[jNr] 04-06-2011 16:56

Re: Using connected players menu
 
I'm sure Connor meant to post this line instead:
Code:
new menu = MakePlayerMenu(id, "something", "menu_handler_something", PLMENU_NO_BOTS)

ConnorMcLeod 04-06-2011 17:18

Re: Using connected players menu
 
Quote:

Originally Posted by Exolent[jNr] (Post 1445429)
I'm sure Connor meant to post this line instead:
Code:
new menu = MakePlayerMenu(id, "something", "menu_handler_something", PLMENU_NO_BOTS)

Exactly, also that last argument is optional.
But i think it's better to use the second i gave.

bibu 04-06-2011 17:24

Re: Using connected players menu
 
I didn't really understand what exactly the defines do, could you tell me that?

ConnorMcLeod 04-06-2011 17:33

Re: Using connected players menu
 
Same as cmd_target does except that this is for players that you want to put or not in menu, depending on actions you want to perform on players, you may want to not collect dead players, or bots, or admins with ADMIN_IMMUNITY flag.

PLMENU_ALLOW_SELF allows, if PLMENU_OBEY_IMMUNITY is set and if you have ADMIN_IMMUNITY flag, to add yourself.

bibu 04-10-2011 08:28

Re: Using connected players menu
 
Ok connor, I made this now, I didn't want to have any flags in this example, since you said flags are optional. You had something twice, iNum I think + you had iPlayer instead of id. Anyway, this doesn't show me anything:

PHP Code:

public SlayMenu(id)
{
    new 
menu MakePlayerMenu(id"\yWhich player to slay?""menu_handler_slay")

    
menu_display(idmenu0)




All times are GMT -4. The time now is 14:39.

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