Help - Search - Members - Calendar
Full Version: Easy "Random Troops in Battle"-Script
RPG RPG Revolution Forums > Scripting > Script Tutorials > RGSS2
54tan666
Functions:
- defines a "trigger"-troop which activates the script when the battle starts
- defines which troops appear when the script has been activated
- turn the script off by using switches
CODE
module ENE
Mi_Troop = {
    #Example
    1 => 3     # a => b    a = "trigger-troop"     b = the following troops which shall appear (in the example troop 1 to troop 3) *look at the picture
  }
  SwitchTroopOff = 1    #with that switch you (de)aktivate the script (false/off = script activated)
end

Click to view attachment
Copy that and paste it above main

CODE
  def setup(troop_id)
    if ENE::Mi_Troop.has_key?(troop_id) and $game_switches[ENE::SwitchTroopOff] == false
      t_id = (rand(ENE::Mi_Troop[troop_id]) + troop_id)
    else
      t_id = troop_id
    end
    # Set array of enemies who are set as troops
    @enemies = []
    troop = $data_troops[t_id]
    for i in 0...troop.members.size
      enemy = $data_enemies[troop.members[i].enemy_id]
      if enemy != nil
        @enemies.push(Game_Enemy.new(t_id, i))
      end
    end
  end


This you have to copy and replace it in Game_Troops with the method "setup(troop_id)" on line 41.


-------------------------------------------
Thats my first little selfmade "scrpt" i'm posting here and i know, my description is very bad. Thats because im from swiss and therefore im not so good in english.
Plz comment if you have any questions or you like it (or dont like it.)
Night_Runner
Welcome to the wonderful world of scripting smile.gif

If you tweak that second section of code to:

CODE
class Game_Troops
  def setup(troop_id)
    if ENE::Mi_Troop.has_key?(troop_id) and $game_switches[ENE::SwitchTroopOff] == false
      t_id = (rand(ENE::Mi_Troop[troop_id]) + troop_id)
    else
      t_id = troop_id
    end
    # Set array of enemies who are set as troops
    @enemies = []
    troop = $data_troops[t_id]
    for i in 0...troop.members.size
      enemy = $data_enemies[troop.members[i].enemy_id]
      if enemy != nil
        @enemies.push(Game_Enemy.new(t_id, i))
      end
    end
  end
end


Then you can paste it above main, with that same bit of customisation code you have in the first codebox.

Otherwise, thanks for submitting, it looks useful smile.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2013 Invision Power Services, Inc.