Advertisement
neonblack

Emptive

Aug 5th, 2012
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.45 KB | None | 0 0
  1. ## Snippet created by Neon Black
  2. ## 8.5.2012
  3.  
  4. ## Mod of one of my other scripts.  Choose a variable not currently in use.
  5. ## When the player approaches the foe from the back, it is set to 1, from the
  6. ## side, it is set to 2.
  7. ## Conversely, when the event approaches the player from the back, it is set to
  8. ## -1, from the side, it is set to -2
  9.  
  10. module CP
  11. module CHASE
  12.  
  13. VARIABLE = 21
  14.  
  15. end
  16. end
  17.  
  18. module BattleManager
  19.   def self.on_encounter
  20.     @preemptive = ($game_variables[CP::CHASE::VARIABLE] == 1)
  21.     @surprise = ($game_variables[CP::CHASE::VARIABLE] == -1)
  22.     $game_variables[CP::CHASE::VARIABLE] = 0
  23.   end
  24. end
  25.  
  26. class Game_Interpreter
  27.   def command_301
  28.     return if $game_party.in_battle
  29.     if @params[0] == 0                      # Direct designation
  30.       troop_id = @params[1]
  31.     elsif @params[0] == 1                   # Designation with variables
  32.       troop_id = $game_variables[@params[1]]
  33.     else                                    # Map-designated troop
  34.       troop_id = $game_player.make_encounter_troop_id
  35.     end
  36.     if $data_troops[troop_id]
  37.       BattleManager.setup(troop_id, @params[2], @params[3])
  38.       BattleManager.event_proc = Proc.new {|n| @branch[@indent] = n }
  39.       $game_player.make_encounter_count
  40.       BattleManager.on_encounter
  41.       SceneManager.call(Scene_Battle)
  42.     end
  43.     Fiber.yield
  44.   end
  45. end
  46.  
  47. class Game_Event < Game_Character
  48.   alias cp_chase_locki lock unless $@
  49.   def lock
  50.     check_both_ev_dir
  51.     cp_chase_locki
  52.   end
  53.  
  54.   def check_both_ev_dir
  55.     sx = distance_x_from($game_player.x)
  56.     sy = distance_y_from($game_player.y)
  57.     if sx.abs > sy.abs
  58.       res = sx > 0 ? 4 : 6
  59.       ops = sx > 0 ? 6 : 4
  60.     elsif sy != 0
  61.       res = sy > 0 ? 8 : 2
  62.       ops = sy > 0 ? 2 : 8
  63.     else
  64.       res = 0; ops = 0
  65.     end
  66.     var = CP::CHASE::VARIABLE
  67.     $game_variables[var] = 0
  68.     $game_variables[var] = -1 if (@direction == res &&
  69.                                   $game_player.direction == res)
  70.     $game_variables[var] = -2 if (@direction == res &&
  71.                                   $game_player.direction != res &&
  72.                                   $game_player.direction != ops)
  73.     $game_variables[var] = 1 if (@direction == ops &&
  74.                                  $game_player.direction == ops)
  75.     $game_variables[var] = 2 if (@direction != ops &&
  76.                                  @direction != res &&
  77.                                  $game_player.direction == ops)
  78.   end
  79. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement