Common event on level up.

Hi guys!
I need help with this.
I want to give a player a certain item whenever player levels up.
Problem is I don't know how to make a common event that will check if player leveled up.
I tried something with variables as player lvl but it didnt work.
Maybe there is a script that will help me? I tried to search for it too but found only something for MV version.
At the start of every battle, call a common event that stores player level into a variable and turns on a switch.
Have another common event set to autorun with the trigger being the switch used above. This common event stores the player level into another variable. Then, run a conditional branch that checks whether the 2nd variable is higher than the 1st, and if so, gives item to the player. Afterwards, turn off the switch to stop autorun.
At the start of every battle, call a common event that stores player level into a variable and turns on a switch.
Have another common event set to autorun with the trigger being the switch used above. This common event stores the player level into another variable. Then, run a conditional branch that checks whether the 2nd variable is higher than the 1st, and if so, gives item to the player. Afterwards, turn off the switch to stop autorun.
Hmm.. I don't have battles in my game. I use SAS IV script for in real time fights.
It would still follow a similar process, just change the way it detects the end of a battle or whenever EXP is gained.
It would still follow a similar process, just change the way it detects the end of a battle or whenever EXP is gained.
I tried it. I made something like when character gets EXP it calls for common event with conditional branch. But I keep recieve same item over and over.

Spoiler: Pics
pic1.PNG

pic2.PNG
That's events I created on map with monsters.
Spoiler: Pics 2
pic3.PNG
pic4.PNG
I probably did something wrong. But my brain now is too confused to figure it out :v
The Parallel Process in the last screenshot continues to trigger because it's not shut down. But without knowing what triggers it, not much I can say about it.
The Parallel Process in the last screenshot continues to trigger because it's not shut down. But without knowing what triggers it, not much I can say about it.
Okay. Totally forgot about that. I changed to stop process after common event enables. That event is running all time in background and it should look for changes in my exp. It worked once when I killed one monster. But after getting another level I did not recieve those items I want to get.
I changed to stop process after common event enables.

Because you've ended the event processing there. You're also going through way more hoops than is necessary. You can just run a single a Parallel Common Event like this:

-Variable1 checks player level.
-If Variable 1 is equal to 1 (or your starting level): set Variable2 equal to Variable1 (this is to avoid giving the item before the first level up is gained).
-If Variable 1 is higher than Variable2: give item to player, then set Variable 2 equal to Variable 1.
the simplest solution would be to make the common event, with no checks, and use a plugin to add the call after the level-up.
there is a function for checking the level-up, by default, and the common event itself isn't much of a challenge either, if it's just giving out an item.... so, it all boils down to adding one instruction to that level-up check.

is this something that will happen every time they level up?
who's leveling up? just the main actor, or any characters?
can this happen out of battle too?
because the actual check for level-up belongs to the actor object, and there's no actual processing within the battle itself, the battle manager lets the individual actors do their own check.
so, with that, you can do this out of battle if you need to.
Because you've ended the event processing there. You're also going through way more hoops than is necessary. You can just run a single a Parallel Common Event like this:

-Variable1 checks player level.
-If Variable 1 is equal to 1 (or your starting level): set Variable2 equal to Variable1 (this is to avoid giving the item before the first level up is gained).
-If Variable 1 is higher than Variable2: give item to player, then set Variable 2 equal to Variable 1.
Okay now im super confused. Should I replace original process or should I make additional one. I deleted everything and I did like you said but no effect.
the simplest solution would be to make the common event, with no checks, and use a plugin to add the call after the level-up.
there is a function for checking the level-up, by default, and the common event itself isn't much of a challenge either, if it's just giving out an item.... so, it all boils down to adding one instruction to that level-up check.

is this something that will happen every time they level up?
who's leveling up? just the main actor, or any characters?
can this happen out of battle too?
because the actual check for level-up belongs to the actor object, and there's no actual processing within the battle itself, the battle manager lets the individual actors do their own check.
so, with that, you can do this out of battle if you need to.

Main actor will get item every time he levels up. It can happen out of battle (quest exp reward for ex.)
(I don't have standard turn based battle btw)
Gain item on level up
Will only process for the main actor. If it did it for all then you would get items for every actor that leveled up.
Ruby:
module R2_Receive_Item_ONLevelUp
  USE_VAR = true
  Item_Type = 1         # 0 = item, 1 = weapon, 2 = armour
  Item_Number = 5       # item id in the database
  Item_Quantity = 2     # Number of items to give
  Var_Item_Type = 4     # variable used to save item type
  Var_Item_Number = 5   # variable used to save item id
  Var_Item_Quantity = 6 # variable used to save how many items to give
end

class Game_Actor < Game_Battler
  alias r2_item_levelup_change_exp  change_exp
  def change_exp(exp, show)
    r2_item_levelup_change_exp(exp, show)
    level_up_item
  end
  def level_up_item
    return if actor.id != $game_party.battle_members[0].id
    if R2_Receive_Item_ONLevelUp::USE_VAR == true
      type = $game_variables[R2_Receive_Item_ONLevelUp::Var_Item_Type]
      number = $game_variables[R2_Receive_Item_ONLevelUp::Var_Item_Number]
      quantity = $game_variables[R2_Receive_Item_ONLevelUp::Var_Item_Quantity]
      case type
      when 0
        $game_party.gain_item($data_items[number], quantity)
      when 1
        $game_party.gain_item($data_weapons[number], quantity)
      when 2
        $game_party.gain_item($data_armors[number], quantity)
      end
    else
      type = R2_Receive_Item_ONLevelUp::Item_Type
      number = R2_Receive_Item_ONLevelUp::Item_Number
      quantity = R2_Receive_Item_ONLevelUp::Item_Quantity
      case type
      when 0
        $game_party.gain_item($data_items[number], quantity)
      when 1
        $game_party.gain_item($data_weapons[number], quantity)
      when 2
        $game_party.gain_item($data_armors[number], quantity)
      end
    end
  end
end
Spoiler: msg
Gain item on level up
Will only process for the main actor. If it did it for all then you would get items for every actor that leveled up.
Ruby:
module R2_Receive_Item_ONLevelUp
  USE_VAR = true
  Item_Type = 1         # 0 = item, 1 = weapon, 2 = armour
  Item_Number = 5       # item id in the database
  Item_Quantity = 2     # Number of items to give
  Var_Item_Type = 4     # variable used to save item type
  Var_Item_Number = 5   # variable used to save item id
  Var_Item_Quantity = 6 # variable used to save how many items to give
end

class Game_Actor < Game_Battler
  alias r2_item_levelup_change_exp  change_exp
  def change_exp(exp, show)
    r2_item_levelup_change_exp(exp, show)
    level_up_item
  end
  def level_up_item
    return if actor.id != $game_party.battle_members[0].id
    if R2_Receive_Item_ONLevelUp::USE_VAR == true
      type = $game_variables[R2_Receive_Item_ONLevelUp::Var_Item_Type]
      number = $game_variables[R2_Receive_Item_ONLevelUp::Var_Item_Number]
      quantity = $game_variables[R2_Receive_Item_ONLevelUp::Var_Item_Quantity]
      case type
      when 0
        $game_party.gain_item($data_items[number], quantity)
      when 1
        $game_party.gain_item($data_weapons[number], quantity)
      when 2
        $game_party.gain_item($data_armors[number], quantity)
      end
    else
      type = R2_Receive_Item_ONLevelUp::Item_Type
      number = R2_Receive_Item_ONLevelUp::Item_Number
      quantity = R2_Receive_Item_ONLevelUp::Item_Quantity
      case type
      when 0
        $game_party.gain_item($data_items[number], quantity)
      when 1
        $game_party.gain_item($data_weapons[number], quantity)
      when 2
        $game_party.gain_item($data_armors[number], quantity)
      end
    end
  end
end
Okay I pasted that script to my project. I changed everything (type, item number, quantity, variables) to match mine. But no effect. Should I do something more?
Okay thanks for help I solved it by myself with a little help of Milennin idea.
I made common event that runs once when you kill an enemy. If your lvl is not higher than before killing him event turns off. If its higher you get an ITEM and level variable gets updated and event turns off also.
For example:
Im on lvl 1 and I kill an enemy.
After killing him im on lvl 2.
Common event sees that im 1 lvl higher.
I recieve item and variable get's updated to lvl 2.
If I kill more monsters up to lvl 3 everything repeats.
But no effect. Should I do something more?
The variables are there if you decide to use variables for the script. If you don't then set it to false and ignore those 3 constants.
Just set the constants for the item to be given.
If you use variables then specify what variables to use for each part and in the game set the variables to whatever value you want for the item to be given.
You don't use both.
The variables are there if you decide to use variables for the script. If you don't then set it to false and ignore those 3 constants.
Just set the constants for the item to be given.
If you use variables then specify what variables to use for each part and in the game set the variables to whatever value you want for the item to be given.
You don't use both.
Ohh okay thanks for clarifying.
Edit: Its working now but not as intended. It seems that whenever I get EXP I recieve that item. So when I kill 10 monsters I get 10x that item
well, Roninator caught my idea, although I was thinking of just adding a reserve_common_event(X) call in the XP calculation and leave the processing to the common event, for ease of handling.
not a fan of using modules and customization through scripts, when the processing will be done by a common event... After a while, you get split between the two when you start changing things and it's a mess.
So when I kill 10 monsters I get 10x that item
Of course forgot that this will run every time exp is gained not just for level up.
Try this
Ruby:
module R2_Receive_Item_ONLevelUp
  USE_VAR = true
  Item_Type = 1         # 0 = item, 1 = weapon, 2 = armour
  Item_Number = 5       # item id in the database
  Item_Quantity = 2     # Number of items to give
  Var_Item_Type = 4     # variable used to save item type
  Var_Item_Number = 5   # variable used to save item id
  Var_Item_Quantity = 6 # variable used to save how many items to give
end

class Game_Actor < Game_Battler
  alias r2_item_levelup_change_exp  change_exp
  def change_exp(exp, show)
    prev_level = @level
    r2_item_levelup_change_exp(exp, show)
    level_up_item if prev_level + 1 == @level
  end
  def level_up_item
    return if actor.id != $game_party.battle_members[0].id
    if R2_Receive_Item_ONLevelUp::USE_VAR == true
      type = $game_variables[R2_Receive_Item_ONLevelUp::Var_Item_Type]
      number = $game_variables[R2_Receive_Item_ONLevelUp::Var_Item_Number]
      quantity = $game_variables[R2_Receive_Item_ONLevelUp::Var_Item_Quantity]
    else
      type = R2_Receive_Item_ONLevelUp::Item_Type
      number = R2_Receive_Item_ONLevelUp::Item_Number
      quantity = R2_Receive_Item_ONLevelUp::Item_Quantity
    end
    case type
    when 0
      $game_party.gain_item($data_items[number], quantity)
    when 1
      $game_party.gain_item($data_weapons[number], quantity)
    when 2
      $game_party.gain_item($data_armors[number], quantity)
    end
  end
end
Moved to: RGSS3 Script Requests
Of course forgot that this will run every time exp is gained not just for level up.
Try this
I'll try it later. Should work now properly thanks. Probably better solution than mine with common events. Mine work without script but requires additional work on new maps. This one might work everywhere.

Original thread: https://forums.rpgmakerweb.com/threads/common-event-on-level-up.140908/