Advertisement
TheSixth

Falcao's ABS + Kal's EventSpawner Patch by Sixth

Sep 4th, 2015
504
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 13.23 KB | None | 0 0
  1. #===============================================================================
  2. # * [ACE] Falcao's ABS + Kal's EventSpawn Patch
  3. #===============================================================================
  4. # * Made by: Sixth (www.rpgmakervxace.net, www.forums.rpgmakerweb.com)
  5. # * Version: 1.5
  6. # * Updated: 07/09/2016
  7. # * Requires: Falcao's Pearl ABS Liquid v3
  8. #             Kal's EventSpawn
  9. #-------------------------------------------------------------------------------
  10. # * < Change Log >
  11. #-------------------------------------------------------------------------------
  12. # * Version 1.0 (15/01/2015)
  13. #   - Initial release.
  14. # * Version 1.1 (28/07/2016)
  15. #   - Added compatibility with my Summon System for Falcao's ABS script.
  16. #     This is a private script, so if you are not me or the owner of the script,
  17. #     you don't have to worry about this one!
  18. # * Version 1.2 (01/08/2016)
  19. #   - Fixed events from the spawn map remaining on the current map after
  20. #     spawning an event. The spawned event, of course, will remain on the map
  21. #     like it should be.
  22. # * Version 1.3 (06/08/2016)
  23. #   - Added compatibility with Khas' Ultra Lightning System.
  24. #     Now you can summon events with lights.
  25. # * Version 1.4 (06/09/2016)
  26. #   - Added a new option which lets you restrict the spawn location based on
  27. #     region and terrain IDs.
  28. #   - Fixed the co-ordinate getter method. It will no longer try to spawn
  29. #     events outside the map's boundaries.
  30. #   - Fixed a typo in the script. This fixed an issue with my Summon System
  31. #     script (which is a private script, so don't worry about this one).
  32. # * Version 1.5 (07/09/2016)
  33. #   - Fixed a typo from the previous update which caused a game crash. >.>
  34. #-------------------------------------------------------------------------------
  35. # * < Description >
  36. #-------------------------------------------------------------------------------
  37. # * This compatibility patch will let you summon enemy events.
  38. # * The summoner event itself can be an enemy now too. It will stop spawning
  39. #   events when killed and it won't be able to spawn if it's using a tool.
  40. # * Added a self-switch condition for spawning. You can now make spawner events
  41. #   which only spawn when the assigned self-switch is turned ON.
  42. #   Extra useful for Falcao's ABS users!
  43. # * Added an animation display for the spawned events. It doesn't look good
  44. #   when events just pop out of nowhere. The animation makes it much better.
  45. #-------------------------------------------------------------------------------
  46. # * < Event Comments >
  47. #-------------------------------------------------------------------------------
  48. # * To display an animation on the spawned events when they appear, you can use
  49. #   the following comment:
  50. #
  51. #     <spawn-anim ID>  |  Example: <spawn-anim 120>, <spawn-anim 68>
  52. #
  53. #   Replace 'ID' with the ID of the animation you want to play on the spawned
  54. #   events. This animation will be played on every single spawned event at the
  55. #   moment they appear.
  56. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  57. # * To add a self-switch condition for the spawner event, you can use the
  58. #   following comment:
  59. #
  60. #     <spawn-sswitch ID>  |  Example: <spawn-sswitch B>, <spawn-sswitch D>
  61. #
  62. #   Replace the 'ID' with the self-switch you want to check for.
  63. #   This means it can be: A, B, C, or D.
  64. #   The spawner event will only spawn when the assigned self-switch for it is
  65. #   turned ON. If it is turned OFF, it will not spawn any events.
  66. #   Needless to say, this is pretty much a mandatory function for Falcao's ABS,
  67. #   since it automatically turns ON a self-switch when the player is near and it
  68. #   automatically turns it OFF when the player is not in the event's range.
  69. #   The self-switch operations (turning them ON or OFF) are only automated if
  70. #   you made the spawner event an enemy and assigned the automatic sensor
  71. #   self-switch from Falcao's ABS for the spawner!
  72. #   If it is NOT an enemy, you must control the self-switch manually to make
  73. #   the spawner start/finish spawning!
  74. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  75. # * To add a region or terrain position restriction for spawned events, use
  76. #   these event comments:
  77. #
  78. #     <spawn-region ID>
  79. #     <spawn-terrain ID>
  80. #
  81. #   Replace the ID with a region or terrain ID.
  82. #
  83. #   Spawned events will only be spawned on those regions/terrains if you use
  84. #   these comments!
  85. #
  86. #   Note that this only works if you have set the spawn position to be random!
  87. #   Also, it will only check for tiles within the range of the spawning
  88. #   position! If it can't find a matching region/terrain tile, the spawned event
  89. #   will appear on the spawner event instead!
  90. #-------------------------------------------------------------------------------
  91. # * < Important Notes >
  92. #-------------------------------------------------------------------------------
  93. # * Yeah, a whole section for them, they are that important!
  94. # * Do NOT try to spawn a spawner event ever!
  95. #   Do NOT put ANY spawner events on the Spawn Map!
  96. #   Doing any of the above will result in a lengthy freeze followed by a crash!
  97. #   Kal forgot to mentioned this in his script, but I think it is a pretty
  98. #   important information which should be noted somewhere.
  99. # * Do NOT try to spawn a real enemy (from the ABS) using the name based
  100. #   comment! That won't work, since an enemy's event in Falcao's ABS must be
  101. #   named <enemy: id>, and the symbols < and > will mess up the comment used
  102. #   in Kal's script. Instead use the <spawn-id ID> to spawn the event based on
  103. #   it's ID. The description in Kal's script is not updated, so you can't really
  104. #   find any useful info on this feature.
  105. #   To spawn an event using it's ID, you can use 2 kind of comments:
  106. #   1. <spawn-id ID> - This will spawn the event with the assigned ID from the
  107. #                      current map. Ex: <spawn-id 22>, <spawn-id 8>
  108. #   2. <spawn-id IDX> - This will spawn an event from the Spawn Map instead.
  109. #                       Ex: <spawn-id 14X>, <spawn-id 3X>
  110. #   So, use these comment tags instead of the <spawn-name name> comment when you
  111. #   want to spawn real enemies!
  112. #-------------------------------------------------------------------------------
  113. # * < Installation >
  114. #-------------------------------------------------------------------------------
  115. # * Place this script below Falcao's ABS and Kal's EventSpawner but above Main!
  116. #-------------------------------------------------------------------------------
  117. # * < Compatibility Info >
  118. #-------------------------------------------------------------------------------
  119. # * No known incompatibilities.
  120. #-------------------------------------------------------------------------------
  121. # * < Known Issues >
  122. #-------------------------------------------------------------------------------
  123. # * No known issues.
  124. #-------------------------------------------------------------------------------
  125. # * < Terms of Use >
  126. #-------------------------------------------------------------------------------
  127. # * Free to use for whatever purposes you want.
  128. # * Credit me (Sixth) in your game, pretty please! :P
  129. # * Posting modified versions of this script is allowed as long as you notice me
  130. #   about it with a link to it!
  131. #===============================================================================
  132. $imported = {} if $imported.nil?
  133. $imported["SixthKalESpawnABSPatch"] = true
  134. #===============================================================================
  135. # No settings! Editing anything below may lead to... you know it, right?
  136. #===============================================================================
  137.  
  138. module Kal::EventSpawn::Factory
  139.   module_function
  140.  
  141.   class << self; alias add_new_stuffs7789 make_options_hash; end
  142.   def make_options_hash(spawn_string)
  143.     opts = add_new_stuffs7789(spawn_string)
  144.     sswitch = spawn_string[/<spawn-sswitch\s+(\w+)>/i, 1]
  145.     anim = spawn_string[/<spawn-anim\s+(\d+)>/i, 1]
  146.     reg = spawn_string[/<spawn-region\s+(\d+)>/i, 1]
  147.     terr = spawn_string[/<spawn-terrain\s+(\d+)>/i, 1]
  148.     opts[:anim] = anim.to_i if anim
  149.     opts[:sswitch] = sswitch if sswitch
  150.     opts[:region] = reg.to_i if reg
  151.     opts[:terrain] = terr.to_i if terr
  152.     return opts
  153.   end
  154.      
  155. end
  156.  
  157. class Kal::EventSpawn::Spawner
  158.      
  159.   attr_accessor :spawned_events, :spawn_count, :player_flag, :saved_lights
  160.  
  161.   def set_player_flag(key)
  162.     @player_flag = key
  163.   end
  164.      
  165.   def get_possible_coords(start_x, start_y, distance)
  166.     coords = []
  167.     left_most   = [start_x - distance,0].max
  168.     right_most  = [start_x + distance,$game_map.width].min
  169.     up_most     = [start_y - distance,0].max
  170.     down_most   = [start_y + distance,$game_map.height].min
  171.     (left_most..right_most).each do |x|
  172.       (up_most..down_most).each do |y|
  173.         next if @options[:region] && $game_map.region_id(x,y) != @options[:region]
  174.         next if @options[:terrain] && $game_map.terrain_tag(x,y) != @options[:terrain]
  175.         coords << [x, y] unless x == start_x && y == start_y
  176.       end
  177.     end
  178.     coords
  179.   end
  180.  
  181.   def spawn
  182.     run_common_event
  183.     set_spawn_pos
  184.     if name = @options[:event_name]
  185.       event = event_from_name(name)
  186.     elsif id = @options[:event_id]
  187.       event = event_from_id(id)
  188.     end
  189.     cloned_event = clone_event(event)
  190.     cloned_event.life_es_kal = @options[:life]
  191.     cloned_event.moveto(@x, @y)
  192.     cloned_event.set_spawner_object(self) if $imported["SixthABSSummonSystem"]
  193.     $game_map.events[cloned_event.id] = cloned_event
  194.     spriteset = SceneManager.scene.instance_eval { @spriteset }
  195.     spriteset.instance_eval do
  196.       @character_sprites << Sprite_Character.new(@viewport1, cloned_event)
  197.     end
  198.     # Initializing the ABS enemy variables manually here!
  199.     $game_map.events[cloned_event.id].init_manual_abs_stuffs
  200.     if $imported["SixthABSSummonSystem"]
  201.       @spawned_events = [] if @spawned_events.nil?
  202.       @spawned_events << $game_map.events[cloned_event.id]
  203.     end
  204.     $game_map.events[cloned_event.id].animation_id = @options[:anim] if @options[:anim]
  205.     # ABS enemy init end!
  206.     @spawn_count += 1
  207.     @should_spawn = false
  208.   end
  209.      
  210.   alias abs_patch5543 update
  211.   def update
  212.     return if @options[:sswitch] && !$game_self_switches[[$game_map.map_id,@game_event.id,@options[:sswitch]]]
  213.     return if @game_event.collapsing?
  214.     if !@game_event.battler.nil?
  215.       return unless @game_event.tool_can_use?
  216.     end
  217.     abs_patch5543
  218.   end
  219.      
  220.   def load_spawn_map_events
  221.     id = SPAWN_MAP_ID
  222.     if id.is_a?(Numeric) && id > 0
  223.       begin
  224.         map = load_data(sprintf("Data/Map%03d.rvdata2", id))
  225.         if $khas_graphics && $khas_graphics[:ultra_lighting]
  226.           @saved_lights = {}
  227.           map.events.each do |key,ev|
  228.             ev.pages.each do |page|
  229.               page.list.each do |cmd|
  230.                 next unless [108, 408].include?(cmd.code)
  231.                 comment = cmd.parameters[0]
  232.                 if comment =~ /\[light (.*)\]/i
  233.                   @saved_lights[key] = $1
  234.                   comment.sub!($1,"")
  235.                 end
  236.               end
  237.             end
  238.           end
  239.         end
  240.       rescue Errno::ENOENT => e
  241.         raise LoadError, "ERROR: Could not find a map with ID #{id}\n" +
  242.                          "(SPAWN_EVENT_ID = #{id})"  
  243.       end
  244.       evs = map.events.values.map { |event| Game_Event.new(id, event) }
  245.       if $khas_graphics && $khas_graphics[:ultra_lighting]
  246.         evs.each do |ev|
  247.           if @saved_lights[ev.event.id]
  248.             ev.saved_light = @saved_lights[ev.event.id]
  249.           end
  250.         end
  251.       end
  252.       return evs
  253.     end
  254.   end
  255.  
  256.   def kill_lights
  257.     @spawn_map_events.each {|ev| ev.drop_light if ev.light }
  258.   end
  259.  
  260. end
  261.  
  262. class Game_Event < Game_Character
  263.  
  264.   attr_accessor :saved_light
  265.  
  266.   alias fix_spawn_maps8827 initialize
  267.   def initialize(map_id, event)
  268.     fix_spawn_maps8827(map_id, event)
  269.     fix_spawn_map_issue
  270.   end
  271.    
  272.   def fix_spawn_map_issue
  273.     if @map_id != $game_map.map_id
  274.       $game_map.events_withtags.delete(self) if $game_map.events_withtags.include?(self)
  275.       $game_map.event_enemies.delete(self) if $game_map.event_enemies.include?(self)
  276.       $game_map.enemies.delete(@enemy) if $game_map.enemies.include?(@enemy)
  277.       if $imported["SixthABSSummonSystem"]
  278.         $game_map.battler_data.delete(self) if $game_map.battler_data.include?(self)
  279.       end
  280.       if $khas_graphics && $khas_graphics[:ultra_lighting]
  281.         drop_light if @light
  282.       end
  283.     end
  284.   end
  285.  
  286.   alias fix_spawn_map8272 set_ids_es_kal
  287.   def set_ids_es_kal(id)
  288.     fix_spawn_map8272(id)
  289.     @map_id = $game_map.map_id
  290.   end
  291.  
  292.   def init_manual_abs_stuffs
  293.     @awareness = false
  294.     @inrangeev = nil
  295.     @being_targeted = false
  296.     @agroto_f = nil
  297.     @draw_drop = false
  298.     @dropped_items = []
  299.     @epassive = false
  300.     @touch_damage = 0
  301.     @start_delay = 0
  302.     @touch_atkdelay = 0
  303.     @killed = false
  304.     @knockdown_enable = false
  305.     @deadposee = false
  306.     @respawn_anim = 0
  307.     create_token_arrays
  308.     register_enemy(@event)
  309.     @enemy.recover_all if @enemy
  310.   end
  311.  
  312. end
  313. #==============================================================================
  314. # !!END OF SCRIPT - OHH, NOES!!
  315. #==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement