Random chance to talk in battles?

Hey everyone,

So in my game I'm trying to implement a system where the enemies, once they get below a certain health threshold, will start a conversation with the player, usually begging for mercy. If anyone has played Persona or Shin Megami Tensei games, it's that same idea. The enemy, at the end of the turn in which their health gets low, will start talking to the player and possibly run away, give them items, or just resume battle depending on what the player chooses.

I don't think I need a plugin to do this, as battle can run events natively. However, I can't figure out how this event would randomly occur. I don't want it to always occur (maybe only 20% of the time), and would want to be able to have some enemies NOT do it, such as bosses.

I also want it to be a conversation randomly selected from a list of possibilities as well.

Anyone have any idea how I can accomplish this? Thanks in advance! 🙂
To get them to occur randomly, set a variable by selecting random and then 1 - 5. Call this variable on the troop page.
Have a second variable which checks the particular enemy's HP
Have a conditional which checks if the variable is e.g. =3
If yes, a second conditional (which is obviously nested within the first) which checks the HP variable and if it is below X (i.e. you pick an amount where you want the conversation to kick in).
If yes, then your conversation.

This would be put into whichever troops you wanted. If you don't want a boss to do this, simply don't put it in that troop page.
Okay cool! Thanks!

So how would I get it to select a random conversation from a list? Also use a variable somehow?
After setting your event I think it goes like this

CONDITION If RANDOM TALK = 1
Event: Message
ELSE IF CONDITION = 2
Event: Message


and so forth?
Hm...I'm not getting it work. The only time it worked was when I set the Span to 'Turn' and the Conditions to Enemy HP under a threshold.

Should setting the Control Variable be happening in the Battle Event or outside of it by a different event?

Attached you'll find what I have right now (I set the Variable to equal or less than 4 so that it would have a higher chance of happening for testing purposes)

Also, @evmaster I'm not sure I fully understand what you're suggesting. So basically the extra conversations go on the Else branches?

Thanks for helping out on this so far everyone 🙂
It's not working because you have it still on the condition "Don't Run" - so it doesn't!
Change that to Turn 1 plus 1, and the span to Turn. Then it will check every turn if the variable for HP is less than 35.
It's not working because you have it still on the condition "Don't Run" - so it doesn't!
Change that to Turn 1 plus 1, and the span to Turn. Then it will check every turn if the variable for HP is less than 35.
Ah yes...that would make sense, haha.

Okay so it works! Now the only problem is that it triggers over and over again. I only want it to trigger once per battle. So this event can only happen a maximum of one time. Should I change the Span to 'Battle' for that?
You need to have it checked every turn - 'Battle' will only check it once, and as that is at the beginning of the battle, your conversation will never happen because at that stage the enemy has full HP.

Your troop event will need 2 pages.
Page 1, set to turn 0 (i.e. this will happen the moment the battle begins.)
Turn on a switch called e.g. "Battle Conversation". Nothing else on that page.
Page 2 set as I said earlier
Conditional branch Switch Battle Conversation is ON
Put inside the condition all the stuff detailed above.
At the end of your choices set switch Battle Conversation to OFF
Leave the 'Else' part of the new conditional empty.

What this means is that each turn the engine will check to see if the battle switch is ON. If it is, it will check if the HP is below the threshold you set. If it is, it will run the conversation, followed by the choices.
If the conversation has already run, that switch will be OFF, so nothing will happen.
Quick tip: you can use Yanfly's 'Base Troop Events' Plugin so you don't have to copypaste these event pages for every troop.

http://yanfly.moe/2015/10/18/yep-15-base-troop-events/
@Kes Oh that makes sense! Thanks so much! So how do I choose a conversation at random from a list of conversatiosn then, I guess is that last part to figure out. I read the post from @evmaster but I'm afraid I don't understand what it's saying.

@Jules98 That plugin looks awesome and would save me so much work! However, because the enemy HP check variable has to specify a particular enemy, I'm not sure I can use it unfortunately, since I have to individually specify each enemy from a dropdown. Unless you know of a workaround to that?
You do it by setting up another variable, with a range to match the number of different conversations you have. Then a conditional for each number. You can uncheck the 'Set handling conditions' box, as you don't need it.
If variable X = 1
Blah, blah
If variable X = 2
Blah de blah
If variable X = 3
Blahblahblah
You get the idea.

I use Base Troop Events a lot, and as far as I can see, there is no way that you can use it to specify individual enemies. Furthermore, it would automatically run in boss battles as well, which is what you don't want. However, once you've got this structure worked out, you can copy/paste everything except the enemy - though if you always pick enemy 1 in the troop, then probably even that bit could be copy/pasted.
Ok, I understand now! One last question, for the different conversation conditionals, do they need Else branches or not?
Yes they need the else branches. It checks each branch and goes down from there. IF not 1 then 2, if then 3 then 4 and so forth.

Edit: To clarify if you meant the random messages need the else branches, then the answer is YES.

Edit 2: ll try to explain. So let's say someone makes a variable that generates a random number between 1-2. In the event they make a conditional branch that checks if the random number generated is 1. If so, that is TRUE (and message under that branch is then displayed in game) But what if the random generated number is 2? The event checks the branch and moves on to the next ELSE in case the previous was not true. Think of it checking and moving down the tree. If you do not put an ELSE, the event stops and nothing else will be checked.

...Ah dangit. Well I tried. I may edit this later. I know I'm bad at explaining. ^^;

Edit 3: Someone please correct me if I am wrong. I'm starting to doubt myself. >_> I apologize Esterk, I was only trying to help.
@esterk I suggest you try and create this now, as doing it will help you understand much more clearly than people trying to explain it. See what works and what doesn't. Having done it yourself, you are much more likely to remember it next time you need something like this.
You guys were great! Sorry for the delayed response. I finally did get it to work and totally understand what everything means.

Thanks so much for explaining all of this to me!

@evmaster that totally makes sense! Don't worry, i was able to understand what you meant.

Thanks guys! You're awesome!

Original thread: https://forums.rpgmakerweb.com/threads/random-chance-to-talk-in-battles.85262/