Level Up Common XP

Level Up Common XP

by Kyonides
​

Introduction

This simple scriptlet will let you call a given Common Event by configuring the ACTORS_EVENT in such a way that it will find the target actor's current level and call the common event if any was found.

How does it find the right common event?

Well, it is very simple to explain. The scriptlet will look for the lowest level possible.
If you set a level like 5 and your actor has just reached level 2, it will trigger the level 5's common event.
Once that actor's level goes beyond that point, it will have to search for a higher level if available.
If no other level is available, nothing will happen.
If you wanna set a specific common event for the remaining levels, 100 or your game's maximum level will suffice.

I embedded some comments in the script to help you add more actors.
Right now it will only work with :asrs: Aluxes aka Alex.

EDIT: Updated

Ruby:
# * Level Up Common XP * # 
#   Scripter : Kyonides Arkanthes
#   2024-03-22

# This scriptlet allows you to call a common event after the actor finishes the
# leveling up process. To accomplish this task, you will have to configure
# the ACTORS_EVENT hash accordingly.
# To add an Actor you need an ActorID & 1 or more Level => CmEvID key pairs.

module LvUpCm
  ACTORS_EVENT = {} # Leave it alone!
  ACTORS_EVENT.default = {} # Leave it alone!
  # Follow this pattern:
  # ACTORS_EVENT[ActorID] = { 5 => 1, 10 => 2, 100 => 3, etc. }
  ACTORS_EVENT[1] = { 4 => 1, 8 => 2, 100 => 3 }
end

class Game_Actor
  alias :kyon_lvl_up_cmmn_gm_act_exp_set :exp=
  def exp=(new_exp)
    old_level = @level
    kyon_lvl_up_cmmn_gm_act_exp_set(new_exp)
    process_level_up_common_event(old_level)
  end

  def process_level_up_common_event(old_level)
    return if @level <= old_level
    event_group = LvUpCm::ACTORS_EVENT[@actor_id]
    return if event_group.empty?
    key = event_group.keys.sort.find {|n| @level <= n }
    $game_temp.common_event_id = event_group[key] || 0
  end
end


Terms & Conditions

Free for use in ANY game.
Due credit is mandatory.
Mention this forums in your game credits.
That's it! 😛
ACTORS_EVENT[1] = { 4 => 1, 8 => 2, 100 => 3 }
if this runs common event 1, and at level 8 or below common event 2
can ACTORS_EVENT[2] also run common event 1 and 2?
or something to make it count for all actors in party?

something like ACTORS_EVENT[0] (for all party members)
and using 1, 2, 3, 4 for actor id's, maybe the same common event depends
what happened there based on variable?

Not that I use XP anytime soon, but it can come in handy when I play around
later with it.
Question said:
if this runs common event 1, and at level 8 or below common event 2
can ACTORS_EVENT[2] also run common event 1 and 2?

Well, depending on the game developer's customizations in the Common Events DB, that should work normally.

Question said:
or something to make it count for all actors in party?

OK, that's not one of its the features currently available, yet, you could use its default value...

Ruby:
ACTORS_EVENT.default = { 3 => 1, 6 => 2, 9 => 1 }

...as a template for any actor that you have not configured already.

Actually, it'd work the way you proposed here if you simply skip the customizations for any specific actors. I mean, feel free to configure the default value and forget about entering separate entries for any given actors.
there is a weird bug I think on the level up part when checking the demo.
when its on target[1] is just keep saying "I'm now level V[1] Fighter"
when I set 3 lines text, it says the same thing.

when I set a new text page, than it seems to work, as the previous lines
aren't read somehow, is this a bug or glitch?

EDIT:
upon testing, it takes the last common event constantly (3) unless

EDIT 2:
using this:
ACTORS_EVENT[1] = { 6 => 1, 20 => 2, 100 => 3 }

will comment event 1 will run till 7, than jumps to common event 3, skipping 2.
not sure why or can figure it out. (I did vice versa, but it will run 3 than 2 non-stop.
as I dont know ruby, I cannot play with the code for a possible fix or how too.
Maintenance Update!​

Thanks to a shadowy figure here, I tested my XP & VX demos and found that I needed to sort the levels first before the system ever tries to find the lowest level group possible based on the new level the hero has recently reached.

@ShadowDragon Concerning the lines of text not drawing when expected, I can't tell you anything about it. I couldn't find that bug on my own.
this is the result on testing:
result.png
I dunno why because today's release clearly sorts the hash keys properly.
Ruby:
ACTORS_EVENT[1] = { 4 => 1, 8 => 2, 100 => 3 }
Internally become:
Ruby:
[4, 8, 100]
...before starting to look for the right level here:
Ruby:
key = event_group.keys.sort.find {|n| @level <= n }
I ran both the default game executable and my custom one. Both throw good results just as intended.

EDIT1: Here's a test script. It will throw popup windows in your face but will let you know what's happening while processing the levels as keys.

EDIT2: I added another line of code to let it print the common event ID.

Spoiler: The Test Code
Ruby:
# * Level Up Common XP - Test * #
#   Scripter : Kyonides Arkanthes
#   2024-03-22

# This scriptlet allows you to call a common event after the actor finishes the
# leveling up process. To accomplish this task, you will have to configure
# the ACTORS_EVENT hash accordingly.
# To add an Actor you need an ActorID & 1 or more Level => CmEvID key pairs.

module LvUpCm
  ACTORS_EVENT = {} # Leave it alone!
  ACTORS_EVENT.default = {} # Leave it alone!
  # Follow this pattern:
  # ACTORS_EVENT[ActorID] = { 5 => 1, 10 => 2, 100 => 3, etc. }
  ACTORS_EVENT[1] = { 4 => 1, 8 => 2, 100 => 3 }
end

class Game_Actor
  alias :kyon_lvl_up_cmmn_gm_act_exp_set :exp=
  def exp=(new_exp)
    old_level = @level
    kyon_lvl_up_cmmn_gm_act_exp_set(new_exp)
    process_level_up_common_event(old_level)
  end

  def process_level_up_common_event(old_level)
    return if @level <= old_level
    event_group = LvUpCm::ACTORS_EVENT[@actor_id]
    return if event_group.empty?
    print "New Level: ", @level
    keys = event_group.keys.sort
    print "Sorted Keys\n", keys
    key = keys.find {|n| @level <= n }
    print "Found Key: ", key
    $game_temp.common_event_id = event_group[key] || 0
    print "Common Event ID: ", $game_temp.common_event_id
  end
end
the printing code worked, nice job, able to rule out the printing part.
Since I suspected that you had not downloaded the demo again, I updated the code on the main post to make sure people will only keep a copy of the most recent version of my script.

Original thread: https://forums.rpgmakerweb.com/threads/level-up-common-xp.167016/