Raised This Month: $ Target: $400
 0% 

Extra Button in New Style Menu


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
snezzsp
BANNED
Join Date: Apr 2015
Location: GB
Old 01-05-2017 , 17:13   Extra Button in New Style Menu
Reply With Quote #1

I would like to add a button on a new style menu, that stay in all pages of the menu, the menu is of the players of the servers, and if there are 2 pages and I pass the page, the button would stay there with a custom function. Like the ban menu from the amxmodmenu, but custom function. Sorry for my bad English

PHP Code:
#include <amxmodx>
#include <amxmisc>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"

new g_maxplayers;
new 
i;
new 
name[33];


public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_clcmd("say /menu""players");
    
g_maxplayers get_maxplayers();
}

public 
players(id)
{
    new 
menu menu_create("PLAYERS :""hd_menu");
    for(
i=1<= g_maxplayersi++)
    {
        if(
is_user_connected(i)){
            
get_user_name(iname[i], 31);
            new 
message[100];
            
format(messagecharsmax(mensaje), "%s"name[i]);
            
menu_additem(menumensaje);
        }
    }
    
menu_setprop(menuMPROP_EXITMEXIT_NEVER);
    
menu_display(idmenu0)
}

public 
hd_menu(idmenuitem)
{
    if(
item == MENU_EXIT){
        
menu_destroy(menu);
        return 
PLUGIN_HANDLED;
    }
    new 
iData[6];
    new 
iAccess;
    new 
iCallback;
    new 
iName[64];
    
menu_item_getinfo(menuitemiAccessiData5iName63iCallback);
    
client_print(id,print_chat,"You have selected %s",iName);
    return 
PLUGIN_CONTINUE

snezzsp is offline
Send a message via ICQ to snezzsp Send a message via AIM to snezzsp Send a message via Yahoo to snezzsp Send a message via Skype™ to snezzsp
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 01-05-2017 , 17:24   Re: Extra Button in New Style Menu
Reply With Quote #2

First of all, use get_players() instead of a loop. If you want to learn more about it: https://forums.alliedmods.net/showthread.php?t=208331

Secondly, what is this?

PHP Code:
get_user_name(iname[i], 31
The name[ i ] never should be like this, just the string name is needed, and use charsmax() instead of the array's size -1 ( the charsmax already does it ).

Here's the code:

PHP Code:
#include <amxmodx> 
#include <amxmisc> 

#define PLUGIN "New Plug-In" 
#define VERSION "1.0" 
#define AUTHOR "author" 

public plugin_init() 

    
register_plugin(PLUGINVERSIONAUTHOR
    
    
register_clcmd("say /menu""players"


public 
players(id

    new 
menu menu_create("Players list:""hd_menu"
    
    new 
Players[32],iPlayersNum,PlayerIDPlayersName[32],FormatMsg[100]
    
get_players(Players,iPlayersNum,"ch")
    for(new 
i<= iPlayersNumi++) 
    { 
        
PlayerID Players[i]
        
get_user_name(PlayerIDPlayersNamecharsmax(PlayersName))  
        
format(FormatMsgcharsmax(FormatMsg), "%s"name
        
menu_additem(menuFormatMsg
    } 
    
menu_display(idmenu0


public 
hd_menu(idmenuitem

    if(
item == MENU_EXIT)
    { 
        
menu_destroy(menu
        return 
PLUGIN_HANDLED 
    

    new 
iData[6], iAccessiCallbackiName[64
    
menu_item_getinfo(menuitemiAccessiData5iName63iCallback

    new 
userid str_to_numszData );
    new 
player find_player"k"userid )

    new 
PlayerSelectedName[32]
    
get_user_name(player,PlayerSelectedName,charsmax(PlayerSelectedName))
    
    
client_print(id,print_chat,"You have selected %s",PlayerSelectedName
    return 
PLUGIN_CONTINUE 

Just a small help about how to make a menu - https://forums.alliedmods.net/showthread.php?t=46364
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo

Last edited by EFFx; 01-05-2017 at 17:28.
EFFx is offline
pupdebox
Senior Member
Join Date: Feb 2016
Location: Wakanda
Old 01-05-2017 , 18:43   Re: Extra Button in New Style Menu
Reply With Quote #3

Quote:
Originally Posted by EFFx View Post
First of all, use get_players() instead of a loop. If you want to learn more about it: https://forums.alliedmods.net/showthread.php?t=208331
WHY? I'm of the opinion that using 1 loop is better instead of using double loop(get_players + loop for menu_additem)
__________________
Quote:
Originally Posted by wickedd View Post
Make me or STFU boy

Last edited by pupdebox; 01-05-2017 at 18:45.
pupdebox is offline
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 01-05-2017 , 18:49   Re: Extra Button in New Style Menu
Reply With Quote #4

Did you read all the replies ?

https://forums.alliedmods.net/showpo...10&postcount=3

There's no problem using two loops, the problem is what the loop does.
The loop for all players call is_user_connected() 32 times, if have 5 players on the server, he still calling 32 times. With the get_players, will only 5. So, its better for the server.
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo

Last edited by EFFx; 01-05-2017 at 18:50.
EFFx is offline
pupdebox
Senior Member
Join Date: Feb 2016
Location: Wakanda
Old 01-05-2017 , 18:58   Re: Extra Button in New Style Menu
Reply With Quote #5

If you have full server it will loop 32 times + using get_players will create a loop. You are right if the server is close to empty. I don't think using 32 loop is a bad habit. Using 32 loop wouldn't effect the server that much in addition, it's easy to filter specific players with that loop.
__________________
Quote:
Originally Posted by wickedd View Post
Make me or STFU boy
pupdebox is offline
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 01-05-2017 , 19:00   Re: Extra Button in New Style Menu
Reply With Quote #6

Yes, the damage will not be much. I'm talking what I learn, what scripters better than me said. If you want to post your plugin here, they will told you to use get_players instead of a loop.
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo

Last edited by EFFx; 01-05-2017 at 19:00.
EFFx is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-05-2017 , 19:37   Re: Extra Button in New Style Menu
Reply With Quote #7

The ban menu is created using the original menu method which is much much more flexible than the "new" menu method but the code is more complicated and is harder to understand (especially for newbies).

To do it with the new menu system, you would need to add a menu item after every 6 players (this assumes that pagination is set to 7). This menu item's data would differentiate it from the players. So, in your handler, you first check to see if the item's data is this special item (after checking for exit). If yes, do what you want otherwise you can assume that a player was chosen and run the original player-based code.
__________________
fysiks is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 01-07-2017 , 08:07   Re: Extra Button in New Style Menu
Reply With Quote #8

Quote:
Originally Posted by pupdebox View Post
WHY? I'm of the opinion that using 1 loop is better instead of using double loop(get_players + loop for menu_additem)
It's more efficient. Simple as that.
One could also argue the readability is better instead of nested if statements.
You could just as well filter players in the second loop, most likely with more efficiency.

https://forums.alliedmods.net/showpo...9&postcount=12
__________________
Black Rose is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 01-07-2017 , 08:42   Re: Extra Button in New Style Menu
Reply With Quote #9

Quote:
Originally Posted by pupdebox View Post
WHY? I'm of the opinion that using 1 loop is better instead of using double loop(get_players + loop for menu_additem)
Fun fact: It looks like that from time to time someone that hates get_players must appear and he won't ever accept that in most of cases it's better than looping manually each possible player slot.
__________________

Last edited by HamletEagle; 01-07-2017 at 08:43.
HamletEagle 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 08:35.


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