Raised This Month: $ Target: $400
 0% 

Using connected players menu


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
bibu
Veteran Member
Join Date: Sep 2010
Old 03-28-2011 , 16:19   Using connected players menu
Reply With Quote #1

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.
bibu is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 03-28-2011 , 16:47   Re: Using connected players menu
Reply With Quote #2

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

__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 03-28-2011 , 18:53   Re: Using connected players menu
Reply With Quote #3

Quote:
Originally Posted by bibu View Post
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.
__________________
fysiks is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 03-29-2011 , 02:20   Re: Using connected players menu
Reply With Quote #4

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

__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 03-29-2011 at 12:22.
ConnorMcLeod is offline
bibu
Veteran Member
Join Date: Sep 2010
Old 04-06-2011 , 16:52   Re: Using connected players menu
Reply With Quote #5

Error: Argument type mismatch (argument 4)

for

new menu = MakePlayerMenu(id, "something", "menu_handler_something", "ch") // ch don't collect bot and hltv
bibu is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 04-06-2011 , 16:56   Re: Using connected players menu
Reply With Quote #6

I'm sure Connor meant to post this line instead:
Code:
new menu = MakePlayerMenu(id, "something", "menu_handler_something", PLMENU_NO_BOTS)
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 04-06-2011 , 17:18   Re: Using connected players menu
Reply With Quote #7

Quote:
Originally Posted by Exolent[jNr] View Post
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.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
bibu
Veteran Member
Join Date: Sep 2010
Old 04-06-2011 , 17:24   Re: Using connected players menu
Reply With Quote #8

I didn't really understand what exactly the defines do, could you tell me that?
bibu is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 04-06-2011 , 17:33   Re: Using connected players menu
Reply With Quote #9

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.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
bibu
Veteran Member
Join Date: Sep 2010
Old 04-10-2011 , 08:28   Re: Using connected players menu
Reply With Quote #10

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)

bibu is offline
Reply



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 14:39.


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