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

Solved Combine the menus


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Supremache
Veteran Member
Join Date: Sep 2019
Location: Egypt
Old 05-22-2021 , 14:40   Combine the menus
Reply With Quote #1

Hi There,
I tried to combining the menus together, but my code doesn't work what is the wrong ?

Code:
enum _:eMenuType {         CHECK_RANK,     RESET_RANK,     MANAGE_RANK }; public PlayerRank(id, iLevel, iCid) {     if(!cmd_access(id, iLevel, iCid, 1))     {         return PLUGIN_HANDLED     }     new iPlayers[MAX_PLAYERS], iPnum, szUserID[32], szTitle[128], iMenu         switch ( iMenu )     {         case CHECK_RANK:         {             MenuTitle("\yRank System: \rXP List")         }         case RESET_RANK:         {             MenuTitle("\yRank System: \rReset Data")         }         case MANAGE_RANK:         {             MenuTitle("\yRank System: \rManage Players")         }     }         iMenu = menu_create(szTitle, "Handler")     get_players(iPlayers, iPnum, "ch"); SortCustom1D(iPlayers, iPnum, "sort_players_by_xp")         for(new szItem[1024], iPlayer, i; i < iPnum; i++)     {         iPlayer = iPlayers[i]                 MenuInfo("\d[%i XP] \w%s \r[\yLevel %i: %s\r]")         formatex( szUserID, charsmax( szUserID ), "%d", get_user_userid(iPlayer))         menu_additem(iMenu, szItem, szUserID)     }         menu_setprop(iMenu, MPROP_BACKNAME, "Previous page")     menu_setprop(iMenu, MPROP_NEXTNAME, "Next page")     menu_setprop(iMenu, MPROP_EXITNAME, "\rClose")     menu_display(id, iMenu)     return PLUGIN_HANDLED } public Handler(id, iMenu, iItem) {     new iAccess, iCallback, iData[6],iName[64];         menu_item_getinfo(iMenu, iItem, iAccess, iData, charsmax(iData), iName, charsmax(iName), iCallback);         new iPlayer = str_to_num(iData);         switch ( iMenu )     {         case CHECK_RANK:         {             return PLUGIN_HANDLED         }         case RESET_RANK:         {             if(get_user_flags(id) & eResetDataFlag)             {                 ResetPlayerRank(id, iPlayer);                 Print(id, "[Rs] You don't have access.");             }         }         case MANAGE_RANK:         {             if(get_user_flags(id) & eManagePlayer)             {                 ChoosePlayerRank(id, iPlayer);                 Print(id, "[Rs] You don't have access.");             }         }     }     menu_destroy(iMenu)     return PLUGIN_HANDLED }
__________________
Youtube.com/Supremache

Bank System [Nvault - SQL Support]
VIP System
  • If you think it's that simple, then do it yourself.

Last edited by Supremache; 05-23-2021 at 13:40.
Supremache is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-22-2021 , 14:54   Re: Combine the menus
Reply With Quote #2

The first thing I notice is that you're using the variable iMenu for two entirely different purposes at the same time which is not possible. Your menu type and the menu pointer used with the menu_*() functions cannot use the same variable.

However, the first question that you should ask yourself is, why would you combine these menus if you're not keeping their functionality completely separate (via the menu type) anyways? As it is, without any other reason, it looks like you shouldn't even attempt combining menus like this. If you have some reason to do it, you should explain because that will help us help you get to the best result.

Also, MenuTitle() is not an AMX Mod X function, what does it do?
__________________

Last edited by fysiks; 05-22-2021 at 14:56.
fysiks is offline
Supremache
Veteran Member
Join Date: Sep 2019
Location: Egypt
Old 05-22-2021 , 15:07   Re: Combine the menus
Reply With Quote #3

Quote:
Originally Posted by fysiks View Post
The first thing I notice is that you're using the variable iMenu for two entirely different purposes at the same time which is not possible. Your menu type and the menu pointer used with the menu_*() functions cannot use the same variable.

However, the first question that you should ask yourself is, why would you combine these menus if you're not keeping their functionality completely separate (via the menu type) anyways? As it is, without any other reason, it looks like you shouldn't even attempt combining menus like this. If you have some reason to do it, you should explain because that will help us help you get to the best result.
I created other variable but it didn't work.

There's three commands on my plugin using the same style of menu for getting online players why i add same menu three times for three commands and there's way to make one menu for these commands.


Quote:
Originally Posted by fysiks View Post
Also, MenuTitle() is not an AMX Mod X function, what does it do?
I did defines for formatex:
Code:
#define MenuInfo(%1) formatex(szItem, charsmax(szItem), %1, g_iPlayerXP[iPlayer], szPlayerName[iPlayer], g_iPlayerLevel[iPlayer], g_mPlayerData[ g_iPlayerLevel[iPlayer]][m_szRankName]); #define MenuTitle(%1)  formatex(szTitle,charsmax(szTitle), %1)
__________________
Youtube.com/Supremache

Bank System [Nvault - SQL Support]
VIP System
  • If you think it's that simple, then do it yourself.

Last edited by Supremache; 05-22-2021 at 15:10.
Supremache is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-22-2021 , 17:13   Re: Combine the menus
Reply With Quote #4

You have to set and keep track of the the menu type for all players (e.g. in a global variable) which you are not even attempting to do. So, currently the handler doesn't know how to handle a menu item selection. Also, you shouldn't be checking flags in the handler, check them before you show the menu and don't show the menu at all if they don't have access.

Finally, you're printing a message saying "you don't have access" even though you just performed the action.
__________________
fysiks is offline
Supremache
Veteran Member
Join Date: Sep 2019
Location: Egypt
Old 05-22-2021 , 18:25   Re: Combine the menus
Reply With Quote #5

Quote:
Originally Posted by fysiks View Post
you shouldn't be checking flags in the handler, check them before you show the menu and don't show the menu at all if they don't have access..
Oops, i will fix that !

Quote:
Originally Posted by fysiks View Post
You have to set and keep track of the the menu type for all players (e.g. in a global variable) which you are not even attempting to do. So, currently the handler doesn't know how to handle a menu item selection.

Finally, you're printing a message saying "you don't have access" even though you just performed the action.
I don't want to do this, an example for what i want to do is adding three commands for one menu:

Code:
 Calling same function
    register_clcmd( "say /manage", "PlayerRank", ADMIN_RCON);     register_clcmd( "say /rr", "PlayerRank", ADMIN_RCON );      register_clcmd( "say /xplist", "PlayerRank", ADMIN_ALL ); public PlayerRank(id, iLevel, iCid) {
 Check who can use that command
    if(!cmd_access(id, iLevel, iCid, 1))     {         return PLUGIN_HANDLED     }     new iPlayers[MAX_PLAYERS], iPnum, szUserID[32], szTitle[128], iMenu    
 Check which command did player chose
 if user use "/manage, /rr ,/xplist" command will open the same menu and calling the same handler
    switch ( iMenu )     {         case CHECK_RANK:         {             MenuTitle("\yRank System: \rXP List")         }         case RESET_RANK:         {             MenuTitle("\yRank System: \rReset Data")         }         case MANAGE_RANK:         {             MenuTitle("\yRank System: \rManage Players")         }     }         iMenu = menu_create(szTitle, "Handler")     get_players(iPlayers, iPnum, "ch"); SortCustom1D(iPlayers, iPnum, "sort_players_by_xp")         for(new szItem[1024], iPlayer, i; i < iPnum; i++)     {         iPlayer = iPlayers[i]
 EX: [ Player XP ] Player Name [ LvL , Rank ]
        MenuInfo("\d[%i XP] \w%s \r[\yLevel %i: %s\r]")         formatex( szUserID, charsmax( szUserID ), "%d", get_user_userid(iPlayer))         menu_additem(iMenu, szItem, szUserID)     }         menu_setprop(iMenu, MPROP_BACKNAME, "Previous page")     menu_setprop(iMenu, MPROP_NEXTNAME, "Next page")     menu_setprop(iMenu, MPROP_EXITNAME, "\rClose")     menu_display(id, iMenu)     return PLUGIN_HANDLED } public Handler(id, iMenu, iItem) {     new iAccess, iCallback, iData[6],iName[64];         menu_item_getinfo(iMenu, iItem, iAccess, iData, charsmax(iData), iName, charsmax(iName), iCallback);         new iPlayer = str_to_num(iData);         switch ( iMenuMode )     {         case CHECK_RANK:         {
 If user use /xplist command and choose player will close the menu
            return PLUGIN_HANDLED         }         case RESET_RANK:         {
 If user use  /rr command and choose player will reset his data
            ResetPlayerRank(id, iPlayer);         }         case MANAGE_RANK:         {
 If user use /manage command and choose player will open new menu have all ranks and select which rank want to change that player to
            ManagePlayerRank(id, iPlayer);         }     }     menu_destroy(iMenu)     return PLUGIN_HANDLED }
__________________
Youtube.com/Supremache

Bank System [Nvault - SQL Support]
VIP System
  • If you think it's that simple, then do it yourself.

Last edited by Supremache; 05-22-2021 at 18:35.
Supremache is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-22-2021 , 18:35   Re: Combine the menus
Reply With Quote #6

Quote:
Originally Posted by Supremache View Post
I don't want to do this
Why? If you have a better way that works then you should do that. If you "want" (even though it's unnecessary) to have the same handler, you have to have some deterministic, reliable method for indicating what command to run in the handler. Otherwise, use three different handlers, one for each menu type. I can't think of any good reason to use the same handler ("using less code" and "because I want to" are not a good reasons).
__________________
fysiks is offline
Supremache
Veteran Member
Join Date: Sep 2019
Location: Egypt
Old 05-22-2021 , 18:48   Re: Combine the menus
Reply With Quote #7

I want to do this because i see this idea is better for being easy for who want to edit it until i do ini file.
If there some one doesn't have any expriance on scripting and want to edit it will not search between menus, which menu for this command plus fixing hard codding.

I saw this idea made before on plugin but i didn't found that plugin, plz if you have any idea how to do this tell me!
__________________
Youtube.com/Supremache

Bank System [Nvault - SQL Support]
VIP System
  • If you think it's that simple, then do it yourself.

Last edited by Supremache; 05-22-2021 at 19:12.
Supremache is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-23-2021 , 04:29   Re: Combine the menus
Reply With Quote #8

If you wanted to make it "easy" for beginners (not a good goal) then you would make three completely separate menus. Just implement something that works (you've been given several options) and then you can modify it later.

Even if it is possible to do what you want to do (still not really sure what you're talking about) it will most likely be more complex anyways.
__________________
fysiks is offline
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 05-23-2021 , 07:36   Re: Combine the menus
Reply With Quote #9

pass your menu type to the handler in the item info field along with the userid
jimaway is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 05-23-2021 , 08:16   Re: Combine the menus
Reply With Quote #10

Destroy the menu right after retrieving the info there is no need to keep it alive.

Also dont be shy to post the whole code no ones gonna steal anything its not that well coded either.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 05-23-2021 at 08:18.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
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 12:12.


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