Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Random enemy parties

This script let you use random enemy parties like games like Dragon Quest. You
define a max, min, and the appear rate of each type of enemy in a set of maps, and
the rest is random.

Code:
#==============================================================================

# Random enemies parties

# By gerkrt/gerrtunk, Heretic86(Idea)

# Version: 1.0

# License: MIT, credits

# Date: 12/07/2011

# IMPORTANT NOTE: to acces the more actualitzed or corrected version of this

# script check here: [url=http://usuarios.multimania.es/kisap/english_list.html]http://usuarios.multimania.es/kisap/english_list.html[/url]

#==============================================================================

 

=begin

 

------INTRODUCTION------

 

This script let you use random enemy parties like games like Dragon Quest. You

define a max, min, and the appear rate of each type of enemy in a set of maps, and

the rest is random.

 

-------TROOPS EFFECTS---------

 

The main configuration to do is to add in Random_Enemies hash the troops effects

you need. A troop effect is a seed for a random generation in a set of maps.

 

  Random_enemies = {

    :troop1 => {

      :maps_ids => [1,2,3],

      # Put this to false if not want confiugre manually, all 50% 1-10

      :enemies_appear => false,

      :defined_positions => false,

      

      :max_enemies => 5,

      :min_enemies => 2,

    }

  }

 

:maps_ids : a list of maps ids where will have effect, in any other map it wont.

:max_enemies : to control the challengue. the max enemies to create.

:mix_enemies : to control the challengue. the min enemies to create. The number 

of enemies is generated randomly with this range.

 

You have configurated the maps where it happens and the number range, but what

about the enemies types? 

 

To do that you have to add a enemy encounter in a map thats in the maps_ids list,

for example, in the map 2. When that combat starts, the number of enemies will 

appear in a random way.

 

Note that normally all the enemies have the same % to appear in a combat, but you

can changue that using the :enemies_appear option. 

 

:enemies_appear => [[1,3, false,false], [4,5, false, false], [5,8, false, false], ],

Using this, you configure the % of appearance of each enemy, and also some of his

partydefined attributes like immortal(cant dead) and invisible.

 

[1,3, false,false]

Enemy id, % appear(1 to 10), invisible, immortal. Set false to true to make that 

the enemy have these options.

 

Anyway if just dont need that, make it =>false and they will have the same probabilities.

 

 

------ENEMIES POSITIONS---------

 

As the number of the enemies are random,  you cant use the positions in the 

database normally. You can define a set of enemy positions for each troop, in order,

to the max of the rpgmaker thats 8.

 

You can have some troubles with enemies only using a enemies positions list  

for all of them, thats why each troop can define his own positions.

  

To define the default enemies positions you have to go to troop n1 in the database

and set any up 8 enemies(or the max you will use) in the positions you like. 

The scipt will use these in the same order and for all enemies.

 

To define defined enemies you have to add this line to a troop:

:defined_positions => 4,

instead of false.

 

Then it will work like the default troop in database, but with troop id=4 this time.

Make the same thing.

  

-------USING THE DEFAULT WAY---------

 

If you go in a combat that havent defined a troop in this script, that will be loaded

like a normal one, using the database.

 

------SYNTAX--------------

 

To add new troop effects just add these each time:

 

 

    :troop2 => {

      :maps_ids => [4,5],

      # Put this to false if not want confiugre manually, all 50% 1-10

      :enemies_appear => false,

      :defined_positions => 1,

      

      :max_enemies => 8,

      :min_enemies => 5,

    },

    but updating troopX, to 3, 4, etc.

 

=end

 

module Wep

  Random_enemies = {

    :troop1 => {

      :maps_ids => [1,2,3],

      # Put this to false if not want confiugre manually, all 50% 1-10

      :enemies_appear => [[1,3, false,false], [4,5, false, false], [5,8, false, false], ],

      :defined_positions => false,

      

      :max_enemies => 5,

      :min_enemies => 2,

    },

    

    :troop2 => {

      :maps_ids => [4,5],

      # Put this to false if not want confiugre manually, all 50% 1-10

      :enemies_appear => false,

      :defined_positions => 1,

      

      :max_enemies => 8,

      :min_enemies => 5,

    }

  }

 

  

end

 

 

 

 

class Game_Enemy

  attr_reader :enemy_id

end

 

#==============================================================================

# ** Game_Troop

#------------------------------------------------------------------------------

#  This class deals with troops. Refer to "$game_troop" for the instance of

#  this class.

#==============================================================================

 

class Game_Troop

    

  #--------------------------------------------------------------------------

  # * Setup

  #     troop_id : troop ID

  #--------------------------------------------------------------------------

  def setup(troop_id)

    # Set array of enemies who are set as troops

    @enemies = []

    

    # Initialize roulette

    roulette = []

    enes_appear = []

    

    # Loop

    count = 0

    # Iterate in troops for the one of active map

    for key, value in Wep::Random_enemies

      troop = Wep::Random_enemies[key] 

      # Check it

      if troop[:maps_ids].include? $game_map.map_id

        # Save it

        used_troop = troop

        # Iterate in all enemies

        for enemy in $data_troops[troop_id].members

          #p enemy

          # Push the game enemy n times.

          n = 0

          # When default use 5

          if not troop[:enemies_appear] 

            n = 5

          else

            enes_appear = troop[:enemies_appear]

           for ene in troop[:enemies_appear]

             

             #p 'ene id ', ene[0], enemy.enemy_id

             if ene[0] == enemy.enemy_id

               n = ene[1]

             end

           end

           # A default value herE?

          end

          #p 'N', n

          n.times do

            roulette.push(enemy.enemy_id) ;# p enemy.enemy_id

    

            

        end

 

        

      end

      count+=1

      

    end

    #p roulette

    # If roulette size is 0 means that no map have been found for this effect. 

    # Then uses the normal way

    if roulette.size == 0

      #p 'normal'

      troop = $data_troops[troop_id]

      for i in 0...troop.members.size

        enemy = $data_enemies[troop.members[i].enemy_id]

        if enemy != nil

          @enemies.push(Game_Enemy.new(troop_id, i))

        end

      end

      

    # The random way 

    else

      #p 'rando'

      # Generate enemies

      # Select random enemy until max and starting in min

 

      val = 0

      

      val = rand(troop[:max_enemies])

      val = troop[:min_enemies] if val < troop[:min_enemies]

      val = troop[:max_enemies] if val > troop[:max_enemies]

      

      count = 0

      for i in 0..val

        #p 'times',i, val, $data_troops

        if used_troop[:defined_positions] 

          j = [used_troop[:defined_positions]][0]

          #p 'defined', [used_troop[:defined_positions]][0], i

          x = $data_troops[j].members[count].x

          y = $data_troops[j].members[count].y

        else

          #p 'default'

          x = $data_troops[1].members[count].x

          y = $data_troops[1].members[count].y

        end    

        #x = arr[count][:x]

        #y = arr[count][:y]

        ene = roulette[rand(roulette.size)]

        for eneapp in enes_appear

          if eneapp[0] == ene

            hidd = eneapp[2]

            imm = eneapp[3]

          end

        end

        # Troop_id, member index

        @enemies.push(Game_Enemy.new(troop_id, i, ene, hidd, imm, x, y))

         count +=1

      end

   

    end

  end

 end

end

 

#==============================================================================

# ** Game_Enemy

#------------------------------------------------------------------------------

#  This class handles enemies. It's used within the Game_Troop class

#  ($game_troop).

#==============================================================================

 

class Game_Enemy < Game_Battler

  #--------------------------------------------------------------------------

  # * Object Initialization

  #     troop_id     : troop ID

  #     member_index : troop member index

  #--------------------------------------------------------------------------

  def initialize(troop_id, member_index, enemy_id, hidden, immortal, x, y)

    super()

    @troop_id = troop_id

    @member_index = member_index

    troop = $data_troops[@troop_id]

    @enemy_id = enemy_id

    enemy = $data_enemies[@enemy_id]

    @battler_name = enemy.battler_name

    @battler_hue = enemy.battler_hue

    @hp = maxhp

    @sp = maxsp

    @x = x

    @y = y

    @hidden = hidden

    @immortal = immortal

  end

    #--------------------------------------------------------------------------

  # * Get Battle Screen X-Coordinate

  #--------------------------------------------------------------------------

  def screen_x

    return @x

  end

  #--------------------------------------------------------------------------

  # * Get Battle Screen Y-Coordinate

  #--------------------------------------------------------------------------

  def screen_y

    return @y

  end

  #--------------------------------------------------------------------------

  # * Get Battle Screen Z-Coordinate

  #--------------------------------------------------------------------------

  def screen_z

    return screen_y

  end

end
 
You know what... I thought of something remotely like this, even quite a while ago... that was when I had no fucking clue how to script anything, and I never thought of it again. Now you made it, and while I personally don't use RM anymore, I wonder how everyone else could've lived without a script like this really... good idea!

Now for the critics... I'd really make use of the Monster Party tab if I were you, instead of creating a redundant hash or two in your script that are even harder to use. Simply follow these:
- each map ID translates to the same monster party ID
- all enemies you put in a monster party may appear in battles on that map
- the more of one enemy there is in the same monster party, the more lkely that monster is to appear
- the name of the monster party determines min and max monster amount, if not defined globally (which might probably make sense)

I can imagine that to be more awesome, easier to use and easier to maintain, as you got visual feedback on what you're doing.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top