Posted By

mladoux on 12/25/10


Tagged

system mod RGSS RMXP Battle


Versions (?)

Xenres' Single Actor Escape


 / Published in: Ruby
 

URL: http://mark.haktstudios.com/

An escape system that allows for a single actor to escape, rather than requiring the whole party to leave the battle. This script is still buggy, but I'm working on it.

  1. =begin
  2.   Xenres' Single Actor Escape
  3.   Last Edit: 2010-08-02
  4.  
  5.   Description:
  6.   Adds single actor escape functionality to the battle system.
  7. =end
  8.  
  9. class Scene_Battle
  10. #--------------------------------------------------------------------------
  11. # * Main Processing
  12. #--------------------------------------------------------------------------
  13. def main
  14.  
  15. # Initialize each kind of temporary battle data
  16. $game_temp.in_battle = true
  17. $game_temp.battle_turn = 0
  18. $game_temp.battle_event_flags.clear
  19. $game_temp.battle_abort = false
  20. $game_temp.battle_main_phase = false
  21. $game_temp.battleback_name = $game_map.battleback_name
  22. $game_temp.forcing_battler = nil
  23.  
  24. # Initialize battle event interpreter
  25. $game_system.battle_interpreter.setup(nil, 0)
  26.  
  27. # Prepare troop
  28. @troop_id = $game_temp.battle_troop_id
  29. $game_troop.setup(@troop_id)
  30.  
  31. # Battle Menu Command List
  32. s1 = $data_system.words.attack
  33. s2 = $data_system.words.skill
  34. s3 = $data_system.words.guard
  35. s4 = $data_system.words.item
  36. s5 = "Escape"
  37.  
  38. # Display appropriate battle menu
  39. if $game_temp.battle_can_escape
  40. @actor_command_window = Window_Command.new(140, [s1, s2, s3, s4, s5])
  41. @actor_command_window.y = 140
  42. else
  43. @actor_command_window = Window_Command.new(160, [s1, s2, s3, s4])
  44. @actor_command_window.y = 160
  45. end
  46. @actor_command_window.back_opacity = 160
  47. @actor_command_window.active = false
  48. @actor_command_window.visible = false
  49.  
  50. # Make other windows
  51. @party_command_window = Window_PartyCommand.new
  52. @help_window = Window_Help.new
  53. @help_window.back_opacity = 160
  54. @help_window.visible = false
  55. @status_window = Window_BattleStatus.new
  56. @message_window = Window_Message.new
  57.  
  58. # Make sprite set
  59. @spriteset = Spriteset_Battle.new
  60.  
  61. # Initialize wait count
  62. @wait_count = 0
  63.  
  64. # Execute transition
  65. if $data_system.battle_transition == ""
  66. Graphics.transition(20)
  67. else
  68. Graphics.transition(40, "Graphics/Transitions/" +
  69. $data_system.battle_transition)
  70. end
  71.  
  72. # Start pre-battle phase
  73. start_phase1
  74.  
  75. # Main loop
  76. loop do
  77.  
  78. # Update game screen
  79. Graphics.update
  80.  
  81. # Update input information
  82. Input.update
  83.  
  84. # Frame update
  85. update
  86.  
  87. # Abort loop if screen is changed
  88. if $scene != self
  89. break
  90. end
  91. end
  92.  
  93. # Refresh map
  94. $game_map.refresh
  95.  
  96. # Prepare for transition
  97. Graphics.freeze
  98.  
  99. # Dispose of windows
  100. @actor_command_window.dispose
  101. @party_command_window.dispose
  102. @help_window.dispose
  103. @status_window.dispose
  104. @message_window.dispose
  105. if @skill_window != nil
  106. @skill_window.dispose
  107. end
  108. if @item_window != nil
  109. @item_window.dispose
  110. end
  111. if @result_window != nil
  112. @result_window.dispose
  113. end
  114.  
  115. # Dispose of sprite set
  116. @spriteset.dispose
  117.  
  118. # If switching to title screen
  119. if $scene.is_a?(Scene_Title)
  120.  
  121. # Fade out screen
  122. Graphics.transition
  123. Graphics.freeze
  124. end
  125.  
  126. # If switching from battle test to any screen other than game over screen
  127. if $BTEST and not $scene.is_a?(Scene_Gameover)
  128. $scene = nil
  129. end
  130. end
  131.  
  132. #----------------------------------------------------------------------------
  133. # Start Actor Escape
  134. #----------------------------------------------------------------------------
  135. def start_actor_escape
  136.  
  137. # Calculate enemy agility average
  138. enemies_agi = 0
  139. enemies_number = 0
  140. for enemy in $game_troop.enemies
  141. if enemy.exist?
  142. enemies_agi += enemy.agi
  143. enemies_number += 1
  144. end
  145. end
  146. if enemies_number > 0
  147. enemies_agi /= enemies_number
  148. end
  149.  
  150. # calculate success
  151. success = rand(100) > 50 * @active_battler.agi / enemies_agi
  152.  
  153. # if successful
  154. if success
  155. # Play escape SE
  156. $game_system.se_play($data_system.escape_se)
  157. # Remove actor from party
  158. $game_party.remove_actor(@active_battler.id)
  159. end
  160.  
  161. # calculate number of actors left in group
  162. actors_number = 0
  163. for actor in $game_party.actors
  164. if actor.exist?
  165. actors_number += 1
  166. end
  167. end
  168. if actors_number > 0
  169. phase3_next_actor
  170. else
  171. $game_system.bgm_play($game_temp.map_bgm)
  172. # Battle ends
  173. battle_end(1)
  174. end
  175. end
  176.  
  177. #--------------------------------------------------------------------------
  178. # * Frame Update (actor command phase : basic command)
  179. #--------------------------------------------------------------------------
  180. def update_phase3_basic_command
  181. # If B button was pressed
  182. if Input.trigger?(Input::B)
  183. # Play cancel SE
  184. $game_system.se_play($data_system.cancel_se)
  185. # Go to command input for previous actor
  186. phase3_prior_actor
  187. return
  188. end
  189. # If C button was pressed
  190. if Input.trigger?(Input::C)
  191. # Branch by actor command window cursor position
  192. case @actor_command_window.index
  193. when 0 # attack
  194. # Play decision SE
  195. $game_system.se_play($data_system.decision_se)
  196. # Set action
  197. @active_battler.current_action.kind = 0
  198. @active_battler.current_action.basic = 0
  199. # Start enemy selection
  200. start_enemy_select
  201. when 1 # skill
  202. # Play decision SE
  203. $game_system.se_play($data_system.decision_se)
  204. # Set action
  205. @active_battler.current_action.kind = 1
  206. # Start skill selection
  207. start_skill_select
  208. when 2 # guard
  209. # Play decision SE
  210. $game_system.se_play($data_system.decision_se)
  211. # Set action
  212. @active_battler.current_action.kind = 0
  213. @active_battler.current_action.basic = 1
  214. # Go to command input for next actor
  215. phase3_next_actor
  216. when 3 # item
  217. # Play decision SE
  218. $game_system.se_play($data_system.decision_se)
  219. # Set action
  220. @active_battler.current_action.kind = 2
  221. # Start item selection
  222. start_item_select
  223. when 4 # escape
  224. # Play decision SE
  225. $game_system.se_play($data_system.decision_se)
  226. # Set Action
  227. @active_battler.current_action.kind = 3
  228. # go to next actor
  229. phase3_next_actor
  230. end
  231. return
  232. end
  233. end
  234.  
  235. #--------------------------------------------------------------------------
  236. # * Frame Update (main phase step 2 : start action)
  237. #--------------------------------------------------------------------------
  238. def update_phase4_step2
  239. # If not a forcing action
  240. unless @active_battler.current_action.forcing
  241. # If restriction is [normal attack enemy] or [normal attack ally]
  242. if @active_battler.restriction == 2 or @active_battler.restriction == 3
  243. # Set attack as an action
  244. @active_battler.current_action.kind = 0
  245. @active_battler.current_action.basic = 0
  246. end
  247. # If restriction is [cannot perform action]
  248. if @active_battler.restriction == 4
  249. # Clear battler being forced into action
  250. $game_temp.forcing_battler = nil
  251. # Shift to step 1
  252. @phase4_step = 1
  253. return
  254. end
  255. end
  256. # Clear target battlers
  257. @target_battlers = []
  258. # Branch according to each action
  259. case @active_battler.current_action.kind
  260. when 0 # basic
  261. make_basic_action_result
  262. when 1 # skill
  263. make_skill_action_result
  264. when 2 # item
  265. make_item_action_result
  266. when 3 # escape
  267. start_actor_escape
  268. end
  269. # Shift to step 3
  270. if @phase4_step == 2
  271. @phase4_step = 3
  272. end
  273. end
  274. end

Report this snippet  

You need to login to post a comment.