Vlue

Pets and Summons

Apr 21st, 2014
8,072
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Pets and Summons (Stand Alone) v1.4g
  2. #----------#
  3. #Features: Allows you to set skills that summons pets (actors) into battle, which
  4. #           can last for the duration of the battle, until dead, or by timer.
  5. #
  6. #Usage:    Plug and play, Customize as needed
  7. #           Skill/Item Notetag:
  8. #            <SUMMON actor_id, timer, level_bonus (optional)>
  9. #           Set timer to 0 to not use it.
  10. #           level_bonus is change in pet level from the actor
  11. #
  12. #            <BIG_SUMMON actor_id, timer, level_bonus>
  13. #           Same as above, but replaces party for duration
  14. #            <MED_SUMMON actor_id, timer, level_bonus>
  15. #           Same as above, but replaces actor for duration
  16. #
  17. #----------#
  18. #-- Script by: V.M of D.T
  19. #- Questions or comments can be:
  20. #    given by email: sumptuaryspade@live.ca
  21. #    provided on facebook: http://www.facebook.com/DaimoniousTailsGames
  22. #   All my other scripts and projects can be found here: http://daimonioustails.weebly.com/
  23. #
  24. #--- Free to use in any project, commercial or non-commercial, with credit given
  25. # - - Though a donation's always a nice way to say thank you~ (I also accept actual thank you's)
  26.  
  27. #Maximum number of pets one actor can have:
  28. MAX_PETS = 3
  29.  
  30. #Message played when certain pet is summoned:
  31. # actor_id => "message"
  32. SUMMON_MESSAGES = {
  33.   2 => "A large wolf joins the fray!",
  34.   3 => "Transformed into a dragon!!!"
  35. }
  36. #Message played when pets timer runs out:
  37. RETREAT_MESSAGES = {
  38.   2 => "A large wolf retreats into the shadows.",
  39.   3 => "A large wolf retreats into the shadows."
  40. }
  41. #Message played when pet dies:
  42. DEATH_MESSAGES = {
  43.   2 => "A large wolf has died!",
  44.   3 => "A large wolf has died!"
  45. }
  46.  
  47. class Game_Battler < Game_BattlerBase
  48.   attr_accessor  :pets
  49.   alias pet_init initialize
  50.   alias pet_iue item_user_effect
  51.   alias pet_obe on_battle_end
  52.   def initialize(*args)
  53.     pet_init(*args)
  54.     @hp = 1
  55.     @pets = []
  56.   end
  57.   def add_pet(actor_id, timer = -1, level = 0)
  58.   end
  59.   def remove_pet(index)
  60.     @pets[index] = nil
  61.     @pets.compact!
  62.   end
  63.   def remove_pets_by_state
  64.     iter = 0
  65.     @pets.each do |pet|
  66.       pet.timer -= 1
  67.       if pet.hp <= 0
  68.         remove = true
  69.         if DEATH_MESSAGES[pet.actor_id]
  70.           SceneManager.scene.log_window.add_text(DEATH_MESSAGES[pet.actor_id])
  71.           SceneManager.scene.log_window.wait
  72.           SceneManager.scene.status_window.refresh
  73.         end
  74.       elsif pet.timer == 0 || self.hp <= 0
  75.         remove = true
  76.         if RETREAT_MESSAGES[pet.actor_id]
  77.           SceneManager.scene.log_window.add_text(RETREAT_MESSAGES[pet.actor_id])
  78.           SceneManager.scene.log_window.wait
  79.           SceneManager.scene.status_window.refresh
  80.         end
  81.       end
  82.       @pets[iter] = nil if remove
  83.       iter += 1
  84.     end
  85.     SceneManager.scene.reset_actor_sprites
  86.     SceneManager.scene.log_window.wait_and_clear
  87.     @pets.compact!
  88.   end
  89.   def item_user_effect(user, item)
  90.     pet_iue(user, item)
  91.     if item.big_summons
  92.       temp_replace_party(item.big_summons)
  93.       @result.success = true
  94.       SceneManager.scene.log_window.wait
  95.       SceneManager.scene.log_window.wait_and_clear
  96.     elsif item.med_summons
  97.       temp_replace_actor(item.med_summons[0])
  98.       @result.success = true
  99.       SceneManager.scene.log_window.wait
  100.       SceneManager.scene.log_window.wait_and_clear
  101.     elsif item.summons
  102.       return if self.pets.size >= MAX_PETS
  103.       item.summons.each do |array|
  104.         next if self.pets.size >= MAX_PETS
  105.         add_pet(array[0],array[1],array[2])
  106.         @result.success = true
  107.       end
  108.       SceneManager.scene.log_window.wait
  109.       SceneManager.scene.log_window.wait_and_clear
  110.     end
  111.   end
  112.   def on_battle_end
  113.     @pets = []
  114.     pet_obe
  115.   end
  116.   def temp_replace_actor(array)
  117.   end
  118.   def temp_replace_party(array)
  119.   end
  120.   def summon_pet(array)
  121.   end
  122. end
  123.  
  124. class Game_Actor < Game_Battler
  125.   attr_accessor  :actor_id
  126.   def add_pet(actor_id, timer = -1, level = 0)
  127.     if level
  128.       @pets.push(Game_Pet.new(actor_id,timer,@level + level))
  129.     else
  130.       @pets.push(Game_Pet.new(actor_id,timer,false))
  131.     end
  132.     @pets[-1].set_ori(@actor_id)
  133.     return unless SceneManager.scene.is_a?(Scene_Battle)
  134.     if SUMMON_MESSAGES[actor_id]
  135.       SceneManager.scene.log_window.add_text(SUMMON_MESSAGES[actor_id])
  136.       SceneManager.scene.log_window.wait
  137.       SceneManager.scene.status_window.refresh
  138.     end
  139.     SceneManager.scene.reset_actor_sprites
  140.   end
  141.   def temp_replace_actor(array)
  142.     $game_party.temp_replace_actor(self, array)
  143.   end
  144.   def temp_replace_party(array)
  145.     $game_party.temp_replace_party(self, array)
  146.   end
  147.   def summon_pet(array)
  148.     $game_party.summon_pet(self, array)
  149.   end
  150.   def restore_actor
  151.     return false
  152.   end
  153.   def screen_x
  154.     0
  155.   end
  156.   def screen_y
  157.     0
  158.   end
  159.   def screen_z
  160.     0
  161.   end
  162. end
  163.  
  164. class Game_Pet < Game_Actor
  165.   attr_accessor  :timer
  166.   attr_accessor  :actor_id
  167.   attr_accessor  :former_actor
  168.   def initialize(actor_id, timer, level_bonus, former_actor = nil)
  169.     super(actor_id)
  170.     @timer = timer
  171.     @timer -= 1 if @timer == 0
  172.     if level_bonus
  173.       @level = [[@level + level_bonus,1].max,99].min
  174.     end
  175.     @former_actor = former_actor
  176.     @ori_actor = nil
  177.     init_skills
  178.     recover_all
  179.   end
  180.   def set_ori(id)
  181.     @ori_actor = id
  182.   end
  183.   def sprite
  184.     @sprite = Sprite_Battler.new(nil) if @sprite.nil?
  185.     @sprite
  186.   end
  187.   def on_turn_end
  188.     super
  189.     if @former_actor
  190.       @timer -= 1
  191.       if @hp <= 0 ||  @timer == 0
  192.         return if $game_party.restore_party
  193.         $game_party.restore_actor(self, former_actor)
  194.       end
  195.     end
  196.   end
  197.   def restore_actor
  198.     return false unless @former_actor
  199.     $game_party.restore_actor(self, former_actor)
  200.     return true
  201.   end
  202.   def on_battle_end
  203.     super
  204.     restore_actor
  205.   end
  206.   def screen_x
  207.     return super unless @ori_actor
  208.     $game_actors[@ori_actor].screen_x + 12
  209.   end
  210.   def screen_y
  211.     return super unless @ori_actor
  212.     $game_actors[@ori_actor].screen_y + 12
  213.   end
  214.   def use_sprite?
  215.     true
  216.   end
  217. end
  218.  
  219. class RPG::UsableItem
  220.   def summons
  221.     return false unless self.note.index("<SUMMON")
  222.     notes = self.note.clone
  223.     summon_array = []
  224.     while notes =~ /<SUMMON (\d+), ((\d+)|(\d+), ((\d+)|(-\d+)))>/
  225.       if $2.include?(",")
  226.         array = [$1.to_i] + $2.split(",").map {|s| s.to_i}
  227.       else
  228.         array = [$1.to_i,$2.to_i,false]
  229.       end
  230.       summon_array.push(array)
  231.       notes[notes.index("SUMMON")] = "N"
  232.     end
  233.     summon_array
  234.   end
  235.   def med_summons
  236.     return false unless self.note.index("<MED_SUMMON")
  237.     notes = self.note.clone
  238.     summon_array = []
  239.     while notes =~ /<MED_SUMMON (\d+), (\d+), (\d+)>/
  240.       summon_array.push([$1.to_i,$2.to_i,$3.to_i])
  241.       notes[notes.index("MED_SUMMON")] = "N"
  242.     end
  243.     summon_array
  244.   end
  245.   def big_summons
  246.     return false unless self.note.index("<BIG_SUMMON")
  247.     notes = self.note.clone
  248.     summon_array = []
  249.     while notes =~ /<BIG_SUMMON (\d+), (\d+), (\d+)>/
  250.       summon_array.push([$1.to_i,$2.to_i,$3.to_i])
  251.       notes[notes.index("BIG_SUMMON")] = "N"
  252.     end
  253.     summon_array
  254.   end
  255. end
  256.  
  257. class Scene_Battle
  258.   attr_accessor  :log_window
  259.   attr_accessor  :status_window
  260.   def turn_start
  261.     @party_command_window.close
  262.     @actor_command_window.close
  263.     @status_window.unselect
  264.     @subject =  nil
  265.     BattleManager.turn_start
  266.     @log_window.wait
  267.     @log_window.clear
  268.   end
  269.   def turn_end
  270.     all_battle_members.each do |battler|
  271.       battler.on_turn_end
  272.       refresh_status
  273.       @log_window.display_auto_affected_status(battler)
  274.       @log_window.wait_and_clear
  275.       battler.remove_pets_by_state
  276.     end
  277.     BattleManager.turn_end
  278.     process_event
  279.     start_party_command_selection
  280.   end
  281.   def reset_actor_sprites
  282.     @spriteset.create_actors
  283.   end
  284. end
  285.  
  286. class Scene_Map
  287.   def reset_actor_sprites
  288.   end
  289. end
  290.  
  291. class Game_Party
  292.   def pets
  293.     pet = []
  294.     self.pets_battle_members.each do |actor|
  295.       pet += actor.pets
  296.     end
  297.     pet.compact
  298.   end
  299.   alias pets_battle_members battle_members
  300.   def battle_members
  301.     pets_battle_members + pets
  302.   end
  303.   def temp_replace_actor(actor, array)
  304.     if SUMMON_MESSAGES[array[0]]
  305.       SceneManager.scene.log_window.add_text(SUMMON_MESSAGES[array[0]])
  306.       SceneManager.scene.log_window.wait
  307.       SceneManager.scene.status_window.refresh
  308.     end
  309.     $game_actors.set_pet(array[0],Game_Pet.new(array[0],array[1],actor.level + array[2],actor.actor_id))
  310.     @actors[actor.index] = array[0]
  311.     SceneManager.scene.reset_actor_sprites
  312.   end
  313.   def restore_actor(pet, actor_id)
  314.     @actors[pet.index] = actor_id
  315.     SceneManager.scene.reset_actor_sprites
  316.   end
  317.   def temp_replace_party(actor, arrays)
  318.     @actors_sideline = @actors.clone
  319.     @actors = []
  320.     arrays.each do |array|
  321.       $game_actors.set_pet(array[0],Game_Pet.new(array[0],array[1],actor.level + array[2],actor.actor_id))
  322.       add_actor(array[0])
  323.     end
  324.     SceneManager.scene.reset_actor_sprites
  325.   end
  326.   def restore_party
  327.     return false unless @actors_sideline
  328.     @actors = @actors_sideline.clone
  329.     @actors_sideline = nil
  330.     SceneManager.scene.reset_actor_sprites
  331.     return true
  332.   end
  333.   def on_battle_end
  334.     restore_party
  335.     super
  336.   end
  337. end
  338.  
  339. class Game_Actors
  340.   def set_pet(id, pet)
  341.     @data[id] = pet
  342.   end
  343. end
  344.  
  345. $imported = {} if $imported.nil?
  346. class Window_BattleStatus < Window_Selectable
  347.   alias pets_yan_refresh refresh
  348.   alias pets_yan_draw_item draw_item
  349.   def refresh
  350.     return pets_yan_refresh if !$imported["YEA-BattleEngine"].nil?
  351.     contents.dispose
  352.     self.contents = Bitmap.new(self.width-24,line_height*item_max)
  353.     contents.clear
  354.     draw_all_items
  355.   end
  356.   def item_max
  357.     $game_party.members.size
  358.   end
  359.   def battle_members; return $game_party.members; end
  360.   def draw_item(index)
  361.     return pets_yan_draw_item(index) if !$imported["YEA-BattleEngine"].nil?
  362.     actor = $game_party.members[index]
  363.     draw_basic_area(basic_area_rect(index), actor)
  364.     draw_gauge_area(gauge_area_rect(index), actor)
  365.   end
  366. end
  367.  
  368. module BattleManager
  369.   class << self
  370.     alias pets_process_victory process_victory
  371.   end
  372.   def self.process_defeat
  373.     return false if $game_party.restore_party
  374.     $game_party.members.each do |actor|
  375.       return false if actor.restore_actor
  376.     end
  377.     $game_message.add(sprintf(Vocab::Defeat, $game_party.name))
  378.     wait_for_message
  379.     if @can_lose
  380.       revive_battle_members
  381.       replay_bgm_and_bgs
  382.       SceneManager.return
  383.     else
  384.       SceneManager.goto(Scene_Gameover)
  385.     end
  386.     battle_end(2)
  387.     return true
  388.   end
  389.   def self.process_victory
  390.     $game_party.restore_party
  391.     pets_process_victory
  392.   end
  393. end
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×