neonblack

Pet Follower v1.1

Jun 18th, 2012
2,656
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ###--------------------------------------------------------------------------###
  2. #  Pet Follower script                                                         #
  3. #  Version 1.1                                                                 #
  4. #                                                                              #
  5. #      Credits:                                                                #
  6. #  Original code by: Neonblack                                                 #
  7. #  Modified by:                                                                #
  8. #                                                                              #
  9. #  This work is licensed under the Creative Commons Attribution-NonCommercial  #
  10. #  3.0 Unported License. To view a copy of this license, visit                 #
  11. #  http://creativecommons.org/licenses/by-nc/3.0/.                             #
  12. #  Permissions beyond the scope of this license are available at               #
  13. #  http://cphouseset.wordpress.com/liscense-and-terms-of-use/.                 #
  14. #                                                                              #
  15. #      Contact:                                                                #
  16. #  NeonBlack - neonblack23@live.com (e-mail) or "neonblack23" on skype         #
  17. ###--------------------------------------------------------------------------###
  18.  
  19. ###--------------------------------------------------------------------------###
  20. #      Revision information:                                                   #
  21. #  V1.1 - 6.18.2012                                                            #
  22. #   Added constant motion for pets                                             #
  23. #  V1.0 - 6.18.2012                                                            #
  24. #   Wrote and debugged main script                                             #
  25. ###--------------------------------------------------------------------------###
  26.  
  27. ###--------------------------------------------------------------------------###
  28. #      Compatibility:                                                          #
  29. #  Alias       - Game_Interpreter: remove_pet, hide_pet, show_pet, pet         #
  30. #                                  pet_motion, pet_top                         #
  31. #                Game_Followers: initialize                                    #
  32. #                Game_Follower: refresh                                        #
  33. #  Overwrites  - Game_Follower: update                                         #
  34. #  New Objects - Game_Followers: remove_pet                                    #
  35. #                Game_Follower: pet?                                           #
  36. ###--------------------------------------------------------------------------###
  37.  
  38. ###--------------------------------------------------------------------------###
  39. #      Instructions:                                                           #
  40. #  Place this script in the "Materials" section of the scripts above main.     #
  41. #  This script is plug and play and is activated and used through some simple  #
  42. #  script calls.  Note that the pet acts exactly like a normal follower and    #
  43. #  will gather if the gather option is used, however the pet will not hide if  #
  44. #  the other followers are hidded.  Here are the commands:                     #
  45. #                                                                              #
  46. #   pet("x", y) - Changes the sprite of the pet follower where "x" is the      #
  47. #                 filename and "y" is the index within the file.  If "y" is    #
  48. #                 not defined, an index of "0" (the first image in a file)     #
  49. #                 will be used.                                                #
  50. #   remove_pet  - Removes the pet from the followers.                          #
  51. #   hide_pet    - Hides the pet until "show_pet" is called.                    #
  52. #   show_pet    - Shows the pet again.                                         #
  53. #   pet_motion  - Causes pet sprites to stay animated.                         #
  54. #   pet_stop    - Stops pet sprite animation.                                  #
  55. ###--------------------------------------------------------------------------###
  56.  
  57.  
  58. ###--------------------------------------------------------------------------###
  59. #  The following lines are the actual core code of the script.  While you are  #
  60. #  certainly invited to look, modifying it may result in undesirable results.  #
  61. #  Modify at your own risk!                                                    #
  62. ###--------------------------------------------------------------------------###
  63.  
  64. $imported = {} if $imported == nil
  65. $imported["CP_PET"] = true
  66.  
  67. class Game_Interpreter  ##  Add pet commands that can be called by the user.
  68.   def remove_pet
  69.     $game_player.followers.remove_pet
  70.     $game_player.followers.refresh
  71.   end
  72.  
  73.   def hide_pet
  74.     $game_player.followers.pet_visible = false
  75.     $game_player.followers.refresh
  76.   end
  77.  
  78.   def show_pet
  79.     $game_player.followers.pet_visible = true
  80.     $game_player.followers.refresh
  81.   end
  82.  
  83.   def pet(name, index = 0)
  84.     $game_player.followers.pet_name = name
  85.     $game_player.followers.pet_index = index
  86.     $game_player.followers.refresh
  87.   end
  88.  
  89.   def pet_motion
  90.     $game_player.followers.pet_motion = true
  91.     $game_player.followers.refresh
  92.   end
  93.  
  94.   def pet_stop
  95.     $game_player.followers.pet_motion = false
  96.     $game_player.followers.refresh
  97.   end
  98. end
  99.  
  100. class Game_Followers  ##  New variables
  101.   attr_accessor :pet_name
  102.   attr_accessor :pet_index
  103.   attr_accessor :pet_visible
  104.   attr_accessor :pet_motion
  105.  
  106.   alias pet_initialize initialize unless $@
  107.   def initialize(leader)  ##  Push an extra follower for the pet.
  108.     pet_initialize(leader)
  109.     @data.push(Game_Follower.new(@data.size + 1, @data[-1]))
  110.     @pet_name = ""
  111.     @pet_index = 0
  112.     @pet_visible = true
  113.     @pet_motion = false
  114.   end
  115.  
  116.   def remove_pet  ##  Nulify variables to remove the pet.
  117.     @pet_name = ""
  118.     @pet_index = 0
  119.   end
  120. end
  121.  
  122. class Game_Follower < Game_Character
  123.   alias pet_refresh refresh unless $@
  124.   def refresh  ##  Add pet names for the refresh.
  125.     pet_refresh
  126.     @character_name = pet? ? $game_player.followers.pet_name : @character_name
  127.     @character_index = pet? ? $game_player.followers.pet_index : @character_index
  128.     @step_anime = pet? ? $game_player.followers.pet_motion : false
  129.   end
  130.  
  131.   def pet?  ##  Check if follower is the pet.
  132.     (@member_index == $game_party.battle_members.size &&
  133.      $game_player.followers.pet_visible && $game_player.followers.visible) ||
  134.     (@member_index == 1 && $game_player.followers.pet_visible &&
  135.      !$game_player.followers.visible)
  136.   end
  137.    
  138.   def update  ##  The only overwrite.
  139.     @move_speed     = $game_player.real_move_speed
  140.     @transparent    = $game_player.transparent
  141.     @walk_anime     = $game_player.walk_anime
  142.     @step_anime     = $game_player.step_anime unless pet?
  143.     @direction_fix  = $game_player.direction_fix
  144.     @opacity        = $game_player.opacity
  145.     @blend_type     = $game_player.blend_type
  146.     super
  147.   end
  148. end
  149.  
  150.  
  151. ###--------------------------------------------------------------------------###
  152. #  End of script.                                                              #
  153. ###--------------------------------------------------------------------------###
RAW Paste Data