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

Menus


Post New Thread Reply   
 
Thread Tools Display Modes
<VeCo>
Veteran Member
Join Date: Jul 2009
Location: Bulgaria
Old 05-18-2012 , 04:47   Re: Menus
Reply With Quote #11

What function, what value?

Yes, you should destroy the menu since you don't need it after closing it and there's no need to fill the memory with useless things.
__________________
<VeCo> is offline
Bilal Pro
Senior Member
Join Date: Mar 2012
Location: Holland
Old 05-18-2012 , 05:45   Re: Menus
Reply With Quote #12

Quote:
Originally Posted by Liverwiz View Post
He had a bunch of errors in that code. But i got what he was trying to say. That tut that EpicMonkey posted was awesome.
Lol tell me the errors, please.
__________________
  • Point System with rank titles for sale [X] [100% private]
  • VIP Menu for sale [X] [100% private]
  • HnS shop more features for sale [X] [100% private]
Contact: Bilalzaandam1234, on steam if you are interested.
Bilal Pro is offline
mottzi
Veteran Member
Join Date: May 2010
Location: Switzerland
Old 05-18-2012 , 06:50   Re: Menus
Reply With Quote #13

Liverwiz for that you'd use the menu's handler.
__________________
Quote:
#define true ((rand() % 2)? true: false) //Happy debugging suckers
mottzi is offline
Send a message via MSN to mottzi
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 05-18-2012 , 09:10   Re: Menus
Reply With Quote #14

I'm trying to prompt the user of the menu (admin) a list of possible players to do an action to, then the proper value for the action.

It'd be most efficient to grab the answers one after another then use the chosen vars in a function that deals with it. Code....

Code:
switch(selection)
	{
		case 1: // set level
		{
			new menu = menu_create("BKF Admin", "mh_BKFAdmin")
			menu_additem(menu, "Set Player Level", "1", ADMIN_KICK)
			menu_additem(menu, "Set Player Frags", "2", ADMIN_KICK)
			menu_additem(menu, "Give Player Frags", "3", ADMIN_KICK)
			menu_additem(menu, "Prune Vault", "4", ADMIN_BAN)
			menu_additem(menu, "Set CVARs", "5", ADMIN_CFG)

			menu_setprop(menu, MPROP_EXIT, MEXIT_ALL)
			menu_display(id, menu, 0)

			new playerID = mh_playerSelect(id)
			new level = mh_levelMenu(id)
			new frags = setLevel(playerID, level, ADMIN_GRANT)
			new sz_name[34]
			get_user_name(playerID, sz_name, charsmax(sz_name) )
			client_print_color(id, DontChage, "[BKF] ^3%s ^1has been set with %d frags. (level %d)", sz_name, frags, getLevel(playerID) )
		}
That's a snippet from the main menu's choices. It wasn't finished (as you can tell i CPd a lot) because i was called away from my programming nook. But you can see what i want out of it.
__________________
What an elegant solution to a problem that doesn't need solving....

Last edited by Liverwiz; 05-18-2012 at 09:22. Reason: typo
Liverwiz is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 05-18-2012 , 09:19   Re: Menus
Reply With Quote #15

Quote:
Originally Posted by Bilal Pro View Post
Lol tell me the errors, please.
You shouldn't have a callback if you didn't set a callback in the menu
Your switch is incomplete
You should ALWAYS have a default: in your switch. (good practice)
Your case's logic should be INSIDE the brackets
You need to CLOSE brackets after your done
You should destroy a menu before you return PLUGIN_HANDLED

And as i was looking back i realized you did close your brackets. But i didn't delete that because it just shows how much white space and indentation adds to readablity of your code. All things you need to work on.
__________________
What an elegant solution to a problem that doesn't need solving....
Liverwiz is offline
hornet
AMX Mod X Plugin Approver
Join Date: Mar 2010
Location: Australia
Old 05-18-2012 , 09:27   Re: Menus
Reply With Quote #16

D'you mean something like this?

PHP Code:
public MyPlayerMenuid )
{
    new 
iMenu menu_create"\ySelect a player""MyPlayerHandler" );
    
    new 
iPlayers32 ], iNumszName32 ], szInfo];
    
get_playersiPlayersiNum );

    for( new 
iNum ++ )
    {
        
get_user_nameiPlayers], szNamecharsmaxszName ) );
        
num_to_striPlayers], szInfocharsmaxszInfo ) );
        
menu_additemiMenuszNameszInfo);
    }
    
    
menu_displayidiMenu );

And then in your handler you can use the info to refer back to the player's index, and then check if they're still eligible to target for a command?

Btw no need for the double posting - there is an edit button ;)
__________________
Quote:
vBulletin Tip #42: Not much would be accomplished by merging this item with itself.

Last edited by hornet; 05-18-2012 at 10:16.
hornet is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 05-18-2012 , 09:43   Re: Menus
Reply With Quote #17

Quote:
Originally Posted by hornet View Post
And then in your handler you can use the info to refer back to the player's index, and then check if they're still eligible to target for a command?
Oh, so like sending the playerID or something as the data to the handler, which will then get the level from the admin and perform calcs from there? I suppose that could work....we shall see!

Quote:
Originally Posted by hornet View Post
Btw no need for the double posting - there is an edit button ;)
They were different purposes for posting to different people. I felt it'd be best to do it that way. I'm quite familiar with the edit button. I use it when its necessary. For instance: i will edit this to see how it compiles when i'm done. ;)
__________________
What an elegant solution to a problem that doesn't need solving....

Last edited by Liverwiz; 05-18-2012 at 09:43.
Liverwiz is offline
hornet
AMX Mod X Plugin Approver
Join Date: Mar 2010
Location: Australia
Old 05-18-2012 , 09:59   Re: Menus
Reply With Quote #18

Quote:
Originally Posted by Liverwiz View Post
Oh, so like sending the playerID or something as the data to the handler, which will then get the level from the admin and perform calcs from there?
Not the admin level, the player index.
__________________
Quote:
vBulletin Tip #42: Not much would be accomplished by merging this item with itself.
hornet is offline
mottzi
Veteran Member
Join Date: May 2010
Location: Switzerland
Old 05-18-2012 , 10:13   Re: Menus
Reply With Quote #19

Like hornet showed in the upper example, you can send data to the Handler by using the third parameter of menu_additem()
__________________
Quote:
#define true ((rand() % 2)? true: false) //Happy debugging suckers
mottzi is offline
Send a message via MSN to mottzi
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 05-18-2012 , 10:45   Re: Menus
Reply With Quote #20

What do you guys think of this? Its just something i came up with to shorten my code a BIT.
PHP Code:
/*   THIS FUNCTION AUTOMATICALLY SETS THE EXIT (creates a useable menu)
       p_menu is a pointer to the menu that we're going to add the players list to
       source[] is the source menu to keep track of what's going on internally
       itemAccess is the "access" paramater for menu_additem
       getPlayersFlags[] is a string of flags for the get_players command 
       RETURNS: number of players in the list */
mhlp_getPlayerMenu(&p_menusource[], itemAccess=0getPlayersFlags[]="ch")
{
    new 
players[32], plyrCnt
    
new sz_name[32], sz_info[8]
    
get_players(playersplyrCntgetPlayersFlags)
    
    for(new 
i=0i<plyrCnt1++)
    {
        
get_user_name(players[i], sz_namecharsmax(sz_name) )
        
format(sz_infocharsmax(sz_info), "%s %d"sourceplayers[i])
        
menu_additem(p_menusz_namesz_infoitemAccess)
    }
    
    
menu_setprop(p_menuMPROP_EXITMEXIT_ALL)
    return 
playCnt

and that is called like this....
Code:
new lvlMn = menu_create("BKF Set Player Level", "mh_setLevel")
mhlp_getPlayerMenu(lvlMn, "I", ADMIN_ALL, "ch")
menu_display(id, lvlMn, 0)
Still writing it.....but i want to make sure its sound before i continue
__________________
What an elegant solution to a problem that doesn't need solving....
Liverwiz 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 10:48.


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