How do I trigger a script when a hero reaches a certain level?

From OHRRPGCE-Wiki
Jump to navigation Jump to search

There's no script trigger specifically for a hero gaining a level, so you will need to do the check yourself in the right place, using the hero levelled script command. There are two cases in which a hero might gain a level: because the player won a battle, or due to a script command such as give experience.

Use an after-battle script to check whether the hero levelled. Each map has its own after-battle script, so set the same script as the after-battle script on all maps.

Let's say you want to see if hero Bob has just reached level 10:

plotscript, check level up, begin
  variable(hero)
  hero := find hero(hero:Bob)
  if (hero levelled(hero)) then (
    # OK, Bob just gained at least one level... did they gain level 10?
    # Check if they're level 10 or higher, and weren't before.
    # If we never heroes never gained more than one level per battle, we could just
    # check "get hero level(hero) == 10" instead.
    if (get hero level(hero) >= 10 && get hero level(hero) -- hero levelled(hero) < 10) then (
      # Stuff that should happen...
      show textbox(42)
    )
  )
end

If you use any command such as give experience, just call the check level up script immediately afterwards.