Item useable both in menu and battle, but common event runs only in menu.

I added a consumable item that can be used in both menu and battle. I made a common event that would run if the player uses it in the menu, but the common event also run during a battle.

melon menu.PNG

melon battle.PNG


I only want the common event to run in the menu and not during battle. Is there anyway I can do this? If a variable is needed to do this, I would like an explanation of it. (I'm not good with variables)
In your common event, put a conditional branch, set it to script, and write either
Code:
!$game_party.in_battle
or
Code:
!SceneManager.scene_is?(Scene_Battle)

Put all the events you want to run outside the battle inside the conditional branch.
Like Theo said, you could do that, or you could also do the following:

(since I'm not sure which command_number the exit event processing command is, I will just say that it's easy to find if you go to the Game_Interpreter class and ctrl+f find the string "Exit Event Processing" and find the method name for the command)
Code:
command_[whatever number it is I cant remember] if $game_party.in_battle?

Basically it's the same thing, but it saves space and you don't need a conditional branch. It's one line of code that pretty much stops the common event if the party is in battle.

Original thread: https://forums.rpgmakerweb.com/threads/item-useable-both-in-menu-and-battle-but-common-event-runs-only-in-menu.122412/