Jump to content

Need help figuring out the CloseAllMenus function with my MessageBox script.


ReelBigFan

Recommended Posts

I've been in the process of making tweaks to my mod The Gharen Hammer (shameless plug, I know) but I'm having some trouble getting part of a script to work. It's an object script attached to an misc item that when activated moves a piece of furniture (an anvil) in front of the player and then removes itself from the players inventory. The actual script is pretty simple with two blocks; a Begin OnEquip and a Begin GameMode. The GameMode block simply calls the anvil moving function and then removes the item from the player's inventory and does the job. The problem is the OnEquip block which is supposed to check if the player is in the air/jumping, and display a message confirming/deny the anvil was placed depending on if the player is on the ground or not, then close the inventory and return to the game.

The fall check works great, but I cannot figure out how to get both the MessageBox function and the CloseAllMenus function to work together. I've tried re-writing this block and experimenting with all sorts of things to try to get both to work, but I can either get the messages to display, but the inventory wont close, or no MessageBox appears but the inventory closes out correctly. I'm pretty stumped and I would love some input as to how I can get this working as intended. Here is a sample of my script:

int iCanMove
int iMenuOption
int iButtonpressed

Begin onEquip


    if (player.IsInAir == 0) && (player.IsJumping == 0)
        set iCanMove to 1
        
        MessageBoxEx "You set the Mithas Anvil.|Okay"  
        set iMenuOption to 1
        if iMenuOption == 1                        
            set iButtonpressed to getbuttonpressed       
            if iButtonpressed > -1
                if iButtonpressed == 0
                    set iMenuOption to 0
                endif
            endif
        endif
    else
        MessageBoxEx "You cannot set the Mithas Anvil at this time.|Okay"  
        set iMenuOption to 1
        if iMenuOption == 1                        
            set iButtonpressed to getbuttonpressed       
            if iButtonpressed > -1
                if iButtonpressed == 0
                    set iMenuOption to 0
                endif
            endif
        endif
    endif
    
    CloseAllMenus
            
End

 

 

I've tried putting the CloseAllMenu function in an if statement like this and in its on MenuMode block, but it was a bust:

...
			if iButtonpressed == 0
				set iMenuOption to 0
				set iCanClose to 1
			endif
		endif
	endif
endif
 

if iCanClose == 1
    CloseAllMenus
    set iCanClose to 0
endif
End

 

If anyone has any ideas as to how to make this work or can explain what I'm doing wrong it would be greatly appreciated. Thanks in advance to anyone who takes the time to look at this!

Link to comment
Share on other sites

You're making a mistake checking a button in the event. You want to wait for player to close a message and return to a game? This should do nicely:

int iCanMove
int iMenuOption
int iButtonpressed

Begin onEquip
	if (player.IsInAir == 0) && (player.IsJumping == 0)
		set iCanMove to 1
		MessageBoxEx "You set the Mithas Anvil.|Okay"  
		set iMenuOption to 1
		set iButtonPressed to -1
	else
		MessageBoxEx "You cannot set the Mithas Anvil at this time.|Okay"  
		set iMenuOption to 1                      
		set iButtonPressed to -1
	endif            
End

begin MenuMode
	if iMenuOption != 0 ;our message ?
		set iButtonPressed to GetButtonPressed
		if iButtonPressed > -1
			set iMenuOption to 0
			set iButtonPressed to -1
			CloseAllMenus
		endif
	endif
end

 

Link to comment
Share on other sites

That worked like a charm! I feel silly now; that was like the one thing I didn't think to try 😅.

 

This is the second time you've come to the rescue and helped me with my amateur scripting, and I can't thank you enough. I greatly appreciate all your help!

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...