RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
Random enemy parties

0 Members and 1 Guest are viewing this topic.

**
Rep: +0/-0Level 68
RMRK Junior
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: [Select]
#==============================================================================
# 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: http://usuarios.multimania.es/kisap/english_list.html
#==============================================================================
 
=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

*****
my name is Timothy what's yours
Rep:
Level 79
Hello
2014 Best IRC Quote2014 Zero to Hero2014 Most Missed Member2012 Zero To HeroSecret Santa 2012 ParticipantContestant - GIAW 9For frequently finding and reporting spam and spam bots2011 Zero to Hero
You should really alias Game_Enemy#initialize. That's my major concern with this code. I'm sure there are other ways to optimize the script, but it looks pretty good as is.
Aliasing is the best thing ever ^_^
it's like a metaphor or something i don't know

**
Rep: +0/-0Level 68
RMRK Junior
You should really alias Game_Enemy#initialize. That's my major concern with this code. I'm sure there are other ways to optimize the script, but it looks pretty good as is.
Aliasing is the best thing ever ^_^

I always do that, is a mistake, i will update it later.

****
Hey... my name's... Sashikinaroji...
Rep:
Level 83
fear me...
Aliasing is the best thing ever ^_^

... Except when photoshopping.  :V
Ok, DON'T EXPECT HELP FROM ME~! I will perhaps rant a bit, but don't expect me to do graphics for you, even if I say I will... I won't.

*****
my name is Timothy what's yours
Rep:
Level 79
Hello
2014 Best IRC Quote2014 Zero to Hero2014 Most Missed Member2012 Zero To HeroSecret Santa 2012 ParticipantContestant - GIAW 9For frequently finding and reporting spam and spam bots2011 Zero to Hero
Aliasing is the best thing ever ^_^

... Except when photoshopping.  :V
Quiet Naroji, scripters are talking. :V
it's like a metaphor or something i don't know

*
Rep: +0/-0Level 66
RMRK Junior
I'm having serious problems getting this script to work.  I posted looking for help on Chaos Project but haven't heard anything yet, so I'm posting here hoping someone knowledgeable will be able to help me out.

I have two maps, map 6 is the main map and map 2 is submap (a cave on map 6).  Map 6 has troop1 as the only random encounter and Map 2 has troop2 as the only random encounter.  Here is how I have the troops in the class:

module Wep
  Random_enemies = {
    :troop1 => {
      :maps_ids => [6],
      :enemies_appear => [[1,8, false,false], [2,5, false, false], [3,3, false, false]],
      :defined_positions => 1,
      :max_enemies => 5,
      :min_enemies => 1,
    },
    :troop2 => {
      :maps_ids => [2],
      :enemies_appear => [[1,5,false,false],[5,4,false,false],[6,2,false,false],[7,3,false,false],[8,3,false,false]],
      :defined_positions => 2,
      :max_enemies => 5,
      :min_enemies => 1,
    }
  }
end

This works fine on map 6 when I only have troop1 defined.  I will only get random groups from 1-5 monsters in the positions I set for troop1 on the database tab for troops.  Once I add the definition for troop2, the random encounters on map 6 get all messed up.  I will now get as many as 8 monsters, and it will use positions from BOTH troop1 and troop2.  It's almost like it is trying to run both troops on map 6 in the same battle.  Although I will get up to 8 monsters, it never uses monsters 5,6,7, or 8, which are only defined for troop2.

If I get into a battle on map 2 instead, the script crashes, claiming "argument error occurred.  wrong number of arguments (2 for 7) on the following line in the script:

@enemies.push(Game_Enemy.new(troop_id, i))
The line is near the middle of the setup method.

Can anyone help me out here?  This is just killing me that I can't get this right and this is probably the most important script to me!  Thanks.

Can someone explain what I am doing wrong?

**
Rep: +0/-0Level 68
RMRK Junior
Nothing, they are bugs. I readed at chaos but i forget that. I will fix the script when i can and study your secobnd problem.