how enemy targeting works?

● ARCHIVED · READ-ONLY
Started by kairi_key 3 posts View original ↗
  1. I tried to look it up in the script editor but I don't understand it, lol, so I need some explaining on these topics...
    - how enemy choose its target?
    - how random target skills work?
    - how is tgr related to all of it?
  2. This is the piece of code that determine the random target from Game_Unit
    Code:
      def random_target
        tgr_rand = rand * tgr_sum
        alive_members.each do |member|
          tgr_rand -= member.tgr
          return member if tgr_rand < 0
        end
        alive_members[0]
      end
    The target selection will be something like roulette wheel selection, where the highest tgr value battler will have a chance to be targeted more. Here are the breakdowns:
    • rand = will generate a number between 0 to 1. The generated number will be something like 0.234, 0.563, 0.876, etc
    • tgr_sum = sum of tgr of all battle members
    • tgr_rand = rand * tgr_sum means, it's like selecting a random selection point. Where the value will be ranged from 0 to tgr_sum
    • next: the code will iterate all "alive_battlers" one by one. Each iteration will reduce tgr_rand value by current iterated battler's tgr value. If the value reached 0, the current iterated battler will be the one is targeted. Otherwise, it will be the battler in index 0
  3. I see...
    so it's more like a battler who has high tgr will have high friction in this random speed roulette.

    thanks I think I get it now.