Check for Highest Stat in First 4 Character Slots

My game will have a D&D-style skill check system where, in the field, certain stats will be called on (STR to move a boulder, AGI to pick a lock, etc.) to determine whether or not an action is a success. I have found a way to set it up so that the FIRST party slot is checked, using that character's stats for the event, but I'd like to know how to set it up so that the first four party members are checked for the highest stat.

For example, maybe the low-INT warrior is leading the party, but the mage is in the fourth slot. Instead of using the fighter's dismal intellect to recall lore, the mage tries it instead, without being moved to the front of the party. I mainly want to avoid having to force the player to keep swapping around the formation.

Does that make sense? I hope it makes sense. Thank you in advance! I've found this to be a very helpful forum!👋
You can check the first eight actors with the control variable command, game data section.

you just have to load all relevant data into several variables, and then use conditional branch to compare the variables and select the highest result.
you could with a control variables event, then use a script to check what you want (or go total event to make the checks. i just find scripting faster).

set variables to get the members order, like v[1] is the leader, v[2] is the 2nd member,...

the perform your checks with conditionals or scripts.

heres a picture of what mine looks like, it was an old project where i used the pages up and down keys to change the party leader "on the fly" in the field map.

Original thread: https://forums.rpgmakerweb.com/threads/check-for-highest-stat-in-first-4-character-slots.147866/