Need help with calling multiple common events after level up (XP)

So I have four common events that I want to run when four different characters level up, so I use this line of code:
$game_temp.common_event_id = [] if actor.id == [] (Replace the [] for the numbers) in Scene Battle 2 as well as Interpreter 6.

It works... as long as the characters aren't leveling up at the same time while in the active party (most notably when they level up due to a battle).

I have no idea how to fix this because I have the scripting know-how of a potato (I only know about this trick due to a forum post in Game Dev Unlimited and reading what little actual English there is in the scripts to figure out what location it would go in.)

All I can say is... help, please?

Edit: If you need my versions of the two scripts, I'll post them, but they're pretty much just the vanilla scripts sans adding this line:
Code:
$game_temp.common_event_id = [] if actor.id == []
to Scene Battle 2 at around line 184 and this line:
Code:
if actor.id == []
            $game_temp.common_event_id = []
          end
to Interpreter 6 at around line 205 four times, one after the other
Um.... I think your problem lies with a particular issue regarding the common events.

When you declare one common event for a leveling actor, it gets overwritten by the next common event for the next actor leveling. By that, I mean, the system only accepts ONE common event.

NOW... Be that the case, the solution is to use only ONE common event and... trick the system to store the IDs of any actors that are leveling!

Examine THIS change to Scene_Battle 2's start_phase5 method:

Code:
    # Treasure is limited to a maximum of 6 items
    treasures = treasures[0..5]
   
    # Create a temp array for your actors.
    # Make it completely empty
    # And erase game variables #1
    $game_variables[1] = 0
    actor_id_array     = []
   
    # Obtaining EXP
    for i in 0...$game_party.actors.size
      actor = $game_party.actors[i]
      if actor.cant_get_exp? == false
        last_level = actor.level
        actor.exp += exp
        if actor.level > last_level
          @status_window.level_up(i)
         
          # Push the ID of your actor into
          # the temp array.  But only here
          # when the actor is leveling!
          actor_id_array.push(actor.id)
         
        end
      end
    end
   
   
    # ONLY if the temp array has something in it,
    # do we shove data into RMXP Game Variable 1
    # And set the common event ID to 1
    if actor_id_array != []
      $game_variables[1] = actor_id_array
      $game_temp.common_event_id = 1
    end
   
   
   
    # Obtaining gold
    $game_party.gain_gold(gold)

The above code obtains all the IDs of your leveling actors and stores it in RMXP game variable 1. Yep, you can do that! Hell, you can even store STRINGS (names or whatnot) into Variables if you wanted. But here, we're storing an array of actor IDs.

So here, we are hardwiring RPGMaker Variable #1 to hold the IDs, and assume that Common Event #1 is the SINGLE common event that runs if there's some Actor leveling.

--------------------------------------------------------------------------​

That was the script change. THIS is the common event:
@>Control Switches: [0001] = OFF
@>Control Variables: [0003: counter] = 0
@>Loop
@>Script: counter = $game_variables[3]
: : $game_variables[2] =
: : $game_variables[1][counter]
: : max_size = $game_variables[1].size
: : if counter > max_size
: : $game_switches[1] = true
: : end
@>Conditional Branch: Switch[0001] == ON
@>Break Loop
@>
: Branch End
@>Conditional Branch: Variable[0002: Individual ID] == 1
@>Text: Woot, Aluxes leveled up!
@>
: Branch End
@>Conditional Branch: Variable[0002: Individual ID] == 2
@>Text: Of course, Basil Leveled
@>
: Branch End
@>Conditional Branch: Variable[0002: Individual ID] == 7
@>Text: Wait. What did Gloria actually kill?
@>
: Branch End
@>Conditional Branch: Variable[0002: Individual ID] == 8
@>Text: Hot Ice Hilda fried enough Ghosts, right?
@>
: Branch End
@>Control Variables: [0003: counter] += 1
@>
: Repeat Above
@>
​

Yep, a bit complex. And it is a LOOP. We have a COUNTER variable (Game Variable #3) and use that counter in the script call at the beginning of this block. The script call lets you snag ONE of the hero IDs from Game Variable 1 and stores it in Game Variable #2.

So rather than have four individual common events, you have one common event, and the contents are in their individual....
@>Conditional Branch: Variable[0002: Individual ID] == whatever
@>... do this code
@>
: Branch End
​
...block of code.

There is one more feature in the script call, and that is to run a check to see if you went through all the actor IDs stored. If you did, it turns on a switch, that being Switch #1 It must be off before the loop, but gets turned on when you run out of actors. And when it is turned on, it breaks out of the loop.

So yeah, you will need to reserve Switch #1, Common Event #1, and Game Variables 1, 2, and 3
What about in Interpreter 6? I tested it out, but it only works when the level up is due to a battle, not the "change level" command.
Ahh... Well, then, something quite similar to be added to command_316

Code:
  def command_316
    # Get operate value
    value = operate_value(@parameters[1], @parameters[2], @parameters[3])
   
    # Create a temp array
    temparray = []
   
    # Process with iterator
    iterate_actor(@parameters[0]) do |actor|
     
      # Change actor level
      actor.level += value
      temparray.push(actor.id)
     
    end
   
    if temparray != []
      $game_variables[1] = temparray
      $game_temp.common_event_id = 1
    end
   
    # Continue
    return true
  end

The same basic constructs in the Scene_Battle edit now within this particular method. Looks the same. Does the same.
It works! Thanks. You're always the one saving my butt when it comes to scripting.
"I don't understand." - Savvik
"You have to know WHY things work on a Starship." - Admiral James T. Kirk (Just before he freakin used WIFI in Star Trek II (c) 1982)

😉 And it's a case of understanding HOW the common events work. I just began tearing scripts apart and studied like crazy. Hell, over 10 years, right? Besides working on your game, make a separate side project and... tear stuff up! Break it and see why it broke. 😛

Original thread: https://forums.rpgmakerweb.com/threads/need-help-with-calling-multiple-common-events-after-level-up-xp.107515/