Preventing Battle if higher than mob level

I want to know if there is a way to compare highest level party member vs monster level. I have a battle setup where the mobs are on the screen. The player runs into the mob to initiate battle. I want to setup a conditional branch checking to see if the party is higher level or not. If the party level is 5 levels higher than the mob level, no fight occurs.

How can this be done? 

I am using Yanfly's Enemy Level script for mob levels. If no script is used, I'm sure a variable could be setup and set on each mob.
I've moved this thread to RGSSx Script Support. Please be sure to post your threads in the correct forum next time. Thank you.


What is the party level? If you have 4 members in the party, their levels could be 1, 10, 20 and 99. What is the party level?
Since you have Yanfly's enemy levels script already, you can get the party's average level with a script call to:

$game_party.average_level

Store the result in a variable, and compare that variable to the number you wish to compare with. If it is higher, have no fight occur. Else, call battle processing and the battle occurs.
Since you have Yanfly's enemy levels script already, you can get the party's average level with a script call to:

$game_party.average_level

Store the result in a variable, and compare that variable to the number you wish to compare with. If it is higher, have no fight occur. Else, call battle processing and the battle occurs.
Very nice. Thank you. This will work perfectly, because each monster type has their own event. So I can setup individual level restrictions based on the mob. 
How do I do the same thing, but for map encounters? As in map properties and battle by steps.
That I think will take a script, and I'm not sure one such one has been written. I've attempted to start one, but I only got it as far as a cut off for each map (as in, if your average level is above a set value that you set, then no battles will occur). If that will help you I can send it your way, but if you need more you may need to make a script request for it.
How do I do the same thing, but for map encounters? As in map properties and battle by steps.
You can use a Random Encounter Event, which allows you to run a common event when a random encounter occurs and cancel the encounter if needed.


Example video starting at 0:32
Very nice. This will do the trick. Thank you!
I can't get your script to work. What am I doing wrong?

Also, will this command work "$game_troop.enemy_level" to compare against the troop level that you encounter?

-Update-

That command doesn't work. Is there a similar command I can call to check enemy level like the check party level above?

1.png

2.png

3.PNG
The ID that you set is not the common event that will run, it's the variable that will store the ID of the common event that will run.


So if variable 3 is currently 0, then no common event will run.


I set things up like this so dev's can have different common events run under different circumstances.


$game_troop is available when the common event runs.
The ID that you set is not the common event that will run, it's the variable that will store the ID of the common event that will run.

So if variable 3 is currently 0, then no common event will run.

I set things up like this so dev's can have different common events run under different circumstances.

$game_troop is available when the common event runs.
Ok so you pretty much set the variable to = what common event ID you want to run? I set the variable 3 to = 3 on autostart and it calls the common event successfully.

Using the enemy levels script, how would I check the party's level vs the monster level? Before when I was running into the mobs on the map, I could specify level requirements based on which mob it was. For instance if mob = dragonfly then party level past lv 8 would cause the battle to not fire. How do I check this in random encounters?

If no command can be used like how you can check party lv ($game_party.average_level) can a command check against enemies inside the troop? Like $game_troop has monster ID X?
This would suggest that each encounter will only consist of one enemy, or multiple copies of the same enemy.

$game_troop.members[0]Returns the first enemy in the troop.You can then check its ID like

Code:
$game_troop.members[0].id
How do I do this with the default in game conditional branch? I can't figure it out.

I've tried:

$game_troop.members[0].id = 3

and

$game_troop.members[0] = $game_troop.members[3].id

How do I get this to work?

1.png
Checking equality is == not =
Oops. I changed it to:

$game_troop.members[0] == $game_troop.members[3].id

and I have an encounter with the id of either 3 or 4. This doesn't fire. I have it display a message that doesn't show up. See attached pic.

What is the correct way to set this up?

1.png
What are you trying to do?

If you want to check whether the first enemy has ID 3 then you would say

Code:
$game_troop.members[0].id == 3
What are you trying to do?

If you want to check whether the first enemy has ID 3 then you would say

$game_troop.members[0].id == 3
I've also tried that as well. Doesn't work. Look at the picture. Am I putting the code in the right part? Clicking script in the conditional branch?
The script requires you to set a variable in the config.


That variable needs to have a value of the common event you want to run.


Verify these are correct.
Yes, The script is firing. Everything is configured correctly. I can put a message outside of that condition and it will fire each time a encounter happens. 

So I set everything up correctly in the picture?

-=Update=-

This is the error message I am getting when trying:

$game_troop.members[0].id == 3

1.png
Sorry, should have double-checked. Only actors can access their ID's via "id". Enemies need to use "enemy_id" for some reason.

Code:
$game_troop.members[0].enemy_id == 3

Original thread: https://forums.rpgmakerweb.com/threads/preventing-battle-if-higher-than-mob-level.37529/