Variable Encounter Rate
#1
This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss.
No support is given. If you are the owner of the thread, please contact administration.


Normally, when RMXP selects an enemy troop for you to fight, it just selects a random troop. However, under this system modification, each troop has a different chance of being fought. To implement this system, do the following:


Add this method to the end of Game_Map:
Code:
def rand_encounter
    troops = @map.encounter_list.clone
    count = 0
    a = []
    b = []
    num = 1
    rate = 0
    x = 0
    y = 0
    z = 0
    #Generate table
    for i in troops
      if troops[i-1] == nil
        break
      end
      z = $data_troops[troops[i-1]]
      x = z.name[0].to_i
      y = z.name[1].to_i
      if x != 0
        rate = (x * 10) + y
      else
        rate = y
      end
      a[i] = count + 1
      b[i] = count + rate
      count += rate
    end
    #generate random number
    srand()
    num += rand(count)
    #check table and return results
    for i in troops
      if num >= a[i] and num <= b[i]
        return troops[i-1]
      end
    end
  end


After that, goto the Update method in Scene_Map, and find this if...then nest:
Code:
if $game_player.encounter_count == 0 and $game_map.encounter_list != []
      [...]
    end

and replace it with this:
Code:
if $game_player.encounter_count == 0 and $game_map.encounter_list != []
      # If event is running or encounter is not forbidden
      unless $game_system.map_interpreter.running? or
             $game_system.encounter_disabled
        # Confirm troop
        troop_id = $game_map.rand_encounter
        # If troop is valid
        if $data_troops[troop_id] != nil
          # Set battle calling flag
          $game_temp.battle_calling = true
          $game_temp.battle_troop_id = troop_id
          $game_temp.battle_can_escape = true
          $game_temp.battle_can_lose = false
          $game_temp.battle_proc = nil
        end
      end
    end

And then your done, sort of. To get each enemy troop a different encounter rate, place a two-digit number, from 01 to 99, in front of each troop's name. This number will determine how frequently the troop will be fought.


Example:

04 Ghost
02 Ghost*2
01 Ghost*3

In this example, the ghost troops have encounter rates of 4, 2, and 1, respectively. The troop with a single ghost is the most likely to appear, while the troop with 3 ghosts is the least likely to appear. The system adds those numbers up, generates a random number within that range, and then determines which troop to fight by comparing the number to a table with the selection range of each troop:

Troop 1: 1~4
Troop 2: 5~6
Trppp 3: 7

If the script generated a three, then troop one would be fought. But a 7 would mean troop 3 would be fought.

Hopefully, you find it useful. Let me know if you find any bugs.
}


Possibly Related Threads…
Thread Author Replies Views Last Post
  Terrain Encounter Areas SephirothSpawn 0 2,260 05-19-2006, 01:00 PM
Last Post: SephirothSpawn
  Encounter Bar makeamidget 0 2,649 05-27-2005, 01:00 PM
Last Post: makeamidget



Users browsing this thread: 1 Guest(s)