Chaos Project

RPG Maker => RPG Maker Scripts => RMXP Script Database => Topic started by: gerrtunk on July 14, 2011, 10:37:29 am

Title: [XP] Random enemy parties
Post by: gerrtunk on July 14, 2011, 10:37:29 am
Random enemy parties
Authors: gerrtunk
Version: 1
Type: Battle Add-on
Key Term: Battle Add-on



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


Features

You define a max, min, and the appear rate of each type of enemy in a set of maps, and
the rest is random. You also configure the battlers positions.


Screenshots
No.


Demo
No.


Script

Spoiler: ShowHide
[

#==============================================================================
# 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





Instructions
In the script.


Compatibility
Any other enemy troop script.


Credits and Thanks
No.


Author's Notes

I will add more things when i need them in my projects(or i have time), so it will be updated. Again, feedback, bugs,retc, i will listen.
Title: Re: [XP] Random enemy parties
Post by: LosZapatos on July 31, 2011, 04:32:32 am
I have an issue...

Script 'Random Enemies Parties' line 223: ArgumentError occurred.
wrong number of arguments(2 for 7)

Anything I'm doing wrong? And does the troop1 above :maps_ids mean anything particular? (I think I understand that :defined_positions represents the troop id in the database for how the enemy(ies) will be position and looks)

  Random_enemies = {
    :troop1 => {
      :maps_ids => [1,2,3],
Title: Re: [XP] Random enemy parties
Post by: TheMajesticYak on August 21, 2011, 09:03:43 pm
I'm having real problems getting this script to work once I add a second enemy troop set.  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.  Although I will get up to 8 monsters, it never uses monsters 5,6,7, or 8, which are only defined for troop2.

Can someone explain what I am doing wrong?
Title: Re: [XP] Random enemy parties
Post by: gerrtunk on September 18, 2011, 04:24:30 pm
nothing, its a bug, i will patch it.
Man i forgot to correct that bug three times at least!  :shy: