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

Menu with different options if conditions are met


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Gasior
Member
Join Date: Mar 2012
Old 02-08-2017 , 14:39   Menu with different options if conditions are met
Reply With Quote #1

Hi Guys,

So just to explain, what I am trying to do is have a menu of weapons with different skins available for players if they have purchased it.

Problem I have is that if I select Carbon from the menu but I don't have Burner available then I will receive model Burner rather than Carbon. Simply because if I don't have option Burner than option Carbon is first and responds to case 0. How do I show things in the menu but don't let players choose it unless my condition is met?

I know I am confusing but I cannot explain it clearer. Please ask questions, I will answer all of them for help .

Code:
 public display_pistolet(id)  
{ 
	new g_Menu = menu_create("Wybierz swoj \rGLOCK!", "glock_handle");
    
	if(Burner1[id] > 0){
	menu_additem(g_Menu, "\wBurner^n" ); 
	}
	if(Carbon1[id] > 0){
	menu_additem(g_Menu, "\wCarbon", "", 0);
	}
	if(Crimson1[id] > 0){
	menu_additem(g_Menu, "\wCrimson", "", 0);
	}
	if(Gradient1[id] > 0){
	menu_additem(g_Menu, "\wGradient", "", 0);
	}
	if(Krolewski1[id] > 0){
	menu_additem(g_Menu, "\wKrolewksi", "", 0);
	}
	menu_additem(g_Menu, "\wStandardowy\w^n" ); 
	menu_addtext(g_Menu, "Odwiedz nas na \rProjektSpark.pl^n" , 0 ); 

	menu_setprop(g_Menu, MPROP_EXIT, MEXIT_ALL);
	menu_setprop(g_Menu, MPROP_BACKNAME, "Wroc");
	menu_setprop(g_Menu, MPROP_NEXTNAME, "Nastepna Strona");
	menu_setprop(g_Menu, MPROP_EXITNAME, "Wyjdz");
	menu_setprop(g_Menu, MPROP_NOCOLORS, 1);

	menu_display(id, g_Menu, 0);

	return PLUGIN_HANDLED;
} 

public glock_handle(id, menu, item) 
{ 
	if(is_user_connected( id ))
	if(item == MENU_EXIT)
	{
		menu_cancel(id);
		return PLUGIN_HANDLED;
	}

	new command[6], name[64], access, callback;

	menu_item_getinfo(menu, item, access, command, sizeof command - 1, name, sizeof name - 1, callback);

	switch(item)
	{
		case 0: SetGlock( id , Glocks:Burner );
		case 1: SetGlock( id , Glocks:Carbon );
		case 2: SetGlock( id , Glocks:Crimson );
		case 3: SetGlock( id , Glocks:Gradient );
		case 4: SetGlock( id , Glocks:Krolewski );
		case 5: SetGlock( id , Glocks:Standardowy );
	}
	menu_destroy(menu);
	return PLUGIN_HANDLED;
}
Gasior is offline
Gasior
Member
Join Date: Mar 2012
Old 02-08-2017 , 14:46   Re: Menu with different options if conditions are met
Reply With Quote #2

I have realised that
Code:
	if(Burner1[id] > 0){
	menu_additem(g_Menu, "\wBurner", "", 0 ); 
	}
	else{
	menu_additem(g_Menu, "\wBurner", "", ADMIN_IMMUNITY ); 
	}
Might be the solution but I'm sure there must be something more logical.

Last edited by Gasior; 02-08-2017 at 14:47.
Gasior is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 02-08-2017 , 21:01   Re: Menu with different options if conditions are met
Reply With Quote #3

The solution is to use the menu item's "info" to uniquely identify the items in the menu. With this method, shown below, when you choose option 5, only option 5 will be executed.

PHP Code:
// Menu function

    
menu_additem(g_Menu"Option 1""1")
    
menu_additem(g_Menu"Option 2""2")
    
menu_additem(g_Menu"Option 3""3")
    
menu_additem(g_Menu"Option 5""5")
    
    
//...
    
// Handler function
    
    
new iAccessszInfo[32], szName[32], callback
    menu_item_getinfo
(menuitemiAccessszInfocharsmax(szInfo), szNamecharsmax(szName), callback)
    
    new 
iOption str_to_num(szInfo)
    
    switch(
iOption)
    {
        case 
1:
        {
            
// Option 1
        
}
        case 
2:
        {
            
// Option 2
        
}
        case 
3:
        {
            
// Option 3
        
}
        case 
4:
        {
            
// Option 4
        
}
        case 
5:
        {
            
// Option 5
        
}
    } 
__________________

Last edited by fysiks; 02-08-2017 at 21:03.
fysiks is offline
Gasior
Member
Join Date: Mar 2012
Old 02-09-2017 , 05:24   Re: Menu with different options if conditions are met
Reply With Quote #4

That's brilliant, do you also happen to know if there is a chance to show the option in the menu but don't let the people use it unless they met this criteria? Otherwise the menu is blank and people may not know what's the matter.
Gasior is offline
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 02-09-2017 , 10:53   Re: Menu with different options if conditions are met
Reply With Quote #5

you can create a menu item callback and return ITEM_DISABLED there when needed

Code:
//menu function new pCallback = menu_makecallback("handle_callback") menu_additem(menu, "name", "info", 0, pCallback) //callback function public handle_callback(id, menu, item) {    new iAccess, szInfo[32], szName[32], callback    menu_item_getinfo(menu, item, iAccess, szInfo, charsmax(szInfo), szName, charsmax(szName), callback)        new iOption = str_to_num(szInfo)    if (iOption != whatever_value) //check if player can use this item       return ITEM_DISABLED }

Last edited by jimaway; 02-09-2017 at 11:01.
jimaway is offline
Gasior
Member
Join Date: Mar 2012
Old 02-09-2017 , 16:30   Re: Menu with different options if conditions are met
Reply With Quote #6

Brilliant! That's what I was looking for. Thanks!
Gasior 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 05:43.


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