[XP] Per-Actor Battle Position

Started by Fantasist, March 16, 2010, 06:11:47 am

Previous topic - Next topic

Fantasist

March 16, 2010, 06:11:47 am Last Edit: March 16, 2010, 06:15:22 am by Mad Scientist Fantasist
Per-Actor Battle Position
Authors: Fantasist
Version: 1.0
Type: Battle Strategy Improvement
Key Term: Actor Add-on



Introduction

This script allows you a finer degree of control over the position during battle (i.e, the "Front", "Middle", "Rear" settings). You normally set positions to actor classes, not the actors themselves. With this script, you can decide the battle positions of individual actors. You can also change positions in-game.
By default, there are only 3 positions: Front, Middle and Rear. With this script, you can add as many positions as you want.


Features


  • Per-actor battle position
  • Changeable in-game
  • Possible to use more than 3 positions



Screenshots

N/A


Demo

N/A


Script

Place this script below "Game_Party".
Spoiler: ShowHide

#==============================================================================
# ** Per-Actor Battle Position
#------------------------------------------------------------------------------
# by Fantasist
# Version: 1.0
# Date: 16-Mar-2010
#------------------------------------------------------------------------------
# Version History:
#
#   1.0 - First version
#------------------------------------------------------------------------------
# Description:
#
#     This script allows you a finer degree of control over the position during
#   battle ("Front", "Middle", "Rear"). You normally set positions to actor
#   classes and not actors themselves. With this script, you can decide the
#   battle positions of individual actors. You can also change positions in-game.
#     By default, there are only 3 positions: Front, Middle and Rear. With this
#   script, you can add as many positions as you want.
#------------------------------------------------------------------------------
# Compatibility:
#
#    - Aliased Game_Actor::setup(actor_id)
#    - Rewritten Game_Party::random_target_actor(hp0)
#
#   Not tested extensively, but should work with most other scripts.
#------------------------------------------------------------------------------
# Instructions:
#
#   Place this script below "Game_Party".
#     Optionally, I suggest you configure the battle position in the database
#   anyway, despite using this script. This is because if an actor's position is
#   not configured, this script used the database setting for the actor's class.
#
#   To change an actor's position in-game, use the following script call:
#
#       $game_actors[<ACTOR_ID>].position = <POSITION>
#------------------------------------------------------------------------------
# Configuration:
#
#     Scroll down a bit for the configuration.
#
#   1. MAX_POSITION: The number of positions you will be using (Default: 3)
#
#   2. Look for:
#   #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#   # * CONFIG START
#   #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#   Then add more lines as needed. The format is:
#
#         when <ACTOR_ID> then <POSITION>
#------------------------------------------------------------------------------
# Regarding the value of Position:
#
#   POSITION takes the values from 1 to MAX_POSITION (Default: 1, 2 or 3)
#   The larger the number, the farther the position, so 1 is front and
#   MAX_POSITION if rear. During the config or setting position in-game, if you
#   set it to 0, the database position will be used. Every other out of range
#   value (like -1, -23, 100, 4, 5 for the default) will be corrected.
#------------------------------------------------------------------------------
# Issues:
#
#   None known.
#------------------------------------------------------------------------------
# Credits and Thanks:
#
#   Credits: Fantasist for making this.
#   Thanks: Zydragon and MeVII for requesting.
#------------------------------------------------------------------------------
# Notes:
#
#     If you have any questions, suggestions or comments, you can
#   find me (Fantasist) in the forums at:
#
#    - www.chaos-project.com
#
#   Enjoy ^_^
#==============================================================================

#==============================================================================
# ** Fantasist's Configuration Module
#==============================================================================
module FTSConfig
 
 MAX_POSITION = 3 # Maximum number of positions
 
 def self.per_actor_position(actor_id)
   position = case actor_id
   #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
   # * CONFIG START
   #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
   # when <actor_id> then <position>
   when 1 then 1
   when 2 then 1
   when 7 then 3
   when 8 then 2
   #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
   # * CONFIG END
   #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
   else
     0
   end
   return position
 end
end
#==============================================================================
# ** Game_Actor
#==============================================================================
class Game_Actor
 attr_reader :position
 #--------------------------------------------------------------------------
 # * Setup
 #--------------------------------------------------------------------------
 alias per_actor_pos_actor_setup setup
 def setup(actor_id)
   # Get actor position from config
   self.position = FTSConfig.per_actor_position(actor_id)
   per_actor_pos_actor_setup(actor_id) # Call everything else
 end
 #--------------------------------------------------------------------------
 # * Position=
 #--------------------------------------------------------------------------
 def position=(val)
   # If not configured, set default
   if val == 0
     actor = $data_actors[actor_id]
     actor_class = $data_classes[actor.class_id]
     # Correct the default (poaition starts with 0) to comply with
     # the new convention (starts with 1)
     val = $data_classes[@class_id].position + 1
   end
   # Correction
   val = FTSConfig::MAX_POSITION if val > FTSConfig::MAX_POSITION
   val = 1 if val < 0
   @position = val
 end
end
#==============================================================================
# ** Game_Party
#==============================================================================
class Game_Party
 #--------------------------------------------------------------------------
 # * Random Selection of Target Actor
 #--------------------------------------------------------------------------
 def random_target_actor(hp0 = false)
   roulette = []
   actors.each {|actor|
   next unless (!hp0 && actor.exist?) || (hp0 && actor.hp0?)
   position = actor.position
   # Larger the number (n), more to the front
   n = FTSConfig::MAX_POSITION + 2 - position
   n.times {roulette.push(actor)}
   }
   return nil if roulette.size == 0
   return roulette[rand(roulette.size)]
 end
end



Instructions

Place this script below "Game_Party".

Optionally, I suggest you configure the battle position in the database anyway, despite using this script. This is because if an actor's position is not configured, this script used the database setting for the actor's class.

To change an actor's position in-game, use the following script call:
$game_actors[<ACTOR_ID>].position = <POSITION>



Configuration


  • MAX_POSITION: The number of positions you will be using (Default: 3)
  • Look for:

#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# * CONFIG START
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::


Then add more lines as needed. The format is:
when <ACTOR_ID> then <POSITION>


Regarding the value of Position:

POSITION takes the values from 1 to MAX_POSITION (Default: 1, 2 or 3). The larger the number, the farther the position, so 1 is front and MAX_POSITION if rear.
During the config or setting position in-game, if you set it to 0, the database position will be used. Every other out of range value (like -1, -23, 100, 4, 5 for the default) will be corrected.


Compatibility

- Aliased Game_Actor::setup(actor_id)
- Rewritten Game_Party::random_target_actor(hp0)

Not tested extensively, but should work with most other scripts.


Credits and Thanks

Credits: Fantasist for making this.
Thanks: Zydragon and MeVII for requesting.


Author's Notes

Maybe a future version will feature a scene where you can set your battle positions without using script calls.

If you have any questions, suggestions or comments, you can find me (Fantasist) in the forums at:

- www.chaos-project.com

Enjoy ^_^
Do you like ambient/electronic music? Then you should promote a talented artist! Help out here. (I'm serious. Just listen to his work at least!)


The best of freeware reviews: Gizmo's Freeware Reviews




Jragyn

This is like that one KGC Script, but better!
http://ytomy.sakura.ne.jp/tkool/rpgtech/php/tech.php?tool=XP&cat=tech_xp/battle_system&tech=rank_concept


Its in english!
It enables more than 3 settings!
Its made by a person with 'mad scientist' in their name!

These three things are what I think makes this script great.
gj.


--JeR
A bright light can either illuminate or blind, but how will you know which until you open your eyes?

Fantasist

Thank you :)
Hm, how about submitting this to Tons?

QuoteIts made by a person with 'mad scientist' in their name!

<3
Do you like ambient/electronic music? Then you should promote a talented artist! Help out here. (I'm serious. Just listen to his work at least!)


The best of freeware reviews: Gizmo's Freeware Reviews




Sase

Can you test if this works with RTAB? I don't have a clean RTAB install on my pc atm (a project with RTAB+RTP with no edits)

Fantasist

Sorry mate, neither do I.

PS:
Quote from: My signatureStopped using RMXP until further notice.
Do you like ambient/electronic music? Then you should promote a talented artist! Help out here. (I'm serious. Just listen to his work at least!)


The best of freeware reviews: Gizmo's Freeware Reviews




Sase

Quote from: Mad Scientist Fantasist on March 17, 2010, 11:09:04 am
Sorry mate, neither do I.
You scripted this piece without using RMXP at all? :o

Blizzard

It's not like that's a big problem. xD
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Holyrapid

This is intersting. If i don´t end up using BABS in my game, i´ll propably use this. Also, nice to see Sase is back here. :)

Fantasist

@Sase: I meant RTAB! >.< I don't have RTAB to test it out.
Do you like ambient/electronic music? Then you should promote a talented artist! Help out here. (I'm serious. Just listen to his work at least!)


The best of freeware reviews: Gizmo's Freeware Reviews




Sase

Well since you also quoted your signature saying you don't use RPGXP anymore, I just made a quick assumption : p

Fantasist

I meant that I'm no longer actively interested in RMXP or scripting :)
Do you like ambient/electronic music? Then you should promote a talented artist! Help out here. (I'm serious. Just listen to his work at least!)


The best of freeware reviews: Gizmo's Freeware Reviews