Results 1 to 10 of 10

Thread: Perform action when menu is open but no button is pressed

  1. #1
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts

    Perform action when menu is open but no button is pressed

    HI all.

    I would like to know how to do an action of a certain menu is opened but no button is pressed.
    Code:
    	for(;;)
    	{	
    		self waittill("menuresponse", menu, response);
    This wait till a button is pressed. I want to do it the same with a waittill if thats possible. Because the other solution should be a normal loop. DOnt know if thats buggy?

  2. #2
    Global Mossaderator Mitch's Avatar
    Join Date
    Nov 2012
    Posts
    654
    Thanks
    204
    Thanked 450 Times in 305 Posts
    PHP Code:
    menuDef
    {
            
    name            "chose_medpack"
            
    fullscreen        0
            rect            0 0 640 480
            focuscolor        1 1 1 1
            disablecolor    0 0 0 0
             style            WINDOW_STYLE_EMPTY

            onOpen
            
    {
                
    scriptMenuResponse "open";
            }
            
    onClose
            
    {
                
    scriptMenuResponse "close";
            }
            
    onEsc 
            
    {
                
    close chose_medpack;
            } 

  3. The Following User Says Thank You to Mitch For This Useful Post:

    Ni3ls (16th November 2014)

  4. #3
    Brigadier General
    Join Date
    Oct 2012
    Posts
    994
    Thanks
    20
    Thanked 588 Times in 388 Posts
    Quote Originally Posted by Ni3ls View Post
    HI all.

    I would like to know how to do an action of a certain menu is opened but no button is pressed.
    Code:
    	for(;;)
    	{	
    		self waittill("menuresponse", menu, response);
    This wait till a button is pressed. I want to do it the same with a waittill if thats possible. Because the other solution should be a normal loop. DOnt know if thats buggy?
    The "menuresponse" notification tells you if the menu is open without any further action being necessary because part of its parameters is the menu that has just opened. So, all you have to do is:

    PHP Code:
        for(;;)
        {    
            
    self waittill"menuresponse"menuresponse );
            
            if( 
    menu == "themenuyouwanttomonitor" )
            {
                
    self dostuff();
            }
        } 

  5. #4
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts
    Quote Originally Posted by Tally View Post
    The "menuresponse" notification tells you if the menu is open without any further action being necessary because part of its parameters is the menu that has just opened. So, all you have to do is:

    PHP Code:
        for(;;)
        {    
            
    self waittill"menuresponse"menuresponse );
            
            if( 
    menu == "themenuyouwanttomonitor" )
            {
                
    self dostuff();
            }
        } 
    `No this is not working. It waits for a scriptresponse ( button action)

  6. #5
    Sergeant maxdamage99's Avatar
    Join Date
    Aug 2014
    Location
    Russia
    Posts
    458
    Thanks
    79
    Thanked 122 Times in 101 Posts
    May be worth a try:
    PHP Code:
    ===============================
    for(;
    {
    self waittill( "menuresponse", menu, response );

    if(menu == "themenuyouwanttomonitor" && response == "openmenu")
    {
    self dostuff();
    }
    }
    =====================

  7. #6
    Brigadier General
    Join Date
    Oct 2012
    Posts
    994
    Thanks
    20
    Thanked 588 Times in 388 Posts
    You could send a scriptmenu response of "open" + the menu it is being sent from, and then parse it from there:

    PHP Code:
        onOpen
        
    {
            
    scriptMenuResponse "mymenu:open";
        }
        
    onClose
        
    {
            
    scriptMenuResponse "mymenu:close";
        }
        
    onEsc 
        
    {
            
    scriptMenuResponse "mymenu:escape";
        } 
            
            
        for( ;; )
        {    
            
    self waittill"menuresponse"menuresponse );
            
            if( 
    getSubStrresponse0) == "mymenu" )
            {
                
    //get proper response
                
    whathappened strTokresponse":" );
                
                if( 
    whathappened[1] == "open" )
                    
    self doOpenstuff();
                else if( 
    whathappened[1] == "close" )
                    
    self doClosestuff();
                else
                    
    self doEscapestuff();
            }
        } 

  8. #7
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    Even onopen sends the menu to a menuresponse listener anyway, so there is no need to hack around it like that.

    Seems like OP didnt adequately test the code posted here, did no debugging at all and just relies on the community to send him a bit-perfect script to copy-paste into his mod.

    Edit: and asid from that, the only way you can open a non-quickmessage menu is by using openmenu() in script, which should allow for the server to have a really good idea (read: know) what menu is open.
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

  9. #8
    Brigadier General
    Join Date
    Oct 2012
    Posts
    994
    Thanks
    20
    Thanked 588 Times in 388 Posts
    Quote Originally Posted by IzNoGoD View Post
    Even onopen sends the menu to a menuresponse listener anyway, so there is no need to hack around it like that.

    Seems like OP didnt adequately test the code posted here, did no debugging at all and just relies on the community to send him a bit-perfect script to copy-paste into his mod.

    Edit: and asid from that, the only way you can open a non-quickmessage menu is by using openmenu() in script, which should allow for the server to have a really good idea (read: know) what menu is open.
    I agree with you about his testing. I knew the menu sent a response without any further work needing doing. However, the bit about the only way to open a menu is by using openmenu() - this may be true at the script language level, but in the menu language level, you can open a menu with a menu or command (open [nameofmenu). If Ni3ls is working with a COD4-type system, where sub-menus open all the time, it is difficult to know what menu is open because they DO NOT send a notification. Let's take an example:

    Code:
    	#define LOCAL_PRIMARY_POPUP_GROUP( suffix, pos, y_offset )\
    		menuDef\
    		{\
    			IMPROVED_POPUP_SETUP_ONOPEN( "ocd_popup_"suffix"_cac_primary", 5, (CHOICE_X( pos )-2), (CHOICE_Y( pos )-y_offset+24), ;, execnow "set ui_inside_popup weapon_class; set ui_show_preview 1; set ui_weapon_class_selected @Primary Weapon";, 1 )\
    			onClose{	execnow "set ui_show_preview 0; set ui_primary_highlighted 0; set ui_attachment_highlighted 0";	}\
    			LOCAL_WEAPON_CLASS( 1, "assault", "@MPUI_ASSAULT_RIFLES", suffix )\
    			LOCAL_WEAPON_CLASS( 2, "SMG", "@MPUI_SUB_MACHINE_GUNS", suffix )\
    			LOCAL_WEAPON_CLASS( 3, "LMG", "@MPUI_LIGHT_MACHINE_GUNS", suffix )\
    			LOCAL_WEAPON_CLASS( 4, "shotgun", "@MPUI_SHOTGUNS", suffix )\
    			LOCAL_WEAPON_CLASS( 5, "sniper", "@MPUI_SNIPER_RIFLES", suffix )\
    		}
    	
    	LOCAL_PRIMARY_POPUP_GROUP( "1", 1, 4 )
    	LOCAL_PRIMARY_POPUP_GROUP( "2", 3, 0 )
    When you open any of those menus, there is no notification sent that can be monitored at the script level. So, you would have to put one in using one of the menu language's open/close/escape notifiers. Like this:

    Code:
    	#define LOCAL_PRIMARY_POPUP_GROUP( suffix, pos, y_offset )\
    		menuDef\
    		{\
    			IMPROVED_POPUP_SETUP_ONOPEN( "ocd_popup_"suffix"_cac_primary", 5, (CHOICE_X( pos )-2), (CHOICE_Y( pos )-y_offset+24), ;, execnow "set ui_inside_popup weapon_class; set ui_show_preview 1; set ui_weapon_class_selected @Primary Weapon";, 1 )\
    			onClose{	execnow "set ui_show_preview 0; set ui_primary_highlighted 0; set ui_attachment_highlighted 0";	}\
    			onOpen{ Scriptmenureponse "ocd_popup_"suffix"_cac_primary:open" }\
    			LOCAL_WEAPON_CLASS( 1, "assault", "@MPUI_ASSAULT_RIFLES", suffix )\
    			LOCAL_WEAPON_CLASS( 2, "SMG", "@MPUI_SUB_MACHINE_GUNS", suffix )\
    			LOCAL_WEAPON_CLASS( 3, "LMG", "@MPUI_LIGHT_MACHINE_GUNS", suffix )\
    			LOCAL_WEAPON_CLASS( 4, "shotgun", "@MPUI_SHOTGUNS", suffix )\
    			LOCAL_WEAPON_CLASS( 5, "sniper", "@MPUI_SNIPER_RIFLES", suffix )\
    		}
    	
    	LOCAL_PRIMARY_POPUP_GROUP( "1", 1, 4 )
    	LOCAL_PRIMARY_POPUP_GROUP( "2", 3, 0 )
    That follows the example I posted above and you can parse it for the menu that opens and the menu operation - in this case "open".

  10. #9
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts
    Before accusing me of something, I did test it.
    Code:
    				self openMenu("spawn");
    				scriptMainMenu = "spawn";
    Thats how I open the menu and it only responds to some action if I pressed something inside that menu. I added some debug iprints and it didnt show. Even closing the menu there didnt work.
    Code:
    		if(menu == "spawn")
    		{
    	          wait 5;
                      self closeMenu();
    		  self closeInGameMenu();
                    }
    The fix of Mitch did the job for me

  11. #10
    Brigadier General
    Join Date
    Oct 2012
    Posts
    994
    Thanks
    20
    Thanked 588 Times in 388 Posts
    Quote Originally Posted by Ni3ls View Post
    Before accusing me of something, I did test it.
    Code:
    				self openMenu("spawn");
    				scriptMainMenu = "spawn";
    Thats how I open the menu and it only responds to some action if I pressed something inside that menu. I added some debug iprints and it didnt show. Even closing the menu there didnt work.
    Code:
    		if(menu == "spawn")
    		{
    	          wait 5;
                      self closeMenu();
    		  self closeInGameMenu();
                    }
    The fix of Mitch did the job for me
    It's not Mitch's. Standard menu file headers from COD2:

    Code:
    {
    	menuDef
    	{
    		name			"team_britishgerman"
    		rect			0 0 640 480
    		focuscolor		GLOBAL_FOCUSED_COLOR
    		style			WINDOW_STYLE_EMPTY
    		blurWorld		5.0
    		onEsc
    		{
    			scriptMenuResponse "close";
    			close team_britishgerman;
    		}
    		onOpen 
    		{
    			scriptMenuResponse "open";
    		}
    		onClose
    		{
    			scriptMenuResponse "close";
    			hide autoassign_info;
    			hide british_info;
    			hide german_info;
    			hide spectator_info;
    		}

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •