Last Fighter XP

Last Fighter XP
(Standard Battle System) Version: 1.0.0
By: Kyonides-Arkanthos
alias Kyonides, Shadowball

Introduction

Simple Plug 'n' Play script.

One of your heroes won't fight against the enemies unless all other heroes are dead already.

Features

Read my comments included in the script...

Screenshots

There's no way you may notice how it works unless you play a demo...

Demo

Pending...

Script

script Spoiler
  1. =begin
  2.   Last Fighter XP
  3.   (Standard Battle System Version)
  4.   by Kyonides-Arkanthos alias Kyonides, Shadowball
  5.   v 1.0.0 - 02.10.2010 (BETA 3)
  6.   v 1.0.0 - 02.08.2010 (BETA 2)
  7.   v 1.0.0 - 02.07.2010 (BETA 1)
  8.  
  9.   A Game_Party & Scene_Battle Mod
  10.  
  11.   Plug n Play
  12.  
  13.   FEATURES (6)
  14.  
  15.   1. The Last Fighter won't fight against their enemies unless all other
  16.   Party Members are officially DEAD.
  17.  
  18.   2. You can change who the Last Fighter should be here in the Script Editor or
  19.   from an event by calling the script like this:
  20.  
  21.   LastActor.new = 2
  22.  
  23.   You may choose a number (-1 to 3), -1 means all Party Members should fight.
  24.  
  25.   3. The Last Fighter will defend himself / herself if you want him/her to do so
  26.  
  27.   # He or She will be guarding...
  28.   ID = [0, true]
  29.   # or
  30.   LastActor.guard = true
  31.  
  32.   # He or She won't be guarding...
  33.   ID = [0, nil]  
  34.   # or
  35.   LastActor.guard = nil
  36.  
  37.   4. Now the Actor Command Window will show a unique customized Skills term for
  38.      every single party member.
  39.      
  40.      Just edit the ClassID Hash as you wish.
  41.  
  42.      It comes with the 8 basic Hero classes, but you can edit it at will
  43.      depending on how many Hero Classes do you created in the Classes Tab
  44.      in the Database Window.
  45.  
  46.  
  47.   "1 Turn Only" Features :
  48.  
  49.   5. AutoFight : All fighters deal physical damage semi-automatically
  50.  
  51.   6. AutoSkill : All fighters use a randomly selected skill if possible.
  52.   Otherwise they'll just deal physical damage to the enemy
  53. =end
  54. module LastActor
  55.   # EDIT THIS VALUE, it must be an Integer (-1 to 3)
  56.   # -1 means All Party Members Will Fight
  57.   # true - PM will protect himself or herself just in case s/he is attacked
  58.   # nil  - Party Member will not protect himself
  59.   ID = [3, true]
  60.  
  61.   Tecnicas = 'Tecnicas'
  62.  
  63.   ClassID = {
  64.     1 => Tecnicas,    2 => Tecnicas,     3 => Tecnicas,
  65.     4 => 'Artimañas', 5 => Tecnicas,     6 => Tecnicas,
  66.     7 => 'Magias',    8 => 'Hechicerias'
  67.   }
  68.  
  69.   def self.new=(index);   ID[0] = index end
  70.  
  71.   def self.guard=(state); ID[1] = state end
  72. end
  73.  
  74. class Game_Party
  75.   attr_reader :others
  76.   alias :kyon_lastman_gm_py_ssm :setup_starting_members
  77.   def setup_starting_members
  78.     @others = [] # Array of all party members but the last standing man
  79.     kyon_lastman_gm_py_ssm
  80.     for actor in @actors
  81.       @others.push actor if actor != @actors[LastActor::ID[0]]
  82.     end
  83.   end
  84.  
  85.   def last_actor; @actors.size-1 end
  86.  
  87.   def others_dead?
  88.     if $game_party.others.size == 0
  89.       return false # If number of other party members is 0
  90.     end
  91.     for actor in @others
  92.       if actor.hp > 0
  93.         return false # If an actor is in the party with 0 or more HP
  94.       end
  95.     end
  96.     return true # All other members are dead
  97.   end
  98. end
  99.  
  100. class Window_Command
  101.   attr_accessor :commands
  102.   # This method replaces the generic Skills command name with a customized one
  103.   # You may replace it by calling the script like this...
  104.   #   @actor_command_window.commands[1] = 'Spells'
  105. end
  106.  
  107. class Window_PartyCommand < Window_Selectable
  108.   def initialize
  109.     x = 320 - (520 / 2)
  110.     super(x, 0, 520, 64)
  111.     self.contents = Bitmap.new(width - 32, height - 32)
  112.     self.back_opacity = 160
  113.     @commands = ['Fight', 'AutoFight', 'AutoSkill','Escape']
  114.     @item_max = @commands.size
  115.     @column_max = @commands.size
  116.     [0,1,2].each {|index| draw_item(index, normal_color)}
  117.     draw_item(3, $game_temp.battle_can_escape ? normal_color : disabled_color)
  118.     self.active = false
  119.     self.visible = false
  120.     self.index = 0
  121.   end
  122.  
  123.   def draw_item(index, color)
  124.     self.contents.font.color = color
  125.     rect = Rect.new(index * 120 + 4, 0, 116 - 10, 32)
  126.     self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  127.     self.contents.draw_text(rect, @commands[index], 1)
  128.   end
  129.  
  130.   def update_cursor_rect
  131.     self.cursor_rect.set(index * 120, 0, 128, 32)
  132.   end
  133. end
  134.  
  135. class Scene_Battle
  136.   def update_phase2
  137.     if Input.trigger?(Input::C)
  138.       # Branch by party command window cursor position
  139.       case @party_command_window.index
  140.       # Fight, AutoFight, AutoSkill - Heroes deal physical damage only (1 turn)
  141.       when 0, 1, 2
  142.         $game_system.se_play($data_system.decision_se) # Play decision SE
  143.         start_phase3 # Start actor command phase
  144.       when 3 # Escape
  145.         if $game_temp.battle_can_escape == false # If it's impossible to escape
  146.           $game_system.se_play($data_system.buzzer_se) # Play buzzer SE
  147.           return
  148.         end
  149.         $game_system.se_play($data_system.decision_se) # Play decision SE
  150.         update_phase2_escape # Escape processing
  151.       end
  152.       return
  153.     end
  154.   end
  155.  
  156.   def start_phase3
  157.     @phase = 3 # Shift to phase 3
  158.     @actor_index = -1 # Set actor as unselectable
  159.     @active_battler = nil
  160.     # Go to command input for next actor if player selected Fight command
  161.     # otherwise all actors will deal physical damage only or use a skill instead
  162.     case @party_command_window.index
  163.     when 0;  phase3_next_actor
  164.     when 1;  phase3_all_actors(:fight)
  165.     when 2;  phase3_all_actors(:skill)
  166.     end
  167.   end
  168.  
  169.   def phase3_all_actors(attack_or_skill) # AutoFight method call
  170.     all_active_battlers(attack_or_skill)
  171.     @party_command_window.active = false
  172.     @party_command_window.visible = false
  173.   end
  174.  
  175.   def phase3_next_actor # Normal Fight method call
  176.     all_active_battlers(:actor_command)
  177.     phase3_setup_command_window
  178.   end
  179.  
  180.   def all_active_battlers(index)
  181.     begin
  182.       if index == :actor_command and @active_battler != nil
  183.         @active_battler.blink = false # Actor blink effect OFF
  184.       end
  185.       # If index is equal to last man standing and that actor is the last one
  186.       # in the list and other party members are alive, let them fight!
  187.       if (@actor_index == LastActor::ID[0]-1 and
  188.         LastActor::ID[0] == $game_party.last_actor and
  189.         !$game_party.others_dead? and LastActor::ID[1].nil?) or
  190.         @actor_index == $game_party.last_actor # If last actor
  191.         start_phase4 # Start main phase
  192.         return
  193.       end
  194.       # Advance actor index
  195.       @actor_index += 1
  196.       @active_battler = $game_party.actors[@actor_index]
  197.       @active_battler.blink = true if index == :actor_command
  198.       if index != :actor_command
  199.         # AutoFight: All active members should fight
  200.         if index == :fight
  201.           @active_battler.current_action.kind = 0
  202.           action = @actor_index != LastActor::ID[0] ? 0 : 1
  203.           @active_battler.current_action.basic = action
  204.         # AutoSkill: all members should use a skill
  205.         elsif index == :skill
  206.           autoselect_skill # Check if battler can use any skill
  207.         end
  208.         index = rand($game_troop.enemies.size)
  209.         @active_battler.current_action.target_index = index
  210.       end
  211.     end until @active_battler.inputable?
  212.   end
  213.  
  214.   alias :kyon_lastman_battle_up_ph3 :update_phase3
  215.   def update_phase3
  216.     phase3_all_actors(:fight) if @party_command_window.index == 1
  217.     phase3_all_actors(:skill) if @party_command_window.index == 2
  218.     kyon_lastman_battle_up_ph3
  219.   end
  220.  
  221.   def autoselect_skill
  222.     for skill in @active_battler.skills
  223.       next if !@active_battler.skill_can_use? skill
  224.       @skill_id = skill
  225.       break
  226.     end
  227.     @active_battler.current_action.kind  = !@skill_id.nil? ? 1 : 0
  228.     @active_battler.current_action.basic = 0 if @skill_id.nil?
  229.     @active_battler.current_action.skill_id = @skill_id if !@skill_id.nil?
  230.   end
  231.   # This method replaces the generic Skills command name with a customized one
  232.   alias :kyon_lastman_battle_ph3_scw :phase3_setup_command_window
  233.   def phase3_setup_command_window
  234.     class_id = $game_party.actors[@actor_index].class_id
  235.     @actor_command_window.commands[1] = LastActor::ClassID[class_id]
  236.     @actor_command_window.refresh
  237.     kyon_lastman_battle_ph3_scw
  238.   end
  239. end
Expand to see the code.


Instructions

Plug 'n' Play script

Edit the ID constant inside LastActor module to select which hero will rest during battles unless all other heroes are dead already.

Accepted party members index values: -1 to 3.

-1 means All Party Members should fight against the enemies.

You can change it at any time from a script call, e.g.

LastActor.new = 1

Here's another way to explain what this script does...

The index is the $game_party.actors index (0 to 3), but if you want all party members to fight against the enemies, then choose -1 to make sure no one is taking a nap while the enemies are attacking you, this (-1) would be the XP's Standard Battle System normal behavior.

If you choose a specific actor not to attack or use any skill, let's say you've chosen Aluxes (the party leader at the party's position number 1), then Aluxes won't do anything unless all other party members are dead.

There are other features, so don't forget to read my comments or just test my script in any of your projects.

FAQ

None yet.

Compatibility

For XP's Standard Battle System...

Credits and Thanks

This was requested by Desbrina, but I'm not sure if he needed any other feature, too.

Author's Notes

None.

Terms and Conditions

Not intended for Commercial Use and you should include my name in your project's credits. If you want to post this script in any other forum, then send me an email or pm first so I can take a decision...
yo, this is approved, but would you please add a demo and some more explanation as soon as possible?
just posting a script is a bit bare.. other people would like to use it too, but they have to know what it's for..
So, it's not by the actual actor, just the index?
I assume the index is the actor index... for example;

Index 0 = First in party
Index 1 = Second in party

etc. etc.

Or it's the actor in the database, so you can decide when adding them to the party.
EDIT: The first post was updated again!

The index is the $game_party.actors index (0 to 3), but if you want all party members to fight against the enemies, then choose -1 to make sure no one is taking a nap while the enemies are attacking you, this (-1) would be the XP's Standard Battle System normal behavior.

If you choose a specific actor not to attack or use any skill, let's say you've chosen Aluxes (the party leader at the party's position number 1), then Aluxes won't do anything unless all other party members are dead.

You might think that behavior is weird, but that's what Desbrina was asking for on Script Requests subforum.

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=69862