Conditional Troop Groups on Map Script [XP]

Started by ArcaneAlchemy, June 26, 2014, 01:26:17 am

Previous topic - Next topic

ArcaneAlchemy

Conditional Troop Encounters
Authors: ArcaneAlchemy
Version: 1
Key Term: Player / Party / Troop Add-on



Introduction

This little script is helpful if you want to easily add, remove, clear, or change a group of troops on
and given map. Maybe monsters get stronger at night, they are there until a mission is done, ect.
Pretty basic, but helpful for random battle maps.


Features


  • Change the Troops on a map based on conditions

  • Use and access pre-defined troop groups easily

  • Add, Remove, or Clear troops on the fly




No Screenshots Available



No Demo



Script
Spoiler: ShowHide

module Troop_Swap
 
module_function
#===============================================================================
# By ArcaneAlchemy
#
# * SCRIPT CALLS
 
  # clears the troop array and replaces it with a user provided troop preset.
  #     Troop_Swap.swap(list_index)
  #
  # clears the troops on the current map
  #     Troop_Swap.no_troops
  #
  #adds a troop on current map if it is not already included.
  #     Troop_Swap.add_troop(troop_id)
  #
  #deletes a troop on current map if it is included in the list
  #     Troop_Swap.del_troop(troop_id)
  #
  #lists the troops currently on the map by Troop ID #
  #     Troop_Swap.list_troops
 
#-------------------------------------------------------------------------------
  #Configure your pre-defined troop lists below.
  #Make sure to use Troop ID and not Enemy ID
  #
  #EXAMPLE: I want the troops 1, 2, and 3 in my preset. Since I already have
  #"1" taken, I'll make my list as follows:
  #
  # 2 => [1,2,3]
  #
  #   Assuming I want to test this out...
  #I can then make an event that calls the script as follows:
  #
  #     Troop_Swap.swap(2)
  #
  #This will swap out our newly defined troop list on the current map.
  #This setting will only last until returning to the map. You can ofcourse
  #easily make this redundant if needed with events.
 
  ALTERNATE_TROOP_LIST = {
  1 => [10,11,12]
  }
 
#===============================================================================
  #clears the troop array and replaces it with a user provided troop preset.
  def swap(list_index)
    $game_map.encounter_list.clear
    for i in 0..ALTERNATE_TROOP_LIST[list_index].size - 1
      $game_map.encounter_list.push ALTERNATE_TROOP_LIST[list_index][i]
    end
  end
 
  #clears the troops on the current map
  def no_troops
    $game_map.encounter_list.clear
  end
 
  #adds a troop on current map if it is not already included.
  def add_troop(troop_id)
    if $game_map.encounter_list.include? troop_id
    else
      $game_map.encounter_list.push troop_id
      $game_map.encounter_list.compact!
    end
  end
 
  #deletes a troop on current map if it is included in the list
  def del_troop(troop_id)
    if $game_map.encounter_list.include? troop_id
      $game_map.encounter_list.delete(troop_id)
    else
    end
  end
 
  #lists the troops currently on the map by ID #
  def list_troops
  a = $game_map.encounter_list

  a.each { |x| print(x) }
  end

end



Really doesn't change much so it should be compatible with anything.



Thanks to Chaos Project for all of the great scripts I use. Just trying to give back a little.



"Wait? Do I look like a waiter?" -Kefka

KK20

Can't be databased in its current state.

You don't have to always do if-else. This

    if $game_map.encounter_list.include? troop_id
    else
      $game_map.encounter_list.push troop_id
      $game_map.encounter_list.compact!
    end

can look like this

    if !$game_map.encounter_list.include? troop_id
      $game_map.encounter_list.push troop_id
      $game_map.encounter_list.compact!
    end

Also, there really is no need to check if an element exists in the array since you're not doing anything extra:

  def del_troop(troop_id)
    $game_map.encounter_list.delete(troop_id)
  end

Interesting idea (and pretty common in some games). I take it you have to have like an autorun event on each map to make these script calls when a switch is on or something?





   


   
   


   
   

Other Projects
RPG Maker XP AceUpgrade RMXP to RMVXA performance!
XPA TilemapTilemap rewrite with many features, including custom resolution!



Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

ArcaneAlchemy

Yeah, I mean you can set it by switches and what not as well. I COULD set them by map id and bypass the db but this was like a 20 minute idea for my little nephew.

As far as the "else" statements, I was using them for print() messages to see if I got the undesired result. Also, as for the include? thing, I'm not sure if it would throw an error if the id didn't exist. Maybe not. Anyway, I'll likely add to this at some point when I'm done organizing my socks lol.
"Wait? Do I look like a waiter?" -Kefka