Raised This Month: $12 Target: $400
 3% 

Creating Menu


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
PurposeLessx
Senior Member
Join Date: Jun 2017
Old 05-31-2018 , 05:48   Creating Menu
Reply With Quote #1

How can I create perfectly a menu who uses fast for server?
Should I use "formatex" ? and also how should "menu_handler" be like?
Thanks for helping.
PurposeLessx is offline
PurposeLessx
Senior Member
Join Date: Jun 2017
Old 05-31-2018 , 05:52   Re: Creating Menu
Reply With Quote #2

Which one is the best for server?

PHP Code:
    //First One
    
new menu menu_create("CTMenu""ctmenu_handler");

    
menu_additem(menu"""1");
    
menu_additem(menu"""1");
    
menu_additem(menu"""1");

    
/** *************************** */

    //Second One
    
static Menu[64];
    
formatex(Menucharsmax(Menu), "CTMenu");
    new 
menu menu_create(Menu"ctmenu_handler");

    
formatex(Menucharsmax(Menu), "");
    
menu_additem(Menu"1");

    
formatex(Menucharsmax(Menu), "");
    
menu_additem(Menu"2");

    
formatex(Menucharsmax(Menu), "");
    
menu_additem(Menu"3");
}

public 
ctmenu_handler(idmenuitem)
{

    
//First One
    
static data[6], name[32], accesscallback;
    
menu_item_getinfo(menuitemaccessdatacharsmax(data), namecharsmax(name), callback);
    switch(
str_to_num(data))
    {
        
        
        
    
/** *************************** */

    //Second One
    
switch(item)
    { 

And also +++;

Which one is the best to use? (FAST)

PHP Code:
    new players[32], inum;
    static 
Uid;
    
get_players(playersinum"ae""CT");
    for(new 
0inumi++) {
        
//do something;
    
}
    
    
/**************************************/
    
    #include <reapi>

    
for(new 1<= MAX_CLIENTSi++) {
        
//dosomething;
    


Last edited by PurposeLessx; 05-31-2018 at 06:20.
PurposeLessx is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 05-31-2018 , 11:04   Re: Creating Menu
Reply With Quote #3

1. Since only two menu exists in amxx, it will depend on what you want to do, but I think no one of both cause lag in server.


2. You only should use formatex if you want to set multilingual support or one variable as an string.

Code:
new szBuffer[32]; new iNumber = 100; formatex(szBuffer, charsmax(szBuffer), "new iNumber = %d", iNumber); menu_additem(hMenu, szBuffer, ...); formatex(szBuffer, charsmax(szBuffer), "%L", pPlayer, "MENU_INUMBER", iNumber); menu_additem(hMenu, szBuffer, ...);

Code:
[en]
MENU_INUMBER = new iNumber = %d

3. menu_handler will be like:

Code:
new hMenu = menu_create("Title", "menuHandle"); ... // pPlayer = player index // hMenu = menu index // iItem = selected item index public menuHandle(pPlayer, hMenu, iItem) {     }


4. Loop through players should be like this

Code:
const MAXPLAYERS = 32; ... new stPlayers[MAXPLAYERS], iPlayersCount, pPlayer; get_players(stPlayers, iPlayersCount, "ae", "CT"); for (new i = 0; i < iPlayersCount; i++) {     pPlayer = stPlayers[i];     // Do something with pPlayer. }

More info about newmenus: https://forums.alliedmods.net/showthread.php?t=46364
__________________









Last edited by CrazY.; 05-31-2018 at 11:04.
CrazY. is offline
NiHiLaNTh
Way Past Expiration
Join Date: May 2009
Location: Latvia
Old 05-31-2018 , 14:14   Re: Creating Menu
Reply With Quote #4

Consider creating static menus.
__________________

NiHiLaNTh is offline
Send a message via Skype™ to NiHiLaNTh
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-31-2018 , 22:19   Re: Creating Menu
Reply With Quote #5

Quote:
Originally Posted by PurposeLessx View Post
How can I create perfectly a menu who uses fast for server?
Should I use "formatex" ? and also how should "menu_handler" be like?
Thanks for helping.
Use the simplest version of the menu system which is in the tutorial here.

Use format() when you need to format a string. formatex() is an optimization for when the output variable is not also used as an input.

Always use get_players() when you need to loop through players.
__________________
fysiks 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 08:27.


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