Script call to check if the player is in battle.

Hi. This is my first post so I apologise if it Isn't exactly clear what I am asking for, but I'll try my best. I am trying to make an item work differently when in battle. I have made the item run a common event, which has a conditional branch. That's where I get stuck. After much experimenting, i came to the conclusion that the only way i would be able to check this, is by using a script call. After searching online the closest thing i could get was this: ' SceneManager.is?(Scene_Battle); ' Which doesn't work. I have no coding experience, so i have no idea what exactly to change to get this to work. Thanks in advance for anybodies help!
What does the item do out of battle and what would you like it to do in battle? Let's see if we can do this without js first.
It is a potion that heals instantly outside of battle. But over a few turns in battle. However, I think the real difficulty might come because I have it tied to a common event that replaces the potion with an 'empty bottle' item, so it can be 'refilled' rather than restocked.
It is a potion that heals instantly outside of battle. But over a few turns in battle. However, I think the real difficulty might come because I have it tied to a common event that replaces the potion with an 'empty bottle' item, so it can be 'refilled' rather than restocked.
You might be able to add multiple commands to the same common event.

Maybe you can turn on a switch every time the character enters battle (I feel like there's a plugin for battle events out there, or you can add it to your encounters if they are evented), and add a conditional branch, "If inbattle = on then add state HoT? Else... heal instantly." Then turn it off at the end of the battle.

I'm at work and can't see if this will work, but maybe you can mess around with switches.

It might be more worth your time to request a script though. Sorry I couldn't help too much! I once had an item that did 2 different things, so I thought maybe I'd have better ideas for you 🙂
I did consider switches, but my initial thought was that I would need to add that switch into every troop. Which led me to try and find a way to tell when the player was in battle. I think switches will make it work, but being able to specifically tell when the player is in battle would allow me to keep everything within the one common event.

No problem! Iv found that just talking it through can be enough to strike an idea!
I did consider switches, but my initial thought was that I would need to add that switch into every troop.
That's true. In another game I made, I put all of my evented encounters (who roamed the map) onto a common event, just so I could do things like add switches without editing *all* of my monsters.

 Iv found that just talking it through can be enough to strike an idea!
Yes! My favorite solution! Good luck 😀
So I'm still looking for a way to specifically tell when the player is in battle. Preferably without the use of switches, instinct is telling me this will only be possible by a plugin, or hopefully, a script call that checks if the player is in battle.

If anyone is also able to give any suggestions for how to upgrade items. I was hoping Yanflys upgrade plugin would work, but it only works for weapons and armour.
http://www.rpgmakervxace.net/topic/16273-conditional-branch-to-check-if-i-am-in-battle/

This script condition is exactly what I need. I just need the equivalent for MV.
$gameParty.inBattle() will return true if player is in battle =)

You can use it inside the item  formula instead of calling a common event.
Perfect! Thank you so much!
$gameParty.inBattle() will return true if player is in battle =)

You can use it inside the item  formula instead of calling a common event.
Just for future reference, how would that change if i want to check if the party isn't in battle?
Ok, now i have another issue! Im using $gameParty.inBattle() in the potions formula. But i cant get it to add a state, i assumed you would add it between the brackets. But i can't get it to work. Its very likely im not even correctly trying to add a state: $gameParty.inBattle(add.State(36)) Any help would be greatly appreciated again!
You have to check if player is in battle and then telling the item what to do, like this:

if ($gameParty.inBattle()) {b.addState(36)} else {}write inside "else{ }" what the item will do if "$gameParty.inBattle()" is false.
The else would be a HP% heal, another thing i cant seem to get to work in the formula, only healing by a specific number. 
It isnt adding the state within battle still, this is what the item looks like in the database:  Potion.png
Got it, my mistake, you can't just add a state, you have to set a healing value too, even if it is 0.

if ($gameParty.inBattle()) {b.addState(36);0} else {value}you can use expressions to determine "value", so if you want to heal 20% of the Max HP for example, use "b.mhp * 0.2"
I tried using:

($gameParty.inBattle()) {b.add.State(36);0} else {b.mhp * 0.2}

and neither is working, in battle or outside. Iv tried removing the common event that is also tied to the item and still nothing. 
I tried using:

($gameParty.inBattle()) {b.add.State(36);0} else {b.mhp * 0.2}

and neither is working, in battle or outside. Iv tried removing the common event that is also tied to the item and still nothing. 
replace b.add.State with b.addState

without dot 😉

and its works for me
yeah my bad, just realised that. However, it still doesnt work when it is all together. When   b.addState(36);0   is used in the formula, the state is added correctly, inside of battle and out. When   b.mhp * 0.2   is used alone in the formula, HP is healed correctly in battle and out. When   ($gameParty.inBattle())   is used alone in the formula, the player is healed by 0 outside or battle, and 1 in battle. I presume the '1' means it has found that the player being in battle is true? However, when all 3 are together:    ($gameParty.inBattle()) {b.addState(36);0} else {b.mhp * 0.2}   , the character is always healed by 0, both inside and outside of battle.

I feel like i missing something obvious  🙁  
>_>   >_>   >_>   >_>   >_>   >_>   >_>   >_>   >_>   >_>   >_>   >_>   >_>   >_>   >_>   >_>   >_>   >_>   >_>   >_>   >_>   >_>   >_>   >_>   >_>

The second i pressed the send button i realised... i was missing somethng obvious. I didnt put 'if' before the whole thing.

It now works perfectly, thank you so much everyone!

Original thread: https://forums.rpgmakerweb.com/threads/script-call-to-check-if-the-player-is-in-battle.49501/