PDA

View Full Version : Perform action when menu is open but no button is pressed



Ni3ls
16th November 2014, 09:09
HI all.

I would like to know how to do an action of a certain menu is opened but no button is pressed.


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?

Mitch
16th November 2014, 09:45
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;
}

Tally
16th November 2014, 10:11
HI all.

I would like to know how to do an action of a certain menu is opened but no button is pressed.


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:


for(;;)
{
self waittill( "menuresponse", menu, response );

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

Ni3ls
16th November 2014, 12:11
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:


for(;;)
{
self waittill( "menuresponse", menu, response );

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


`No this is not working. It waits for a scriptresponse ( button action)

maxdamage99
17th November 2014, 13:02
May be worth a try:
PHP Code:
===============================
for(;;)
{
self waittill( "menuresponse", menu, response );

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

Tally
17th November 2014, 15:13
You could send a scriptmenu response of "open" + the menu it is being sent from, and then parse it from there:


onOpen
{
scriptMenuResponse "mymenu:open";
}
onClose
{
scriptMenuResponse "mymenu:close";
}
onEsc
{
scriptMenuResponse "mymenu:escape";
}


for( ;; )
{
self waittill( "menuresponse", menu, response );

if( getSubStr( response, 0, 6 ) == "mymenu" )
{
//get proper response
whathappened = strTok( response, ":" );

if( whathappened[1] == "open" )
self doOpenstuff();
else if( whathappened[1] == "close" )
self doClosestuff();
else
self doEscapestuff();
}
}

IzNoGoD
17th November 2014, 16:31
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.

Tally
17th November 2014, 18:04
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:


#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:


#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".

Ni3ls
18th November 2014, 08:37
Before accusing me of something, I did test it.
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.
if(menu == "spawn")
{
wait 5;
self closeMenu();
self closeInGameMenu();
}
The fix of Mitch did the job for me

Tally
18th November 2014, 10:55
Before accusing me of something, I did test it.
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.
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:


{
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;
}