SHARE
TWEET

Following Pokemon v1.4

mej71 Jan 4th, 2016 (edited) 19,842 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #===============================================================================
  2. # * Config Script For Your Game Here. Change the emo_ to what ever number is
  3. #        the cell holding the animation.
  4. #===============================================================================
  5. Unused_Common_Event         = 5       #Common event should be blank, but reserved
  6. Following_Activated_Switch = 126      # Switch should be reserved
  7. Toggle_Following_Switch = 103         # Switch should be reserved
  8. Current_Following_Variable = 36       # Variable should be reserved
  9. ItemWalk=26                           # Variable should be reserved
  10. Walking_Time_Variable = 27            # Variable should be reserved
  11. Walking_Item_Variable = 28            # Variable should be reserved
  12. Animation_Come_Out = 93              
  13. Animation_Come_In = 94
  14. Emo_Happy = 95
  15. Emo_Normal = 96
  16. Emo_Hate = 97
  17. Emo_Poison= 98
  18. Emo_sing= 99
  19. Emo_love= 100
  20.  
  21. # * Support for Pokemon Birthsigns script
  22. Emo_Cake= 92 if self.class.const_defined?(:PBBirthsigns) &&  self.class.const_get(:PBBirthsigns).instance_of?(::Module)
  23.  
  24. ALLOWTOGGLEFOLLOW = true             # Allow the player to toggle followers on/off
  25. ALLOWFIELDSWITCHING = true          # Allow the player to cycle through pokemon
  26. APPLYSTATUSTONES = true# Add tone to follower if statused
  27. #Status tones to be used, if the above is true (Red,Green,Blue,Gray)
  28. BURNTONE = [204,51,51,50]
  29. POISONTONE = [153,102,204,50]
  30. PARALYSISTONE = [255,255,153,50]
  31. FREEZETONE = [153,204,204,50]
  32. SLEEPTONE = [0,0,0,0]  # I did not use this tone, but you may if you wish
  33. ALWAYS_ANIMATE  = true #Follower sprite will always animated while standing still
  34. #Regardless of the above setting,the species in this array will always animate
  35. ALWAYS_ANIMATED_FOLLOWERS=[151]  # Mew
  36. #Add exclusions to always animated (small birds like Pidgey mostly hop, due to small wings)
  37. ALWAYS_ANIMATED_EXCEPTION=[16] #Pidgey
  38. #Removed for now
  39. #REGULAR_WALKING = true  
  40. WATERPOKEMONCANSURF = true  # Allow water pokemon to follow the player while surfing
  41. WATERPOKEMONCANDIVE = true #Allow water pokemon to follow the player while diving
  42. ALWAYS_ANIMATED_CAN_SURF = true #Pokemon that are always animated can follow you
  43.                                 # across water (flying, levitating, or specified)
  44.  
  45. #Don't change
  46. FOLLOWER_FILE_PATH = "Graphics/Characters/"
  47. #The subfolder where your follower sprites are located
  48. #Has to be within Graphics/Characters
  49. FOLLOWER_FILE_DIR = ""
  50.                                            
  51.  
  52. #===============================================================================
  53. # * Credit to Help-14 for both the original scripts and sprites
  54. # * Change Log:
  55. #===============================================================================
  56.  
  57. #===============================================================================
  58. # * Edited by zingzags
  59. #===============================================================================
  60. # * Fixed bugs
  61. # * Clean ups
  62. # * Fixed Surf Bug (After Surf is done)
  63. # * Fixed def talk_to_pokemon while in surf
  64. # * Fixed Surf Check
  65. # * Fixed Type Check
  66. # * Added Door Support
  67. # * Fixed Hp Bug
  68. # * Added Pokemon Center Support
  69. # * Animation problems
  70. # * Fixed Walk_time_variable problem
  71. # * Added random item loot
  72. # * Added egg check
  73. #===============================================================================
  74.  
  75. #===============================================================================
  76. # * Edited by Rayd12smitty
  77. # * Version 1.0
  78. #===============================================================================
  79. # * Fixed Walk_Time_Variable
  80. # * Fixed crash when talking to Pokemon on a different map than the original
  81. #   they appeared on
  82. # * Receiving Items from Pokemon now works
  83. # * Improved Talk_to_Pokemon wiht more messages and special messages
  84. # * Added messages for all Status Conditions
  85. # * Added Party Rotation to switch follower
  86. # * Made Following Pokemon Toggleable
  87. # * Added Animation for Pokemon coming out of Pokeball in sprite_refresh
  88. # * Tidied up script layout and made more user friendly
  89. # * Fixed Issues with Pokemon jumping around on ledges
  90. # * Fixed Badge for Surf Typo in the script
  91. #===============================================================================
  92. # * Version 1.1
  93. #===============================================================================
  94. # * Fixed Surfing so Pokemon doesn't reappear on water when toggled off
  95. # * Changed Layout and location of Toggle Script
  96. #===============================================================================
  97.  
  98. #===============================================================================
  99. # * Edited by Rayd12smitty and venom12
  100. # * Version 1.2
  101. #===============================================================================
  102. # * Fixed Walk step count so it doesn't add on when Pokemon is toggled off
  103. # * No longer have to manually set Toggle_Following_Switch and
  104. #   Following_Activated_Switch whenever "pbPokemonFollow(x)" is called
  105. # * Now supports Pokemon with multiple forms
  106. # * Items found on specific maps support
  107. # * Support for messages when on a map including a word/phrase in its name
  108. #   rather than a single map
  109. # * Added stepping animation for follower
  110. # * Fixed dismount bike so Pokemon reappears
  111. # * Fixed bike so if it couldn't be used it now can
  112. # * Few other small bike fixes
  113. #===============================================================================
  114.  
  115. #===============================================================================
  116. # * Version 1.3
  117. #===============================================================================
  118. # * Fixed bug with surf where the Follower could block the player from being
  119. #   able to surf, possibly stranding the player
  120. # * Added script to animate all events named "Poke"
  121. # * Increased time to find an item. I realize now that 5000 frames is less than
  122. #   5 min. Way too short.
  123. #===============================================================================
  124.  
  125. #===============================================================================
  126. # * Edited by mej71
  127. # * Version 1.4
  128. #===============================================================================
  129. # * Combined all into one script section for ease of installation
  130. # * Added setting to allow/disallow cycling through pokemon in field
  131. # * Added tone effect to following pokemon if statused
  132. # * Fixed follower grass animations
  133. # * NPCs won't walk over the follower
  134. # * Fixed crash caused by toggling follower when loading a map sometimes
  135. # * Prevent some HM usage when having a nonfollower dependent event
  136. #   so hopefully this will lead more towards support for regular dependent events
  137. # * Your followers don't automatically turn when you do, so it looks more natural
  138. # * There's a setting now to make pokemon always animate while you're standing still
  139. #   Note that flying, levitating, or any pokemon species specified will always animate
  140. #   regardless of this setting
  141. # *Reflected sprites support for followers
  142. # *Player transfer works a bit better, your follower shouldn't appear on top of
  143. #  you anymore
  144. # *There's a setting that allows water pokemon to follow you over water
  145. # *Additional setting allows flying, levitating, or other pokemon species to also
  146. #  follow you over water
  147. # *Sprite refreshes after evolution
  148. # *Blacking out won't cause errors
  149. # *v15.1 compatability
  150. # *Followers walk cycle works properly
  151. # *Move routes work properly (they worked in old versions, but were temporarily
  152. #  broken in my version)
  153. # *Pokemon get put away when transferring to a bike only map
  154. # *Follower gets checked when going underwater (water pokemon can follow underwater)
  155. # * Support for Pokemon Birthsigns script
  156. #===============================================================================
  157.  
  158. #===============================================================================
  159. # * To Do
  160. #===============================================================================
  161. # * None.  Perfect?
  162. #===============================================================================
  163.  
  164.  
  165.  
  166. #===============================================================================
  167. # * Control the following Pokemon
  168. # * Example:
  169. #     FollowingMoveRoute([
  170. #         PBMoveRoute::TurnRight,
  171. #         PBMoveRoute::Wait,4,
  172. #         PBMoveRoute::Jump,0,0
  173. #     ])
  174. # * The Pokemon turns Right, waits 4 frames, and then jumps
  175. # * Call pbPokeStep to animate all events on the map named "Poke"
  176. #===============================================================================
  177. def FollowingMoveRoute(commands,waitComplete=false)
  178.   return if $Trainer.party[0].hp<=0 || $Trainer.party[0].isEgg? ||
  179.       $game_variables[Current_Following_Variable]==0 ||
  180.       !$game_switches[Toggle_Following_Switch]
  181.   $PokemonTemp.dependentEvents.SetMoveRoute(commands,waitComplete)
  182. end
  183.  
  184. def pbPokeStep
  185.   for event in $game_map.events.values
  186.     if event.name=="Poke"              
  187.       pbMoveRoute(event,[PBMoveRoute::StepAnimeOn])
  188.     end
  189.   end
  190. end
  191. #===============================================================================
  192. # * Toggle for Following Pokemon
  193. #===============================================================================
  194. def pbToggleFollowingPokemon
  195.   return if $Trainer.party[0].hp<=0 || $Trainer.party[0].isEgg?
  196.   if $game_switches[Following_Activated_Switch]
  197.     if $game_switches[Toggle_Following_Switch]
  198.       $game_switches[Toggle_Following_Switch]=false
  199.       $PokemonTemp.dependentEvents.remove_sprite(true)
  200.       pbWait(1)      
  201.     else
  202.       $game_switches[Toggle_Following_Switch]=true
  203.       $PokemonTemp.dependentEvents.refresh_sprite
  204.       pbWait(1)
  205.      
  206.     end
  207.   end
  208. end
  209.  
  210.  
  211.  
  212. class DependentEvents
  213.   attr_accessor :realEvents
  214. #===============================================================================
  215. # Raises The Current Pokemon's Happiness level +1 per each time the
  216. # Walk_time_Variable reachs 5000 then resets to 0
  217. # ItemWalk, is when the variable reaches a certain amount, that you are able
  218. # to talk to your pokemon to recieve an item
  219. #===============================================================================
  220.   def add_following_time
  221.     if $game_switches[Toggle_Following_Switch] && $Trainer.party.length>=1
  222.       $game_variables[Walking_Time_Variable]+=1 if $game_variables[Current_Following_Variable]!=0
  223.       $game_variables[Walking_Item_Variable]+=1 if $game_variables[Current_Following_Variable]!=0
  224.       if $game_variables[Walking_Time_Variable]==5000
  225.         $Trainer.party[0].happiness+=1
  226.         $game_variables[Walking_Time_Variable]=0
  227.       end
  228.       if $game_variables[Walking_Item_Variable]==1000
  229.         if $game_variables[ItemWalk]==15
  230.         else
  231.           $game_variables[ItemWalk]+=1
  232.         end
  233.         $game_variables[Walking_Item_Variable]=0
  234.       end
  235.     end
  236.   end
  237. #===============================================================================
  238. # * refresh_sprite
  239. # * Updates the sprite sprite with an animation
  240. #===============================================================================
  241.   def refresh_sprite(animation=true)
  242.     if $game_variables[Current_Following_Variable]!=0
  243.       return unless $game_switches[Toggle_Following_Switch]
  244.       return if $PokemonGlobal.bicycle
  245.       if $Trainer.party[0].isShiny?
  246.         shiny=true
  247.       else
  248.         shiny=false
  249.       end
  250.       if $Trainer.party[0].form>0
  251.         form=$Trainer.party[0].form
  252.       else
  253.         form=nil
  254.       end
  255.       if defined?($Trainer.party[0].isShadow?)
  256.         shadow = $Trainer.party[0].isShadow?
  257.       else
  258.         shadow = false
  259.       end
  260.       if $PokemonGlobal.surfing
  261.         if $Trainer.party[0].hp>0 && !$Trainer.party[0].isEgg? && $Trainer.party[0].hasType?(:WATER)
  262.           events=$PokemonGlobal.dependentEvents
  263.           if animation
  264.             for i in 0...events.length
  265.               $scene.spriteset.addUserAnimation(Animation_Come_Out,@realEvents[i].x,@realEvents[i].y)
  266.               pbWait(10)
  267.             end
  268.           end
  269.           change_sprite($Trainer.party[0].species, shiny, false, form, $Trainer.party[0].gender, shadow)
  270.         elsif ALWAYS_ANIMATED_CAN_SURF && ($Trainer.party[0].hasType?(:FLYING) ||
  271.           isConst?($Trainer.party[0].ability,PBAbilities,:LEVITATE) ||
  272.           ALWAYS_ANIMATED_FOLLOWERS.include?($Trainer.party[0].species)) &&
  273.           !(ALWAYS_ANIMATED_EXCEPTION.include?($Trainer.party[0].species)) &&
  274.           $Trainer.party[0].hp>0 && !$Trainer.party[0].isEgg?
  275.           events=$PokemonGlobal.dependentEvents
  276.           if animation
  277.             for i in 0...events.length
  278.               $scene.spriteset.addUserAnimation(Animation_Come_Out,@realEvents[i].x,@realEvents[i].y)
  279.               pbWait(10)
  280.             end
  281.           end
  282.           change_sprite($Trainer.party[0].species, shiny, false, form, $Trainer.party[0].gender, shadow)
  283.         else
  284.           remove_sprite(false)
  285.         end  
  286.       elsif $PokemonGlobal.diving
  287.         if $Trainer.party[0].hp>0 && !$Trainer.party[0].isEgg? && $Trainer.party[0].hasType?(:WATER) && WATERPOKEMONCANDIVE
  288.           events=$PokemonGlobal.dependentEvents
  289.           if animation
  290.             for i in 0...events.length
  291.               $scene.spriteset.addUserAnimation(Animation_Come_Out,@realEvents[i].x,@realEvents[i].y)
  292.               pbWait(10)
  293.             end
  294.           end
  295.           change_sprite($Trainer.party[0].species, shiny, false, form, $Trainer.party[0].gender, shadow)
  296.         else
  297.           remove_sprite(false)
  298.         end  
  299.       else
  300.         if $Trainer.party[0].hp>0 && !$Trainer.party[0].isEgg? && $scene.is_a?(Scene_Map)
  301.           events=$PokemonGlobal.dependentEvents
  302.           if animation
  303.             for i in 0...events.length
  304.               $scene.spriteset.addUserAnimation(Animation_Come_Out,@realEvents[i].x,@realEvents[i].y)
  305.               pbWait(10)
  306.             end
  307.           end
  308.           change_sprite($Trainer.party[0].species, shiny, false, form, $Trainer.party[0].gender, shadow)
  309.         elsif $Trainer.party[0].hp<=0 || $Trainer.party[0].isEgg?
  310.           remove_sprite(animation)
  311.         end
  312.       end
  313.     else
  314.       check_faint
  315.     end
  316.   end
  317. #===============================================================================
  318. # * change_sprite(id, shiny, animation)
  319. # * Example, to change sprite to shiny lugia with animation:
  320. #     change_sprite(249, true, true)
  321. # * If just change sprite:
  322. #     change_sprite(249)
  323. #===============================================================================
  324.   def change_sprite(id, shiny=nil, animation=nil, form=nil, gender=nil, shadow=false)
  325.     events=$PokemonGlobal.dependentEvents
  326.     for i in 0...events.length
  327.       if events[i] && events[i][8]=="Dependent"
  328.         tgender = (gender==1)? "f" : ""
  329.         tshiny  = (shiny)? "s" : ""
  330.         tform   = (form && form>0) ? "_#{form}" : ""
  331.         tshadow = (shadow)? "_shadow": ""
  332.         speciesname = getConstantName(PBSpecies,id)
  333.         bitmapFileName=sprintf("%s%s%s%s%s",speciesname,tgender,tshiny,tform,tshadow)
  334.         if pbResolveBitmap(FOLLOWER_FILE_PATH+FOLLOWER_FILE_DIR+bitmapFileName)
  335.           events[i][6] = FOLLOWER_FILE_DIR+bitmapFileName
  336.           @realEvents[i].character_name=FOLLOWER_FILE_DIR+bitmapFileName
  337.         else
  338.           bitmapFileName=sprintf("%s%s",speciesname,tshiny)
  339.           if pbResolveBitmap(FOLLOWER_FILE_PATH+FOLLOWER_FILE_DIR+bitmapFileName)
  340.             events[i][6] = FOLLOWER_FILE_DIR+bitmapFileName
  341.             @realEvents[i].character_name=FOLLOWER_FILE_DIR+bitmapFileName
  342.           else
  343.             bitmapFileName=sprintf("%s",speciesname)
  344.             if pbResolveBitmap(FOLLOWER_FILE_PATH+FOLLOWER_FILE_DIR+bitmapFileName)
  345.               events[i][6] = FOLLOWER_FILE_DIR+bitmapFileName
  346.               @realEvents[i].character_name=FOLLOWER_FILE_DIR+bitmapFileName
  347.             else  
  348.               bitmapFileName=sprintf("%03d%s%s%s%s",id,tgender,tshiny,tform,tshadow)
  349.               if pbResolveBitmap(FOLLOWER_FILE_PATH+FOLLOWER_FILE_DIR+bitmapFileName)
  350.                 events[i][6] = FOLLOWER_FILE_DIR+bitmapFileName
  351.                 @realEvents[i].character_name=FOLLOWER_FILE_DIR+bitmapFileName
  352.               else  
  353.                 bitmapFileName=sprintf("%03d%s%s%s",id,tshiny,tform,tshadow)
  354.                 if pbResolveBitmap(FOLLOWER_FILE_PATH+FOLLOWER_FILE_DIR+bitmapFileName)
  355.                   events[i][6] = FOLLOWER_FILE_DIR+bitmapFileName
  356.                   @realEvents[i].character_name=FOLLOWER_FILE_DIR+bitmapFileName
  357.                 else
  358.                   bitmapFileName=sprintf("%03d%s",id,tshiny)
  359.                   if pbResolveBitmap(FOLLOWER_FILE_PATH+FOLLOWER_FILE_DIR+bitmapFileName)
  360.                     events[i][6] = FOLLOWER_FILE_DIR+bitmapFileName
  361.                     @realEvents[i].character_name=FOLLOWER_FILE_DIR+bitmapFileName
  362.                   else
  363.                     bitmapFileName=sprintf("%03d",id)
  364.                     events[i][6] = FOLLOWER_FILE_DIR+bitmapFileName
  365.                     @realEvents[i].character_name=FOLLOWER_FILE_DIR+bitmapFileName
  366.                   end
  367.                 end
  368.               end
  369.             end
  370.           end
  371.         end
  372.         if animation
  373.           $scene.spriteset.addUserAnimation(Animation_Come_Out,@realEvents[i].x,@realEvents[i].y)
  374.         end
  375.         $game_variables[Walking_Time_Variable]=0
  376.       end
  377.     end
  378.   end
  379. #===============================================================================
  380. # * update_stepping
  381. # * Adds step animation for followers
  382. #===============================================================================  
  383.   def update_stepping
  384.     FollowingMoveRoute([PBMoveRoute::StepAnimeOn])
  385.   end
  386.  
  387.   def stop_stepping
  388.     FollowingMoveRoute([PBMoveRoute::StepAnimeOff])
  389.   end
  390. #===============================================================================
  391. # * remove_sprite(animation)
  392. # * Example, to remove sprite with animation:
  393. #     remove_sprite(true)
  394. # * If just remove sprite:
  395. #     remove_sprite
  396. #===============================================================================
  397.   def remove_sprite(animation=nil)
  398.     events=$PokemonGlobal.dependentEvents
  399.     for i in 0...events.length
  400.       if events[i] && events[i][8]=="Dependent"
  401.         events[i][6]=sprintf("nil")
  402.         @realEvents[i].character_name=sprintf("nil")
  403.         if animation==true
  404.           $scene.spriteset.addUserAnimation(Animation_Come_In,@realEvents[i].x,@realEvents[i].y)
  405.           pbWait(10)
  406.         end
  407.         $game_variables[Current_Following_Variable]=$Trainer.party[0]
  408.         $game_variables[Walking_Time_Variable]=0
  409.       end
  410.     end
  411.   end
  412. #===============================================================================
  413. # * check_surf(animation)
  414. # * If current Pokemon is a water Pokemon, it is still following.
  415. # * If current Pokemon is not a water Pokemon, remove sprite.
  416. # * Require Water_Pokemon_Can_Surf = true to enable
  417. #===============================================================================
  418.   def check_surf(animation=nil)
  419.     if $Trainer.party[0].hp>0 && !$Trainer.party[0].isEgg?
  420.       if ALWAYS_ANIMATED_CAN_SURF && ($Trainer.party[0].hasType?(:FLYING) ||
  421.         isConst?($Trainer.party[0].ability,PBAbilities,:LEVITATE) ||
  422.         ALWAYS_ANIMATED_FOLLOWERS.include?($Trainer.party[0].species)) &&
  423.         !(ALWAYS_ANIMATED_EXCEPTION.include?($Trainer.party[0].species))
  424.        
  425.           #do nothing
  426.       elsif $Trainer.party[0].hasType?(:WATER) && WATERPOKEMONCANSURF
  427.         #do nothing
  428.       else
  429.         remove_sprite(animation)
  430.       end
  431.      
  432.     end
  433.   end
  434. #===============================================================================
  435. # * talk_to_pokemon
  436. # * It will run when you talk to Pokemon following
  437. #===============================================================================
  438.   def talk_to_pokemon
  439.     e=$Trainer.party[0]
  440.     events=$PokemonGlobal.dependentEvents
  441.     for i in 0...events.length
  442.       if events[i] && events[i][8]=="Dependent"
  443.         pos_x=@realEvents[i].x
  444.         pos_y=@realEvents[i].y
  445.         case $game_player.direction
  446.         when 2 # Facing Down
  447.           return if $game_player.x != pos_x
  448.           return if $game_player.y != pos_y-1
  449.         when 4 # Facing Left
  450.           return if $game_player.x != pos_x+1
  451.           return if $game_player.y != pos_y
  452.         when 6 # Facing Right
  453.           return if $game_player.x != pos_x-1
  454.           return if $game_player.y != pos_y
  455.         when 8 # Facing Up
  456.           return if $game_player.x != pos_x
  457.           return if $game_player.y != pos_y+1
  458.         else
  459.           return false
  460.         end
  461.       end
  462.     end
  463.     if e!=0
  464.       if e.hp>0 && !$Trainer.party[0].isEgg?        
  465.         if $PokemonGlobal.bicycle
  466.           return
  467.         elsif $PokemonGlobal.surfing
  468.           flag = true
  469.           if WATERPOKEMONCANSURF && $Trainer.party[0].hasType?(:WATER)
  470.             flag = false
  471.           elsif ALWAYS_ANIMATED_CAN_SURF && ($Trainer.party[0].hasType?(:FLYING) ||
  472.               isConst?($Trainer.party[0].ability,PBAbilities,:LEVITATE) ||
  473.               ALWAYS_ANIMATED_FOLLOWERS.include?($Trainer.party[0].species)) &&
  474.               !(ALWAYS_ANIMATED_EXCEPTION.include?($Trainer.party[0].species))
  475.             flag = false
  476.           end
  477.           return if flag
  478.         elsif $PokemonGlobal.diving && (!WATERPOKEMONCANDIVE || !$Trainer.party[0].hasType?(:WATER))
  479.           return
  480.         end
  481. #===============================================================================
  482. # * Checks to make sure the Pokemon isn't blocking a surfable water surface
  483. # * If the water is blocked by the sprite (even though it is invisible) and
  484. #   the player should be able to surf, calls surf
  485. #===============================================================================
  486.         terrain=Kernel.pbFacingTerrainTag
  487.         notCliff=$game_map.passable?($game_player.x,$game_player.y,$game_player.direction)
  488.         if PBTerrain.isWater?(terrain) || !notCliff
  489.           if !pbGetMetadata($game_map.map_id,MetadataBicycleAlways) && !$PokemonGlobal.surfing
  490.             if $DEBUG
  491.               Kernel.pbSurf
  492.               return
  493.             elsif (HIDDENMOVESCOUNTBADGES ? $Trainer.numbadges>=BADGEFORSURF : $Trainer.badges[BADGEFORSURF])
  494.               Kernel.pbSurf
  495.               return
  496.             end
  497.           end
  498.         end
  499. #===============================================================================
  500. # * talk_to_pokemon when possible begins here
  501. #===============================================================================
  502.         if e!=6 && $game_switches[Toggle_Following_Switch]==true
  503.           pbPlayCry(e.species)
  504.           random1=rand(7) # random message if no special conditions apply
  505.           mapname=$game_map.name # Get's current map name
  506. #===============================================================================
  507. # * Pokemon Messages when Status Condition
  508. #===============================================================================          
  509.           if e.status==PBStatuses::POISON && e.hp>0 && !e.isEgg? # Pokemon Poisoned
  510.             $scene.spriteset.addUserAnimation(Emo_Poison, pos_x, pos_y-2)
  511.             pbWait(120)
  512.             Kernel.pbMessage(_INTL("{1} is shivering with the effects of being poisoned.",e.name))
  513.            
  514.           elsif e.status==PBStatuses::BURN && e.hp>0 && !e.isEgg? # Pokemon Burned
  515.             $scene.spriteset.addUserAnimation(Emo_Hate, pos_x, pos_y-2)
  516.             pbWait(70)
  517.             Kernel.pbMessage(_INTL("{1}'s burn looks painful.",e.name))
  518.            
  519.           elsif e.status==PBStatuses::FROZEN && e.hp>0 && !e.isEgg? # Pokemon Frozen
  520.             $scene.spriteset.addUserAnimation(Emo_Normal, pos_x, pos_y-2)
  521.             pbWait(100)
  522.             Kernel.pbMessage(_INTL("{1} seems very cold. It's frozen solid!",e.name))
  523.          
  524.           elsif e.status==PBStatuses::SLEEP && e.hp>0 && !e.isEgg? # Pokemon Asleep
  525.             $scene.spriteset.addUserAnimation(Emo_Normal, pos_x, pos_y-2)
  526.             pbWait(100)
  527.             Kernel.pbMessage(_INTL("{1} seems really tired.",e.name))
  528.            
  529.           elsif e.status==PBStatuses::PARALYSIS && e.hp>0 && !e.isEgg? # Pokemon Paralyzed
  530.             $scene.spriteset.addUserAnimation(Emo_Normal, pos_x, pos_y-2)
  531.             pbWait(100)
  532.             Kernel.pbMessage(_INTL("{1} is standing still and twitching.",e.name))
  533. #===============================================================================
  534. # * Pokemon is holding an item on a Specific Map
  535. #===============================================================================          
  536.           elsif $game_variables[ItemWalk]==15 and mapname=="Item Map" # Pokemon has item and is on map "Item Map"
  537.             items=[:MASTERBALL,:MASTERBALL] # This array can be edited and extended. Look at the one below for a guide
  538.             random2=0
  539.             loop do
  540.               random2=rand(items.length)
  541.               break if hasConst?(PBItems,items[random2])
  542.             end
  543.             Kernel.pbMessage(_INTL("{1} seems to be holding something.",e.name))
  544.             Kernel.pbPokemonFound(getConst(PBItems,items[random2]))
  545.             $game_variables[ItemWalk]=0
  546. #===============================================================================
  547. # * Pokemon is holding an item on any other map
  548. #===============================================================================            
  549.           elsif $game_variables[ItemWalk]==15 # Pokemon has Item
  550.             items=[:POTION,:SUPERPOTION,:FULLRESTORE,:REVIVE,:PPUP,
  551.                  :PPMAX,:RARECANDY,:REPEL,:MAXREPEL,:ESCAPEROPE,
  552.                  :HONEY,:TINYMUSHROOM,:PEARL,:NUGGET,:GREATBALL,
  553.                  :ULTRABALL,:THUNDERSTONE,:MOONSTONE,:SUNSTONE,:DUSKSTONE,
  554.                  :REDAPRICORN,:BLUAPRICORN,:YLWAPRICORN,:GRNAPRICORN,:PNKAPRICORN,
  555.                  :BLKAPRICORN,:WHTAPRICORN
  556.             ]
  557.             random2=0
  558.             loop do
  559.               random2=rand(items.length)
  560.               break if hasConst?(PBItems,items[random2])
  561.             end
  562.  
  563.             Kernel.pbMessage(_INTL("{1} seems to be holding something.",e.name))
  564.             Kernel.pbPokemonFound(getConst(PBItems,items[random2]))
  565.             $game_variables[ItemWalk]=0
  566. #===============================================================================
  567. # * Examples of Map Specific Messages
  568. #===============================================================================
  569.           elsif mapname=="Dusk Forest" && e.hasType?(:BUG) # Bug Type in Dusk Forest
  570.             $scene.spriteset.addUserAnimation(Emo_sing, pos_x, pos_y-2)
  571.             pbWait(50)
  572.             random3=rand(3)
  573.             if random3==0
  574.               Kernel.pbMessage(_INTL("{1} seems highly interested in the trees.",e.name,$Trainer.name))
  575.             elsif random3==1
  576.               Kernel.pbMessage(_INTL("{1} seems to enjoy the buzzing of the bug Pokémon.",e.name,$Trainer.name))
  577.             elsif random3==2
  578.               Kernel.pbMessage(_INTL("{1} is jumping around restlessly in the forest.",e.name,$Trainer.name))
  579.             end
  580.          
  581.           elsif mapname=="Old Lab" # In the Old Lab
  582.             $scene.spriteset.addUserAnimation(Emo_Normal, pos_x, pos_y-2)
  583.             pbWait(100)
  584.             random3=rand(3)
  585.             if random3==0
  586.               Kernel.pbMessage(_INTL("{1} is touching some kind of switch.",e.name,$Trainer.name))
  587.             elsif random3==1
  588.               Kernel.pbMessage(_INTL("{1} has a cord in its mouth!",e.name,$Trainer.name))
  589.             elsif random3==2
  590.               Kernel.pbMessage(_INTL("{1} seems to want to touch the machinery.",e.name,$Trainer.name))
  591.             end  
  592.            
  593.           elsif mapname=="Home" # In the Player's Home
  594.             $scene.spriteset.addUserAnimation(Emo_Happy, pos_x, pos_y-2)
  595.             pbWait(70)
  596.             random3=rand(3)
  597.             if random3==0
  598.               Kernel.pbMessage(_INTL("{1} is sniffing around the room.",e.name,$Trainer.name))
  599.             elsif random3==1
  600.               Kernel.pbMessage(_INTL("{1} noticed {2}'s mom is nearby.",e.name,$Trainer.name))
  601.             elsif random3==2
  602.               Kernel.pbMessage(_INTL("{1} seems to want to settle down at home.",e.name,$Trainer.name))
  603.             end
  604. #===============================================================================
  605. # * Pokemon Messages when birthday
  606. # * Support for Pokemon Birthsigns script
  607. #===============================================================================          
  608.           elsif defined?(e.isBirthday?) && e.isBirthday?
  609.             $scene.spriteset.addUserAnimation(Emo_Cake, pos_x, pos_y-2)
  610.             pbWait(50)
  611.             messages=rand(10)
  612.             case messages
  613.             when 0
  614.               Kernel.pbMessage(_INTL("{1} seems to be reminiscing on all it has learned in the last year.",e.name,$Trainer.name))
  615.             when 1
  616.               Kernel.pbMessage(_INTL("{1} seems glad to be spending its birthday with {2}.",e.name,$Trainer.name))
  617.             when 2
  618.               Kernel.pbMessage(_INTL("{1} is having the best birthday ever!",e.name,$Trainer.name))
  619.             when 3
  620.               Kernel.pbMessage(_INTL("{1} can't believe its been a whole year already!",e.name,$Trainer.name))
  621.             when 4
  622.               Kernel.pbMessage(_INTL("{1} seems to be sniffing around for presents...",e.name,$Trainer.name))
  623.             when 5
  624.               Kernel.pbMessage(_INTL("{1} seems a bit out of breath...\nYou're getting old!",e.name,$Trainer.name))
  625.             when 6
  626.               Kernel.pbMessage(_INTL("{1} looks ready to party!",e.name,$Trainer.name))
  627.             when 7
  628.               Kernel.pbMessage(_INTL("You wish {1} a happy birthday.\nHappy birthday, {1}!",e.name,$Trainer.name))
  629.             when 8
  630.               Kernel.pbMessage(_INTL("{1} seems to be looking forward to another year with {2}.",e.name,$Trainer.name))
  631.             when 9
  632.               Kernel.pbMessage(_INTL("{1} wants to eat some cake!",e.name,$Trainer.name))
  633.             end
  634. #===============================================================================
  635. # * Random Messages if none of the above apply
  636. #===============================================================================            
  637.           elsif random1==0 # Music Note
  638.             $scene.spriteset.addUserAnimation(Emo_sing, pos_x, pos_y-2)
  639.             pbWait(50)
  640.             random3=rand(5)
  641.             if random3==0
  642.               Kernel.pbMessage(_INTL("{1} seems to want to play with {2}.",e.name,$Trainer.name))
  643.             elsif random3==1
  644.               Kernel.pbMessage(_INTL("{1} is singing and humming.",e.name,$Trainer.name))
  645.             elsif random3==2
  646.               Kernel.pbMessage(_INTL("{1} is looking up at the sky.",e.name,$Trainer.name))
  647.             elsif random3==3
  648.               Kernel.pbMessage(_INTL("{1} swayed and danced around as it pleased.",e.name,$Trainer.name))
  649.             elsif random3==4
  650.               Kernel.pbMessage(_INTL("{1} is pulling out the grass.",e.name,$Trainer.name))
  651.             end
  652.            
  653.           elsif random1==1 # Hate/Angry Face
  654.             $scene.spriteset.addUserAnimation(Emo_Hate, pos_x, pos_y-2)
  655.             pbWait(70)
  656.             random3=rand(5)
  657.             if random3==0
  658.               Kernel.pbMessage(_INTL("{1} let out a roar!",e.name,$Trainer.name))
  659.             elsif random3==1
  660.               Kernel.pbMessage(_INTL("{1} is making a face like it's angry!",e.name,$Trainer.name))
  661.             elsif random3==2
  662.               Kernel.pbMessage(_INTL("{1} seems to be angry for some reason.",e.name,$Trainer.name))
  663.             elsif random3==3
  664.               Kernel.pbMessage(_INTL("{1} chewed on your feet.",e.name,$Trainer.name))
  665.             elsif random3==4
  666.               Kernel.pbMessage(_INTL("{1} is trying to be intimidating.",e.name,$Trainer.name))
  667.             end
  668.            
  669.           elsif random1==2 # ... Emoji
  670.             $scene.spriteset.addUserAnimation(Emo_Normal, pos_x, pos_y-2)
  671.             pbWait(70)
  672.             random3=rand(5)
  673.             if random3==0
  674.               Kernel.pbMessage(_INTL("{1} is looking down steadily.",e.name,$Trainer.name))
  675.             elsif random3==1
  676.               Kernel.pbMessage(_INTL("{1} is sniffing at the floor.",e.name,$Trainer.name))
  677.             elsif random3==2
  678.               Kernel.pbMessage(_INTL("{1} is concentrating deeply.",e.name,$Trainer.name))
  679.             elsif random3==3
  680.               Kernel.pbMessage(_INTL("{1} faced this way and nodded.",e.name,$Trainer.name))
  681.             elsif random3==4
  682.               Kernel.pbMessage(_INTL("{1} is glaring straight into {2}'s eyes.",e.name,$Trainer.name))
  683.             end
  684.            
  685.           elsif random1==3 # Happy Face
  686.             $scene.spriteset.addUserAnimation(Emo_Happy, pos_x, pos_y-2)
  687.             pbWait(70)
  688.             random3=rand(5)
  689.             if random3==0
  690.               Kernel.pbMessage(_INTL("{1} began poking you in the stomach.",e.name,$Trainer.name))
  691.             elsif random3==1
  692.               Kernel.pbMessage(_INTL("{1} looks very happy.",e.name,$Trainer.name))
  693.             elsif random3==2
  694.               Kernel.pbMessage(_INTL("{1} happily cuddled up to you.",e.name,$Trainer.name))
  695.             elsif random3==3
  696.               Kernel.pbMessage(_INTL("{1} is so happy that it can't stand still.",e.name,$Trainer.name))
  697.             elsif random3==4
  698.               Kernel.pbMessage(_INTL("{1} looks like it wants to lead!",e.name,$Trainer.name))
  699.             end
  700.            
  701.           elsif random1==4 # Heart Emoji
  702.             $scene.spriteset.addUserAnimation(Emo_love, pos_x, pos_y-2)
  703.             pbWait(70)
  704.             random3=rand(5)
  705.             if random3==0
  706.               Kernel.pbMessage(_INTL("{1} suddenly started walking closer.",e.name,$Trainer.name))
  707.             elsif random3==1
  708.               Kernel.pbMessage(_INTL("Woah! {1} suddenly hugged {2}.",e.name,$Trainer.name))
  709.             elsif random3==2
  710.               Kernel.pbMessage(_INTL("{1} is rubbing up against you.",e.name,$Trainer.name))
  711.             elsif random3==3
  712.               Kernel.pbMessage(_INTL("{1} is keeping close to {2}.",e.name,$Trainer.name))
  713.             elsif random3==4
  714.               Kernel.pbMessage(_INTL("{1} blushed.",e.name,$Trainer.name))
  715.             end
  716.            
  717.           elsif random1==5 # No Emoji
  718.             random3=rand(5)
  719.             if random3==0
  720.               Kernel.pbMessage(_INTL("{1} spun around in a circle!",e.name,$Trainer.name))
  721.             elsif random3==1
  722.               Kernel.pbMessage(_INTL("{1} let our a battle cry.",e.name,$Trainer.name))
  723.             elsif random3==2
  724.               Kernel.pbMessage(_INTL("{1} is on the lookout!",e.name,$Trainer.name))
  725.             elsif random3==3
  726.               Kernel.pbMessage(_INTL("{1} is standing patiently.",e.name,$Trainer.name))
  727.             elsif random3==4
  728.               Kernel.pbMessage(_INTL("{1} is looking around restlessly.",e.name,$Trainer.name))
  729.             end
  730. #===============================================================================
  731. # * This random message shows the Pokemon's Happiness Level
  732. #===============================================================================            
  733.           elsif random1==6 # Check Happiness Level
  734.             if e.happiness>0 && e.happiness<=50
  735.               $scene.spriteset.addUserAnimation(Emo_Hate, pos_x, pos_y-2)
  736.               pbWait(70)
  737.               Kernel.pbMessage(_INTL("{1} hates to travel with {2}.",e.name,$Trainer.name))
  738.             elsif e.happiness>50 && e.happiness<=100
  739.               $scene.spriteset.addUserAnimation(Emo_Normal, pos_x, pos_y-2)
  740.               pbWait(100)
  741.               Kernel.pbMessage(_INTL("{1} is still unsure about traveling with {2} is a good thing or not.",e.name,$Trainer.name))
  742.             elsif e.happiness>100 && e.happiness<150
  743.               $scene.spriteset.addUserAnimation(Emo_Happy, pos_x, pos_y-2)
  744.               Kernel.pbMessage(_INTL("{1} is happy traveling with {2}.",e.name,$Trainer.name))
  745.             elsif e.happiness>=150
  746.               $scene.spriteset.addUserAnimation(Emo_love, pos_x, pos_y-2)
  747.               pbWait(70)
  748.               Kernel.pbMessage(_INTL("{1} loves traveling with {2}.",e.name,$Trainer.name))
  749.             end
  750.           end
  751.         else
  752.         end
  753.     end
  754.   end
  755. end
  756. #===============================================================================
  757. # * Pokemon reapear after using surf
  758. #===============================================================================
  759. def Come_back(shiny=nil, animation=nil)
  760.   return if !$game_variables[Following_Activated_Switch]
  761.   return if $Trainer.party.length==0
  762.   $PokemonTemp.dependentEvents.pbMoveDependentEvents
  763.   events=$PokemonGlobal.dependentEvents
  764.   if $game_variables[Current_Following_Variable]==$Trainer.party[0]
  765.     remove_sprite(false)
  766.     if $scene.is_a?(Scene_Map)
  767.       for i in 0...events.length
  768.         $scene.spriteset.addUserAnimation(Animation_Come_Out,@realEvents[i].x,@realEvents[i].y)
  769.       end
  770.     end
  771.   end
  772.   if $Trainer.party[0].hp>0 && !$Trainer.party[0].isEgg?
  773.     $game_variables[Current_Following_Variable]=$Trainer.party[0]
  774.     refresh_sprite(animation)
  775.   end
  776.   for i in 0...events.length
  777.     if events[i] && events[i][8]=="Dependent"
  778.       id = $Trainer.party[0].species
  779.       tgender = ($Trainer.party[0].gender==1)? "f" : ""
  780.       tshiny  = ($Trainer.party[0].isShiny?)? "s" : ""
  781.       tform   = ($Trainer.party[0].form && $Trainer.party[0].form>0) ? "_#{$Trainer.party[0].form}" : ""
  782.       tshadow = ($Trainer.party[0].shadow)? "_shadow": ""
  783.       speciesname = getConstantName(PBSpecies,id)
  784.       bitmapFileName=sprintf("%s%s%s%s%s",speciesname,tgender,tshiny,tform,tshadow)
  785.       if pbResolveBitmap(FOLLOWER_FILE_PATH+FOLLOWER_FILE_DIR+bitmapFileName)
  786.         events[i][6] = FOLLOWER_FILE_DIR+bitmapFileName
  787.         @realEvents[i].character_name=FOLLOWER_FILE_DIR+bitmapFileName
  788.       else
  789.         bitmapFileName=sprintf("%s%s",speciesname,tshiny)
  790.         if pbResolveBitmap(FOLLOWER_FILE_PATH+FOLLOWER_FILE_DIR+bitmapFileName)
  791.           events[i][6] = FOLLOWER_FILE_DIR+bitmapFileName
  792.           @realEvents[i].character_name=FOLLOWER_FILE_DIR+bitmapFileName
  793.         else
  794.           bitmapFileName=sprintf("%s",speciesname)
  795.           if pbResolveBitmap(FOLLOWER_FILE_PATH+FOLLOWER_FILE_DIR+bitmapFileName)
  796.             events[i][6] = FOLLOWER_FILE_DIR+bitmapFileName
  797.             @realEvents[i].character_name=FOLLOWER_FILE_DIR+bitmapFileName
  798.           else  
  799.             bitmapFileName=sprintf("%03d%s%s%s%s",id,tgender,tshiny,tform,tshadow)
  800.             if pbResolveBitmap(FOLLOWER_FILE_PATH+FOLLOWER_FILE_DIR+bitmapFileName)
  801.               events[i][6] = FOLLOWER_FILE_DIR+bitmapFileName
  802.               @realEvents[i].character_name=FOLLOWER_FILE_DIR+bitmapFileName
  803.             else  
  804.               bitmapFileName=sprintf("%03d%s",id,tshiny)
  805.               if pbResolveBitmap(FOLLOWER_FILE_PATH+FOLLOWER_FILE_DIR+bitmapFileName)
  806.                 events[i][6] = FOLLOWER_FILE_DIR+bitmapFileName
  807.                 @realEvents[i].character_name=FOLLOWER_FILE_DIR+bitmapFileName
  808.               else
  809.                 bitmapFileName=sprintf("%03d",id)
  810.                 events[i][6] = FOLLOWER_FILE_DIR+bitmapFileName
  811.                 @realEvents[i].character_name=FOLLOWER_FILE_DIR+bitmapFileName
  812.               end
  813.             end
  814.           end
  815.         end
  816.       end
  817.     end
  818.   end
  819. end
  820. #===============================================================================
  821. # * check_faint
  822. # * If current Pokemon is fainted, removes the sprite
  823. #===============================================================================
  824. def check_faint
  825.   return if !$game_switches[Following_Activated_Switch] || $Trainer.party.length<=0
  826.   if $PokemonGlobal.bicycle
  827.     return
  828.   elsif $PokemonGlobal.diving && WATERPOKEMONCANDIVE && $Trainer.party[0].hasType?(:WATER)
  829.     return
  830.   elsif $PokemonGlobal.surfing && WATERPOKEMONCANSURF && $Trainer.party[0].hasType?(:WATER)
  831.     return
  832.   elsif $PokemonGlobal.surfing && ALWAYS_ANIMATED_CAN_SURF && ($Trainer.party[0].hasType?(:FLYING) ||
  833.         isConst?($Trainer.party[0].ability,PBAbilities,:LEVITATE) ||
  834.         ALWAYS_ANIMATED_FOLLOWERS.include?($Trainer.party[0].species)) &&
  835.         !(ALWAYS_ANIMATED_EXCEPTION.include?($Trainer.party[0].species))
  836.     return
  837.   else
  838.     if $Trainer.party[0].hp<=0
  839.       $game_variables[Current_Following_Variable]=0
  840.       remove_sprite
  841.     elsif $Trainer.party[0].hp>0 && !$Trainer.party[0].isEgg? && $game_variables[Current_Following_Variable]==0
  842.         $game_variables[Current_Following_Variable]=$Trainer.party[0]
  843.         refresh_sprite
  844.     end
  845.   end
  846. end
  847. #===============================================================================
  848. # * SetMoveRoute
  849. # * Used in the "Control Following Pokemon" Script listed farther above
  850. #===============================================================================
  851. def SetMoveRoute(commands,waitComplete=true)
  852.     events=$PokemonGlobal.dependentEvents
  853.     for i in 0...events.length
  854.       if events[i] && events[i][8]=="Dependent"
  855.         pbMoveRoute(@realEvents[i],commands,waitComplete)
  856.       end
  857.     end
  858.   end
  859. end
  860.  
  861.  
  862.  
  863. #===============================================================================
  864. # * Update followers for surfing
  865. # * Non-follower dependent events not allowed
  866. #===============================================================================
  867. def Kernel.pbSurf
  868.   if $game_player.pbHasDependentEvents? && !$game_switches[Following_Activated_Switch]
  869.     return false
  870.   end
  871.   if $DEBUG ||
  872.     (HIDDENMOVESCOUNTBADGES ? $Trainer.numbadges>=BADGEFORSURF : $Trainer.badges[BADGEFORSURF])
  873.     movefinder=Kernel.pbCheckMove(:SURF)
  874.     if $DEBUG || movefinder
  875.       if Kernel.pbConfirmMessage(_INTL("The water is dyed a deep blue...  Would you like to surf?"))
  876.         speciesname=!movefinder ? $Trainer.name : movefinder.name
  877.         Kernel.pbMessage(_INTL("{1} used Surf!",speciesname))
  878.         pbHiddenMoveAnimation(movefinder)
  879.         surfbgm=pbGetMetadata(0,MetadataSurfBGM)
  880.         $PokemonTemp.dependentEvents.check_surf(true)
  881.         if surfbgm
  882.           pbCueBGM(surfbgm,0.5)
  883.         end
  884.         pbStartSurfing()
  885.         return true
  886.       end
  887.     end
  888.   end
  889.   return false
  890. end
  891.  
  892. alias follow_pbStartSurfing pbStartSurfing
  893. def pbStartSurfing()
  894.   follow_pbStartSurfing
  895.   $PokemonGlobal.surfing=true
  896. end
  897.  
  898. alias follow_pbEndSurf pbEndSurf
  899. def pbEndSurf(xOffset,yOffset)
  900.   ret = follow_pbEndSurf(xOffset,yOffset)
  901.   if $game_switches[Toggle_Following_Switch] && ret && $game_variables[Current_Following_Variable]!=0
  902.     if WATERPOKEMONCANSURF && $Trainer.party[0].hasType?(:WATER)
  903.       $PokemonTemp.dependentEvents.Come_back($Trainer.party[0].isShiny?,false)
  904.     elsif ALWAYS_ANIMATED_CAN_SURF && ($Trainer.party[0].hasType?(:FLYING) ||
  905.         isConst?($Trainer.party[0].ability,PBAbilities,:LEVITATE) ||
  906.         ALWAYS_ANIMATED_FOLLOWERS.include?($Trainer.party[0].species)) &&
  907.         !(ALWAYS_ANIMATED_EXCEPTION.include?($Trainer.party[0].species))
  908.         $PokemonTemp.dependentEvents.Come_back($Trainer.party[0].isShiny?,false)
  909.     else
  910.       $PokemonTemp.dependentEvents.Come_back(true)
  911.     end
  912.   end
  913. end
  914.  
  915. #===============================================================================
  916. # * Auto add Script to Kernel.pbCanUseHiddenMove, fix HM bug
  917. # * Fixed so non-pokemon follower dependent events will return false
  918. #===============================================================================
  919. def Kernel.pbCanUseHiddenMove?(pkmn,move,showmsg=true)
  920.   case move
  921.     when PBMoves::FLY
  922.       if !$DEBUG && !$Trainer.badges[BADGEFORFLY]
  923.         Kernel.pbMessage(_INTL("Sorry, a new Badge is required.")) if showmsg
  924.         return false
  925.       end
  926.      if $game_player.pbHasDependentEvents? && !$game_switches[Following_Activated_Switch]
  927.        Kernel.pbMessage(_INTL("You can't use that if you have someone with you.")) if showmsg
  928.        return false
  929.      end
  930.       if !pbGetMetadata($game_map.map_id,MetadataOutdoor)
  931.         Kernel.pbMessage(_INTL("Can't use that here.")) if showmsg
  932.         return false
  933.       end
  934.       return true
  935.     when PBMoves::CUT
  936.       if !$DEBUG && !$Trainer.badges[BADGEFORCUT]
  937.         Kernel.pbMessage(_INTL("Sorry, a new Badge is required.")) if showmsg
  938.         return false
  939.       end
  940.       facingEvent=$game_player.pbFacingEvent
  941.       if !facingEvent || facingEvent.name!="Tree"
  942.         Kernel.pbMessage(_INTL("Can't use that here.")) if showmsg
  943.         return false
  944.       end
  945.       return true
  946.     when PBMoves::HEADBUTT
  947.       facingEvent=$game_player.pbFacingEvent
  948.       if !facingEvent || facingEvent.name!="HeadbuttTree"
  949.         Kernel.pbMessage(_INTL("Can't use that here.")) if showmsg
  950.         return false
  951.       end
  952.       return true
  953.     when PBMoves::SURF
  954.       terrain=Kernel.pbFacingTerrainTag
  955.       if !$DEBUG && !$Trainer.badges[BADGEFORSURF]
  956.         Kernel.pbMessage(_INTL("Sorry, a new Badge is required.")) if showmsg
  957.         return false
  958.       end
  959.       if $PokemonGlobal.surfing
  960.         Kernel.pbMessage(_INTL("You're already surfing.")) if showmsg
  961.         return false
  962.       end
  963.       if $game_player.pbHasDependentEvents? && !$game_switches[Following_Activated_Switch]
  964.          Kernel.pbMessage(_INTL("You can't use that if you have someone with you.")) if showmsg
  965.          return false
  966.       end
  967.       terrain=Kernel.pbFacingTerrainTag
  968.       if pbGetMetadata($game_map.map_id,MetadataBicycleAlways)
  969.         Kernel.pbMessage(_INTL("Let's enjoy cycling!")) if showmsg
  970.         return false
  971.       end
  972.       if !PBTerrain.isWater?(terrain)
  973.         Kernel.pbMessage(_INTL("No surfing here!")) if showmsg
  974.         return false
  975.       end
  976.       return true
  977.     when PBMoves::STRENGTH
  978.       if !$DEBUG && !$Trainer.badges[BADGEFORSTRENGTH]
  979.         Kernel.pbMessage(_INTL("Sorry, a new Badge is required.")) if showmsg
  980.         return false
  981.       end
  982.       facingEvent=$game_player.pbFacingEvent
  983.       if !facingEvent || facingEvent.name!="Boulder"
  984.         Kernel.pbMessage(_INTL("Can't use that here.")) if showmsg
  985.         return false
  986.       end
  987.       return true  
  988.     when PBMoves::ROCKSMASH
  989.       terrain=Kernel.pbFacingTerrainTag
  990.       if !$DEBUG && !$Trainer.badges[BADGEFORROCKSMASH]
  991.         Kernel.pbMessage(_INTL("Sorry, a new Badge is required.")) if showmsg
  992.         return false
  993.       end
  994.       facingEvent=$game_player.pbFacingEvent
  995.       if !facingEvent || facingEvent.name!="Rock"
  996.         Kernel.pbMessage(_INTL("Can't use that here.")) if showmsg
  997.         return false
  998.       end
  999.       return true  
  1000.     when PBMoves::FLASH
  1001.       if !$DEBUG && !$Trainer.badges[BADGEFORFLASH]
  1002.         Kernel.pbMessage(_INTL("Sorry, a new Badge is required.")) if showmsg
  1003.         return false
  1004.       end
  1005.       if !pbGetMetadata($game_map.map_id,MetadataDarkMap)
  1006.         Kernel.pbMessage(_INTL("Can't use that here.")) if showmsg
  1007.         return false
  1008.       end
  1009.       if $PokemonGlobal.flashUsed
  1010.         Kernel.pbMessage(_INTL("This is in use already.")) if showmsg
  1011.         return false
  1012.       end
  1013.       return true
  1014.     when PBMoves::WATERFALL
  1015.       if !$DEBUG && !$Trainer.badges[BADGEFORWATERFALL]
  1016.         Kernel.pbMessage(_INTL("Sorry, a new Badge is required.")) if showmsg
  1017.         return false
  1018.       end
  1019.       terrain=Kernel.pbFacingTerrainTag
  1020.       if terrain!=PBTerrain::Waterfall
  1021.         Kernel.pbMessage(_INTL("Can't use that here.")) if showmsg
  1022.         return false
  1023.       end
  1024.       return true
  1025.     when PBMoves::DIVE
  1026.       if !$DEBUG && !$Trainer.badges[BADGEFORDIVE]
  1027.         Kernel.pbMessage(_INTL("Sorry, a new Badge is required.")) if showmsg
  1028.         return false
  1029.       end
  1030.       if $PokemonGlobal.diving
  1031.         return true
  1032.       end
  1033.       if $game_player.terrain_tag!=PBTerrain::DeepWater
  1034.         Kernel.pbMessage(_INTL("Can't use that here.")) if showmsg
  1035.         return false
  1036.       end
  1037.       if !pbGetMetadata($game_map.map_id,MetadataDiveMap)
  1038.         Kernel.pbMessage(_INTL("Can't use that here.")) if showmsg
  1039.         return false
  1040.       end
  1041.       return true
  1042.     when PBMoves::TELEPORT
  1043.       if !pbGetMetadata($game_map.map_id,MetadataOutdoor)
  1044.         Kernel.pbMessage(_INTL("Can't use that here.")) if showmsg
  1045.         return false
  1046.       end
  1047.      if $game_player.pbHasDependentEvents? && !$game_switches[Following_Activated_Switch]
  1048.        Kernel.pbMessage(_INTL("You can't use that if you have someone with you.")) if showmsg
  1049.        return false
  1050.      end
  1051.       healing=$PokemonGlobal.healingSpot
  1052.       if !healing
  1053.         healing=pbGetMetadata(0,MetadataHome) # Home
  1054.       end
  1055.       if healing
  1056.         mapname=pbGetMapNameFromId(healing[0])
  1057.         if Kernel.pbConfirmMessage(_INTL("Want to return to the healing spot used last in {1}?",mapname))
  1058.           return true
  1059.         end
  1060.         return false
  1061.       else
  1062.         Kernel.pbMessage(_INTL("Can't use that here.")) if showmsg
  1063.         return false
  1064.       end
  1065.     when PBMoves::DIG
  1066.       escape=($PokemonGlobal.escapePoint rescue nil)
  1067.       if !escape || escape.empty?
  1068.         Kernel.pbMessage(_INTL("Can't use that here.")) if showmsg
  1069.         return false
  1070.       end
  1071.       if $game_player.pbHasDependentEvents? && !$game_switches[Following_Activated_Switch]
  1072.         Kernel.pbMessage(_INTL("You can't use that if you have someone with you.")) if showmsg
  1073.         return false
  1074.       end
  1075.       mapname=pbGetMapNameFromId(escape[0])
  1076.       if Kernel.pbConfirmMessage(_INTL("Want to escape from here and return to {1}?",mapname))
  1077.         return true
  1078.       end
  1079.       return false
  1080.     when PBMoves::SWEETSCENT
  1081.       return true
  1082.     else
  1083.       return HiddenMoveHandlers.triggerCanUseMove(move,pkmn)
  1084.     end
  1085.   return false
  1086. end
  1087.  
  1088.  
  1089. #===============================================================================
  1090. # * Modifies bike scripts to properly affect the follower sprites
  1091. #===============================================================================
  1092. module Kernel
  1093.   class << self
  1094.     alias follow_pbDismountBike pbDismountBike
  1095.     alias follow_pbMountBike pbMountBike
  1096.     alias follow_pbCancelVehicles pbCancelVehicles
  1097.   end
  1098.  
  1099.   def self.pbDismountBike
  1100.     return if !$PokemonGlobal.bicycle
  1101.     ret=follow_pbDismountBike
  1102.     if $game_switches[Toggle_Following_Switch]
  1103.       $PokemonTemp.dependentEvents.Come_back(true)
  1104.     end
  1105.     $PokemonTemp.dependentEvents.refresh_sprite
  1106.     return ret
  1107.   end
  1108.  
  1109.   def self.pbMountBike
  1110.     ret=follow_pbMountBike
  1111.     if $game_switches[Toggle_Following_Switch]
  1112.       if pbGetMetadata($game_map.map_id,MetadataBicycleAlways)
  1113.         $PokemonTemp.dependentEvents.remove_sprite
  1114.       else
  1115.         $PokemonTemp.dependentEvents.remove_sprite(true)
  1116.       end
  1117.     end
  1118.     return ret
  1119.   end
  1120.  
  1121.   def self.pbCancelVehicles(destination=nil)
  1122.     if $game_switches[Toggle_Following_Switch] && ($PokemonGlobal.bicycle ||
  1123.                                                     $PokemonGlobal.diving) &&
  1124.                                                     destination.nil?
  1125.       $PokemonTemp.dependentEvents.Come_back(false)
  1126.     end
  1127.     return follow_pbCancelVehicles(destination)
  1128.   end
  1129.  
  1130. end
  1131.  
  1132. #===============================================================================
  1133. # * Replaces pbBikeCheck
  1134. # * Can still reject for dependent events if the pokemon follower has been removed
  1135. #===============================================================================
  1136. def pbBikeCheck
  1137.   if $PokemonGlobal.surfing ||
  1138.      (!$PokemonGlobal.bicycle && pbGetTerrainTag==PBTerrain::TallGrass)
  1139.     Kernel.pbMessage(_INTL("Can't use that here."))
  1140.     return false
  1141.   end
  1142.   if $game_player.pbHasDependentEvents? && !$game_switches[Following_Activated_Switch]
  1143.     Kernel.pbMessage(_INTL("It can't be used when you have someone with you."))
  1144.     return false
  1145.   end
  1146.   if $PokemonGlobal.bicycle
  1147.     if pbGetMetadata($game_map.map_id,MetadataBicycleAlways)
  1148.       Kernel.pbMessage(_INTL("You can't dismount your Bike here."))
  1149.       return false
  1150.     end
  1151.     return true
  1152.   else
  1153.     val=pbGetMetadata($game_map.map_id,MetadataBicycle)
  1154.     val=pbGetMetadata($game_map.map_id,MetadataOutdoor) if val==nil
  1155.     if !val
  1156.       Kernel.pbMessage(_INTL("Can't use that here."))
  1157.       return false
  1158.     end
  1159.     return true
  1160.   end
  1161. end
  1162.  
  1163.  
  1164.  
  1165. #===============================================================================
  1166. # * Refresh follower after accessing TrainerPC
  1167. #===============================================================================
  1168. alias follow_pbTrainerPC pbTrainerPC
  1169. def pbTrainerPC
  1170.   follow_pbTrainerPC
  1171.   $PokemonTemp.dependentEvents.refresh_sprite
  1172. end
  1173. #===============================================================================
  1174. # * Refresh follower after accessing TrainerPC
  1175. #===============================================================================
  1176. class TrainerPC
  1177.  
  1178.   alias follow_access access
  1179.   def access
  1180.     follow_access
  1181.     $PokemonTemp.dependentEvents.refresh_sprite
  1182.   end
  1183. end
  1184. #===============================================================================
  1185. # * Auto add Script to pbPokeCenterPC
  1186. #===============================================================================
  1187. alias follow_pbPokeCenterPC pbPokeCenterPC
  1188. def pbPokeCenterPC
  1189.   follow_pbPokeCenterPC
  1190.   $PokemonTemp.dependentEvents.refresh_sprite
  1191. end
  1192. #===============================================================================
  1193. #Fix for followers having animations (grass, etc) when toggled off
  1194. #Treats followers as if they are under a bridge when toggled
  1195. #===============================================================================
  1196. alias follow_pbGetTerrainTag pbGetTerrainTag
  1197. def pbGetTerrainTag(event=nil,countBridge=false)
  1198.   ret=follow_pbGetTerrainTag(event,countBridge)
  1199.   if event && event!=$game_player
  1200.     for devent in $PokemonGlobal.dependentEvents
  1201.       if event.id==devent[1] && (!$game_switches[Toggle_Following_Switch] ||
  1202.                                   $Trainer.party.length==0 ||
  1203.                                   $Trainer.party[0].isEgg? || $Trainer.party[0].hp<=0)
  1204.         ret = PBTerrain::Bridge
  1205.         break
  1206.       end
  1207.     end
  1208.   end
  1209.   return ret
  1210. end
  1211.  
  1212.  
  1213.  
  1214.  
  1215. #===============================================================================
  1216. # * Start Pokemon Following
  1217. # * x is the Event ID that will become the follower
  1218. #===============================================================================
  1219. def pbPokemonFollow(x)
  1220.   Kernel.pbAddDependency2(x, "Dependent", Unused_Common_Event)
  1221.   $PokemonTemp.dependentEvents.refresh_sprite
  1222.   $PokemonTemp.dependentEvents.Come_back(nil,false)
  1223.   $game_switches[Following_Activated_Switch]=true
  1224.   $game_switches[Toggle_Following_Switch]=true
  1225. end
  1226.  
  1227.  
  1228. def pbTestPass(follower,x,y,direction=nil)
  1229.   ret = $MapFactory.isPassable?(follower.map.map_id,x,y,follower)
  1230.   if !ret && $PokemonGlobal.bridge>0&&
  1231.           PBTerrain.isBridge?($MapFactory.getTerrainTag(follower.map.map_id,x,y))
  1232.     ret = true
  1233.   end
  1234.   return ret
  1235. end
  1236.  
  1237.  
  1238. class DependentEvents
  1239.  
  1240.   def pbFollowEventAcrossMaps(leader,follower,instant=false,leaderIsTrueLeader=true)
  1241.     d=leader.direction
  1242.     areConnected=$MapFactory.areConnected?(leader.map.map_id,follower.map.map_id)
  1243.     # Get the rear facing tile of leader
  1244.     facingDirection=[0,0,8,0,6,0,4,0,2][d]
  1245.     if !leaderIsTrueLeader && areConnected
  1246.       relativePos=$MapFactory.getThisAndOtherEventRelativePos(leader,follower)
  1247.       if (relativePos[1]==0 && relativePos[0]==2) # 2 spaces to the right of leader
  1248.         facingDirection=6
  1249.       elsif (relativePos[1]==0 && relativePos[0]==-2) # 2 spaces to the left of leader
  1250.         facingDirection=4
  1251.       elsif relativePos[1]==-2 && relativePos[0]==0 # 2 spaces above leader
  1252.         facingDirection=8
  1253.       elsif relativePos[1]==2 && relativePos[0]==0 # 2 spaces below leader
  1254.         facingDirection=2
  1255.       end
  1256.     end
  1257.     facings=[facingDirection] # Get facing from behind
  1258.     facings.push([0,0,4,0,8,0,2,0,6][d]) # Get right facing
  1259.     facings.push([0,0,6,0,2,0,8,0,4][d]) # Get left facing
  1260.     if !leaderIsTrueLeader
  1261.       facings.push([0,0,2,0,4,0,6,0,8][d]) # Get forward facing
  1262.     end
  1263.     mapTile=nil
  1264.     if areConnected
  1265.       bestRelativePos=-1
  1266.       oldthrough=follower.through
  1267.       follower.through=false
  1268.       for i in 0...facings.length
  1269.         facing=facings[i]
  1270.         tile=$MapFactory.getFacingTile(facing,leader)
  1271.         passable=tile && $MapFactory.isPassable?(tile[0],tile[1],tile[2],follower)
  1272.         if !passable && $PokemonGlobal.bridge>0
  1273.           passable = PBTerrain.isBridge?($MapFactory.getTerrainTag(tile[0],tile[1],tile[2]))
  1274.         elsif passable && !$PokemonGlobal.surfing && $PokemonGlobal.bridge==0      
  1275.           passable=!PBTerrain.isWater?($MapFactory.getTerrainTag(tile[0],tile[1],tile[2]))
  1276.         end
  1277.         if i==0 && !passable && tile &&
  1278.            $MapFactory.getTerrainTag(tile[0],tile[1],tile[2],true)==PBTerrain::Ledge &&
  1279.            $PokemonGlobal.bridge==0
  1280.           # If the tile isn't passable and the tile is a ledge,
  1281.           # get tile from further behind
  1282.           tile=$MapFactory.getFacingTileFromPos(tile[0],tile[1],tile[2],facing)
  1283.           passable=tile && $MapFactory.isPassable?(tile[0],tile[1],tile[2],follower)
  1284.           if passable && !$PokemonGlobal.surfing
  1285.             passable=!PBTerrain.isWater?($MapFactory.getTerrainTag(tile[0],tile[1],tile[2]))
  1286.           end
  1287.         end
  1288.         if passable
  1289.           relativePos=$MapFactory.getThisAndOtherPosRelativePos(
  1290.              follower,tile[0],tile[1],tile[2])
  1291.           distance=Math.sqrt(relativePos[0]*relativePos[0]+relativePos[1]*relativePos[1])
  1292.           if bestRelativePos==-1 || bestRelativePos>distance
  1293.             bestRelativePos=distance
  1294.             mapTile=tile
  1295.           end
  1296.           if i==0 && distance<=1 # Prefer behind if tile can move up to 1 space
  1297.             break
  1298.           end
  1299.         end
  1300.       end
  1301.       follower.through=oldthrough
  1302.     else
  1303.       tile=$MapFactory.getFacingTile(facings[0],leader)
  1304.       passable=tile && $MapFactory.isPassable?(
  1305.          tile[0],tile[1],tile[2],follower)
  1306.       mapTile=passable ? mapTile : nil
  1307.     end
  1308.     if mapTile && follower.map.map_id==mapTile[0]
  1309.       # Follower is on same map
  1310.       newX=mapTile[1]
  1311.       newY=mapTile[2]
  1312.       deltaX=(d == 6 ? -1 : d == 4 ? 1 : 0)
  1313.       deltaY=(d == 2 ? -1 : d == 8 ? 1 : 0)
  1314.       posX = newX + deltaX
  1315.       posY = newY + deltaY
  1316.       follower.move_speed=leader.move_speed # sync movespeed
  1317.       if (follower.x-newX==-1 && follower.y==newY) ||
  1318.          (follower.x-newX==1 && follower.y==newY) ||
  1319.          (follower.y-newY==-1 && follower.x==newX) ||
  1320.          (follower.y-newY==1 && follower.x==newX)
  1321.         if instant
  1322.           follower.moveto(newX,newY)
  1323.         else
  1324.           pbFancyMoveTo(follower,newX,newY)
  1325.         end
  1326.       elsif (follower.x-newX==-2 && follower.y==newY) ||
  1327.             (follower.x-newX==2 && follower.y==newY) ||
  1328.             (follower.y-newY==-2 && follower.x==newX) ||
  1329.             (follower.y-newY==2 && follower.x==newX)
  1330.         if instant
  1331.           follower.moveto(newX,newY)
  1332.         else
  1333.           pbFancyMoveTo(follower,newX,newY)
  1334.         end
  1335.       elsif follower.x!=posX || follower.y!=posY
  1336.         if instant
  1337.           follower.moveto(newX,newY)
  1338.         else
  1339.           pbFancyMoveTo(follower,posX,posY)
  1340.           pbFancyMoveTo(follower,newX,newY)
  1341.         end
  1342.       end
  1343.     else
  1344.       if !mapTile
  1345.         # Make current position into leader's position
  1346.         mapTile=[leader.map.map_id,leader.x,leader.y]
  1347.       end
  1348.       if follower.map.map_id==mapTile[0]
  1349.         # Follower is on same map as leader
  1350.         follower.moveto(leader.x,leader.y)
  1351.         #pbTurnTowardEvent(follower,leader)
  1352.       else
  1353.         # Follower will move to different map
  1354.         events=$PokemonGlobal.dependentEvents
  1355.         eventIndex=pbEnsureEvent(follower,mapTile[0])
  1356.         if eventIndex>=0
  1357.           newFollower=@realEvents[eventIndex]
  1358.           newEventData=events[eventIndex]
  1359.           newFollower.moveto(mapTile[1],mapTile[2])
  1360.           newEventData[3]=mapTile[1]
  1361.           newEventData[4]=mapTile[2]
  1362.           if mapTile[0]==leader.map.map_id
  1363.             #pbTurnTowardEvent(follower,leader)
  1364.           end
  1365.         end
  1366.       end
  1367.     end
  1368.   end
  1369.  
  1370.   #Fix follower not being in the same spot upon save
  1371.   def pbMapChangeMoveDependentEvents
  1372.     return
  1373.   end
  1374. end
  1375.  
  1376.  
  1377.  
  1378. class DependentEventSprites
  1379.  
  1380.   attr_accessor :sprites
  1381.  
  1382.   def refresh
  1383.     for sprite in @sprites
  1384.       sprite.dispose
  1385.     end
  1386.     @sprites.clear
  1387.     $PokemonTemp.dependentEvents.eachEvent {|event,data|
  1388.        if data[0]==@map.map_id # Check original map
  1389.          #@map.events[data[1]].erase
  1390.        end
  1391.        if data[2]==@map.map_id # Check current map
  1392.          spr = Sprite_Character.new(@viewport,event)
  1393.          @sprites.push(spr)
  1394.        end
  1395.     }
  1396.   end
  1397.  
  1398.   def update
  1399.     if $PokemonTemp.dependentEvents.lastUpdate!=@lastUpdate
  1400.       refresh
  1401.       @lastUpdate=$PokemonTemp.dependentEvents.lastUpdate
  1402.     end
  1403.     for sprite in @sprites
  1404.       sprite.update
  1405.     end
  1406.     for i in 0...@sprites.length
  1407.       pbDayNightTint(@sprites[i])
  1408.       if $game_switches[Toggle_Following_Switch] && APPLYSTATUSTONES && $Trainer.party[0] && $Trainer.party[0].hp>0
  1409.         case $Trainer.party[0].status
  1410.         when PBStatuses::BURN
  1411.           @sprites[i].tone.set(@sprites[i].tone.red+BURNTONE[0],@sprites[i].tone.green+BURNTONE[1],@sprites[i].tone.blue+BURNTONE[2],@sprites[i].tone.gray+BURNTONE[3])
  1412.         when PBStatuses::POISON
  1413.           @sprites[i].tone.set(@sprites[i].tone.red+POISONTONE[0],@sprites[i].tone.green+POISONTONE[1],@sprites[i].tone.blue+POISONTONE[2],@sprites[i].tone.gray+POISONTONE[3])
  1414.         when PBStatuses::PARALYSIS
  1415.           @sprites[i].tone.set(@sprites[i].tone.red+PARALYSISTONE[0],@sprites[i].tone.green+PARALYSISTONE[1],@sprites[i].tone.blue+PARALYSISTONE[2],@sprites[i].tone.gray+PARALYSISTONE[3])
  1416.         when PBStatuses::FROZEN
  1417.           @sprites[i].tone.set(@sprites[i].tone.red+FREEZETONE[0],@sprites[i].tone.green+FREEZETONE[1],@sprites[i].tone.blue+FREEZETONE[2],@sprites[i].tone.gray+FREEZETONE[3])
  1418.         when PBStatuses::SLEEP
  1419.           @sprites[i].tone.set(@sprites[i].tone.red+SLEEPTONE[0],@sprites[i].tone.green+SLEEPTONE[1],@sprites[i].tone.blue+SLEEPTONE[2],@sprites[i].tone.gray+SLEEPTONE[3])
  1420.         end
  1421.       end
  1422.     end
  1423.   end
  1424.  
  1425. end
  1426.  
  1427.  
  1428. #Refresh following pokemon after switching pokemon around
  1429. class PokemonPartyScreen
  1430.  
  1431.   alias follow_pbSwitch pbSwitch
  1432.   def pbSwitch(oldid,newid)
  1433.     follow_pbSwitch(oldid,newid)
  1434.     $PokemonTemp.dependentEvents.refresh_sprite(false)
  1435.   end
  1436.  
  1437.   alias follow_pbRefreshSingle pbRefreshSingle
  1438.   def pbRefreshSingle(pkmnid)
  1439.     follow_pbRefreshSingle(pkmnid)
  1440.     $PokemonTemp.dependentEvents.refresh_sprite(false)
  1441.   end
  1442.  
  1443. end
  1444.  
  1445. #Refresh after evolution
  1446. class PokemonEvolutionScene
  1447.  
  1448.   alias follow_pbEndScreen pbEndScreen
  1449.   def pbEndScreen
  1450.     follow_pbEndScreen
  1451.     if @pokemon==$Trainer.party[0]
  1452.       $PokemonTemp.dependentEvents.refresh_sprite(false)
  1453.     end
  1454.   end
  1455.  
  1456. end
  1457.  
  1458. #Update follower's following time
  1459. class Game_Player < Game_Character
  1460.  
  1461.   alias follow_update update
  1462.   def update
  1463.     follow_update
  1464.     $PokemonTemp.dependentEvents.add_following_time
  1465.   end
  1466.  
  1467.   alias follow_moveto moveto
  1468.   def moveto(x,y)
  1469.     ret = follow_moveto(x,y)
  1470.     events=$PokemonGlobal.dependentEvents
  1471.     leader=$game_player
  1472.     for i in 0...events.length
  1473.       event=$PokemonTemp.dependentEvents.realEvents[i]
  1474.       $PokemonTemp.dependentEvents.pbFollowEventAcrossMaps(leader,event,true,i==0)
  1475.     end
  1476.     return ret
  1477.   end
  1478.  
  1479. end
  1480.  
  1481. #Update follower after battle
  1482. class PokeBattle_Scene
  1483.  
  1484.   alias follow_pbEndBattle pbEndBattle
  1485.   def pbEndBattle(result)
  1486.     follow_pbEndBattle(result)
  1487.     $PokemonTemp.dependentEvents.check_faint
  1488.   end
  1489.  
  1490. end
  1491.  
  1492. #Script for when a pokemon finds an item in the field
  1493. class PokemonField
  1494.  
  1495.   def Kernel.pbPokemonFound(item,quantity=1,plural=nil)
  1496.     itemname=PBItems.getName(item)
  1497.     pocket=pbGetPocket(item)
  1498.     e=$Trainer.party[0].name
  1499.     if $PokemonBag.pbStoreItem(item,quantity)
  1500.       pbWait(5)
  1501.       if $ItemData[item][ITEMUSE]==3 || $ItemData[item][ITEMUSE]==4
  1502.         Kernel.pbMessage(_INTL("\\se[]{1} found {2}!\\se[itemlevel]\\nIt contained {3}.\\wtnp[30]",e,itemname,PBMoves.getName($ItemData[item][ITEMMACHINE])))
  1503.         Kernel.pbMessage(_INTL("{1} put the {2}\r\nin the {3} Pocket.",$Trainer.name,itemname,PokemonBag.pocketNames()[pocket]))
  1504.       elsif PBItems.const_defined?(:LEFTOVERS) && isConst?(item,PBItems,:LEFTOVERS)
  1505.         Kernel.pbMessage(_INTL("\\se[]{1} found some {2}!\\se[itemlevel]\\wtnp[30]",e,itemname))
  1506.         Kernel.pbMessage(_INTL("{1} put the {2}\r\nin the {3} Pocket.",$Trainer.name,itemname,PokemonBag.pocketNames()[pocket]))
  1507.       else
  1508.         if quantity>1
  1509.           if plural
  1510.             Kernel.pbMessage(_INTL("\\se[]{1} found {2} {3}!\\se[itemlevel]\\wtnp[30]",e,quantity,plural))
  1511.             Kernel.pbMessage(_INTL("{1} put the {2}\r\nin the {3} Pocket.",$Trainer.name,plural,PokemonBag.pocketNames()[pocket]))
  1512.           else
  1513.             Kernel.pbMessage(_INTL("\\se[]{1} found {2} {3}s!\\se[itemlevel]\\wtnp[30]",e,quantity,itemname))
  1514.             Kernel.pbMessage(_INTL("{1} put the {2}s\r\nin the {3} Pocket.",$Trainer.name,itemname,PokemonBag.pocketNames()[pocket]))
  1515.           end
  1516.         else
  1517.           Kernel.pbMessage(_INTL("\\se[]{1} found one {2}!\\se[itemlevel]\\wtnp[30]",e,itemname))
  1518.           Kernel.pbMessage(_INTL("{1} put the {2}\r\nin the {3} Pocket.",$Trainer.name,itemname,PokemonBag.pocketNames()[pocket]))
  1519.         end
  1520.       end
  1521.       return true
  1522.     else   # Can't add the item
  1523.       if $ItemData[item][ITEMUSE]==3 || $ItemData[item][ITEMUSE]==4
  1524.         Kernel.pbMessage(_INTL("{1} found {2}!\\wtnp[20]",e,itemname))
  1525.       elsif PBItems.const_defined?(:LEFTOVERS) && isConst?(item,PBItems,:LEFTOVERS)
  1526.         Kernel.pbMessage(_INTL("{1} found some {2}!\\wtnp[20]",$Trainer.name,itemname))
  1527.       else
  1528.         if quantity>1
  1529.           if plural
  1530.             Kernel.pbMessage(_INTL("{1} found {2} {3}!\\wtnp[20]",e,quantity,plural))
  1531.           else
  1532.             Kernel.pbMessage(_INTL("{1} found {2} {3}s!\\wtnp[20]",$Trainer.name,quantity,itemname))
  1533.           end
  1534.         else
  1535.           Kernel.pbMessage(_INTL("{1} found one {2}!\\wtnp[20]",e,itemname))
  1536.         end
  1537.       end
  1538.       Kernel.pbMessage(_INTL("Too bad... The Bag is full..."))
  1539.       return false
  1540.     end
  1541.   end
  1542. end
  1543.  
  1544. $IssueStop = false
  1545.  
  1546. #Toggle follower, cycle through pokemon in field
  1547. class Scene_Map
  1548.  
  1549.   alias follow_update update
  1550.   def update
  1551.     follow_update
  1552.     return if $FollowerMoveRoute
  1553.     for i in 0...$PokemonGlobal.dependentEvents.length
  1554.       event=$PokemonTemp.dependentEvents.realEvents[i]
  1555.       return if event.move_route_forcing
  1556.     end    
  1557.     if $game_switches[Following_Activated_Switch] && $Trainer.party.length>0
  1558.       if Input.trigger?(Input::C) # try to talk to pokemon
  1559.         $PokemonTemp.dependentEvents.talk_to_pokemon
  1560.       end
  1561.       # Pokemon always move if switch is on, have flying type, or are in a settings array
  1562.       moving = Input.press?(Input::DOWN) || Input.press?(Input::UP) ||
  1563.                 Input.press?(Input::RIGHT) || Input.press?(Input::LEFT)
  1564.       if (ALWAYS_ANIMATE || $game_player.moving? || moving ||
  1565.         $Trainer.party[0].hasType?(:FLYING) ||
  1566.         isConst?($Trainer.party[0].ability,PBAbilities,:LEVITATE) ||
  1567.         ALWAYS_ANIMATED_FOLLOWERS.include?($Trainer.party[0].species)) &&
  1568.         !$PokemonGlobal.surfing
  1569.           if !(ALWAYS_ANIMATED_EXCEPTION.include?($Trainer.party[0].species))
  1570.             $PokemonTemp.dependentEvents.update_stepping
  1571.           end
  1572.       elsif $PokemonGlobal.surfing && $Trainer.party[0].hasType?(:WATER)
  1573.         if !(ALWAYS_ANIMATED_EXCEPTION.include?($Trainer.party[0].species))
  1574.           $PokemonTemp.dependentEvents.update_stepping
  1575.         end
  1576.       elsif $PokemonGlobal.surfing &&
  1577.                 ALWAYS_ANIMATED_CAN_SURF && ($Trainer.party[0].hasType?(:FLYING) ||
  1578.                 isConst?($Trainer.party[0].ability,PBAbilities,:LEVITATE) ||
  1579.                 ALWAYS_ANIMATED_FOLLOWERS.include?($Trainer.party[0].species)) &&
  1580.                 !(ALWAYS_ANIMATED_EXCEPTION.include?($Trainer.party[0].species)) &&
  1581.                 $Trainer.party[0].hp>0 && !$Trainer.party[0].isEgg?
  1582.           $PokemonTemp.dependentEvents.update_stepping
  1583.       elsif $PokemonGlobal.diving && $Trainer.party[0].hp>0 && !$Trainer.party[0].isEgg? && $Trainer.party[0].hasType?(:WATER)  && WATERPOKEMONCANDIVE
  1584.             $PokemonTemp.dependentEvents.update_stepping
  1585.       else
  1586.             $PokemonTemp.dependentEvents.stop_stepping
  1587.       end
  1588.       if Input.trigger?(Input::CTRL) && ALLOWTOGGLEFOLLOW && !$PokemonGlobal.bicycle
  1589.         if $PokemonGlobal.surfing
  1590.           if $Trainer.party[0].hp>0 && !$Trainer.party[0].isEgg? && $Trainer.party[0].hasType?(:WATER)
  1591.             if WATERPOKEMONCANSURF
  1592.               pbToggleFollowingPokemon
  1593.             end
  1594.           elsif ALWAYS_ANIMATED_CAN_SURF && ($Trainer.party[0].hasType?(:FLYING) ||
  1595.             isConst?($Trainer.party[0].ability,PBAbilities,:LEVITATE) ||
  1596.             ALWAYS_ANIMATED_FOLLOWERS.include?($Trainer.party[0].species)) &&
  1597.             !(ALWAYS_ANIMATED_EXCEPTION.include?($Trainer.party[0].species))
  1598.            
  1599.             pbToggleFollowingPokemon
  1600.           end
  1601.         elsif $PokemonGlobal.diving
  1602.           if $Trainer.party[0].hp>0 && !$Trainer.party[0].isEgg? && $Trainer.party[0].hasType?(:WATER)
  1603.             if WATERPOKEMONCANDIVE
  1604.               pbToggleFollowingPokemon
  1605.             end
  1606.           end
  1607.         else
  1608.           pbToggleFollowingPokemon
  1609.         end
  1610.       end
  1611.       if ALLOWFIELDSWITCHING && !$PokemonGlobal.bicycle
  1612.         tlength=$Trainer.party.length-1
  1613.         tparty=$Trainer.party
  1614.         return if tlength<=0
  1615.         if Input.trigger?(Input::X) && $Trainer.party.size > 1
  1616.           tparty.push(tparty.delete_at(0))
  1617.           if $game_switches[Toggle_Following_Switch]
  1618.             if $PokemonGlobal.surfing
  1619.               if tparty[0].hp>0 && !tparty[0].isEgg? && tparty[0].hasType?(:WATER)
  1620.                 $PokemonTemp.dependentEvents.refresh_sprite
  1621.               elsif ALWAYS_ANIMATED_CAN_SURF && ($Trainer.party[0].hasType?(:FLYING) ||
  1622.                 isConst?($Trainer.party[0].ability,PBAbilities,:LEVITATE) ||
  1623.                 ALWAYS_ANIMATED_FOLLOWERS.include?($Trainer.party[0].species)) &&
  1624.                 !(ALWAYS_ANIMATED_EXCEPTION.include?($Trainer.party[0].species)) &&
  1625.                 tparty[0].hp>0 && !tparty[0].isEgg?
  1626.                
  1627.                 $PokemonTemp.dependentEvents.refresh_sprite
  1628.               else
  1629.                 $PokemonTemp.dependentEvents.refresh_sprite(false)
  1630.               end
  1631.               if tparty[tlength].hp>0 && !tparty[tlength].isEgg? && tparty[tlength].hasType?(:WATER)
  1632.                 $PokemonTemp.dependentEvents.check_surf(true)
  1633.               elsif ALWAYS_ANIMATED_CAN_SURF && ($Trainer.party[tlength].hasType?(:FLYING) ||
  1634.                 isConst?($Trainer.party[tlength].ability,PBAbilities,:LEVITATE) ||
  1635.                 ALWAYS_ANIMATED_FOLLOWERS.include?($Trainer.party[tlength].species)) &&
  1636.                 !(ALWAYS_ANIMATED_EXCEPTION.include?($Trainer.party[tlength].species)) &&
  1637.                 tparty[tlength].hp>0 && !tparty[tlength].isEgg?
  1638.                
  1639.                 $PokemonTemp.dependentEvents.check_surf(true)
  1640.               else
  1641.                 $PokemonTemp.dependentEvents.check_surf(false)
  1642.               end
  1643.             elsif $PokemonGlobal.diving
  1644.               if tparty[0].hp>0 && !tparty[0].isEgg? && tparty[0].hasType?(:WATER) && WATERPOKEMONCANDIVE
  1645.                 $PokemonTemp.dependentEvents.refresh_sprite
  1646.               end
  1647.               if tparty[tlength].hp>0 && !tparty[tlength].isEgg? && tparty[tlength].hasType?(:WATER) && WATERPOKEMONCANDIVE
  1648.                 $PokemonTemp.dependentEvents.check_surf(true)
  1649.               end
  1650.             else
  1651.               $PokemonTemp.dependentEvents.refresh_sprite
  1652.             end
  1653.           end
  1654.         end
  1655.         if Input.trigger?(Input::Z) && $Trainer.party.size > 1
  1656.           $Trainer.party.insert(0,$Trainer.party.pop)
  1657.           if $game_switches[Toggle_Following_Switch]
  1658.             if $PokemonGlobal.surfing
  1659.               if tparty[0].hp>0 && !tparty[0].isEgg? && tparty[0].hasType?(:WATER)
  1660.                 $PokemonTemp.dependentEvents.refresh_sprite
  1661.               elsif ALWAYS_ANIMATED_CAN_SURF && ($Trainer.party[0].hasType?(:FLYING) ||
  1662.                 isConst?($Trainer.party[0].ability,PBAbilities,:LEVITATE) ||
  1663.                 ALWAYS_ANIMATED_FOLLOWERS.include?($Trainer.party[0].species)) &&
  1664.                 !(ALWAYS_ANIMATED_EXCEPTION.include?($Trainer.party[0].species)) &&
  1665.                 tparty[0].hp>0 && !tparty[0].isEgg?
  1666.                
  1667.                 $PokemonTemp.dependentEvents.refresh_sprite
  1668.                
  1669.               else
  1670.                 $PokemonTemp.dependentEvents.refresh_sprite(false)
  1671.               end
  1672.               if tparty[1].hp>0 && !tparty[1].isEgg? && tparty[1].hasType?(:WATER)
  1673.                 $PokemonTemp.dependentEvents.check_surf(true)
  1674.               elsif ALWAYS_ANIMATED_CAN_SURF && ($Trainer.party[1].hasType?(:FLYING) ||
  1675.                 isConst?($Trainer.party[1].ability,PBAbilities,:LEVITATE) ||
  1676.                 ALWAYS_ANIMATED_FOLLOWERS.include?($Trainer.party[1].species)) &&
  1677.                 !(ALWAYS_ANIMATED_EXCEPTION.include?($Trainer.party[1].species)) &&
  1678.                 tparty[1].hp>0 && !tparty[1].isEgg?
  1679.                
  1680.                 $PokemonTemp.dependentEvents.check_surf(true)
  1681.               else
  1682.                 $PokemonTemp.dependentEvents.check_surf(false)
  1683.               end
  1684.             elsif $PokemonGlobal.diving
  1685.                if tparty[0].hp>0 && !tparty[0].isEgg? && tparty[0].hasType?(:WATER)  && WATERPOKEMONCANDIVE
  1686.                 $PokemonTemp.dependentEvents.refresh_sprite
  1687.               end
  1688.               if tparty[1].hp>0 && !tparty[1].isEgg? && tparty[1].hasType?(:WATER) && WATERPOKEMONCANDIVE
  1689.                 $PokemonTemp.dependentEvents.check_surf(true)
  1690.               end
  1691.             else
  1692.               $PokemonTemp.dependentEvents.refresh_sprite
  1693.             end
  1694.           end
  1695.         end
  1696.       end
  1697.     end
  1698.   end
  1699.  
  1700.   alias follow_transfer transfer_player
  1701.   def transfer_player(cancelVehicles=true)
  1702.     follow_transfer(cancelVehicles)
  1703.     events=$PokemonGlobal.dependentEvents
  1704.     $PokemonTemp.dependentEvents.updateDependentEvents
  1705.     leader=$game_player
  1706.     for i in 0...events.length
  1707.       event=$PokemonTemp.dependentEvents.realEvents[i]
  1708.       $PokemonTemp.dependentEvents.pbFollowEventAcrossMaps(leader,event,false,i==0)
  1709.     end
  1710.     $PokemonTemp.dependentEvents.refresh_sprite
  1711.   end
  1712.  
  1713. end
  1714.  
  1715. #Fix follower landing on player when transfering
  1716. $NeedFollowerUpdate = false
  1717. #Don't try to unlock the follower events
  1718. class Interpreter
  1719.  
  1720.   def command_end
  1721.     # Clear list of event commands
  1722.     @list = nil
  1723.     # If main map event and event ID are valid
  1724.     if @main && @event_id > 0 && !($game_map.events[@event_id] && $game_map.events[@event_id].name=="Dependent")
  1725.       # Unlock event
  1726.       $game_map.events[@event_id].unlock if $game_map.events[@event_id]
  1727.     end
  1728.     if $NeedFollowerUpdate
  1729.       events=$PokemonGlobal.dependentEvents
  1730.       $PokemonTemp.dependentEvents.updateDependentEvents
  1731.       leader=$game_player
  1732.       for i in 0...events.length
  1733.         event=$PokemonTemp.dependentEvents.realEvents[i]
  1734.         $PokemonTemp.dependentEvents.pbFollowEventAcrossMaps(leader,event,false,i==0)
  1735.       end
  1736.       $NeedFollowerUpdate=false
  1737.     end
  1738.   end
  1739.  
  1740.   alias follow_201 command_201
  1741.   def command_201
  1742.     ret=follow_201
  1743.     $NeedFollowerUpdate=true
  1744.     return ret
  1745.   end
  1746.  
  1747. end
  1748.  
  1749.  
  1750. # Fix other events walking through dependent events
  1751. class Game_Map
  1752.  
  1753.   alias follow_passable? passable?
  1754.   def passable?(x, y, d, self_event=nil)
  1755.     ret=follow_passable?(x,y,d,self_event)
  1756.     if !ret && !$game_temp.player_transferring && $game_player.pbHasDependentEvents? && $game_switches[Toggle_Following_Switch] &&
  1757.        self_event != $game_player
  1758.          dependent=pbGetDependency("Dependent")
  1759.          if dependent != nil && self_event != dependent
  1760.            if dependent.x==x && dependent.y==y
  1761.              return false
  1762.            end
  1763.          end
  1764.     end
  1765.     return ret
  1766.    end
  1767.    
  1768. end
  1769.  
  1770.  
  1771. #Fix blacking out
  1772. #overwrite starting over to fix black out error
  1773. def Kernel.pbStartOver(gameover=false)
  1774.   if pbInBugContest?
  1775.     Kernel.pbBugContestStartOver
  1776.     return
  1777.   end
  1778.   pbHealAll()
  1779.   if $PokemonGlobal.pokecenterMapId && $PokemonGlobal.pokecenterMapId>=0
  1780.     if gameover
  1781.       Kernel.pbMessage(_INTL("\\w[]\\wm\\c[8]\\l[3]After the unfortunate defeat, {1} scurried to a Pokémon Center.",$Trainer.name))
  1782.     else
  1783.       Kernel.pbMessage(_INTL("\\w[]\\wm\\c[8]\\l[3]{1} scurried to a Pokémon Center, protecting the exhausted and fainted Pokémon from further harm.",$Trainer.name))
  1784.     end
  1785.     Kernel.pbCancelVehicles
  1786.     pbRemoveDependencies()
  1787.     $game_switches[STARTING_OVER_SWITCH]=true
  1788.     $game_temp.player_new_map_id=$PokemonGlobal.pokecenterMapId
  1789.     $game_temp.player_new_x=$PokemonGlobal.pokecenterX
  1790.     $game_temp.player_new_y=$PokemonGlobal.pokecenterY
  1791.     $game_temp.player_new_direction=$PokemonGlobal.pokecenterDirection
  1792.     $scene.transfer_player if $scene.is_a?(Scene_Map)
  1793.     $game_map.refresh
  1794.   else
  1795.     homedata=pbGetMetadata(0,MetadataHome)
  1796.     if (homedata && !pbRxdataExists?(sprintf("Data/Map%03d",homedata[0])) )
  1797.       if $DEBUG
  1798.         Kernel.pbMessage(_ISPRINTF("Can't find the map 'Map{1:03d}' in the Data folder. The game will resume at the player's position.",homedata[0]))
  1799.       end
  1800.       pbHealAll()
  1801.       return
  1802.     end
  1803.     if gameover
  1804.       Kernel.pbMessage(_INTL("\\w[]\\wm\\c[8]\\l[3]After the unfortunate defeat, {1} scurried home.",$Trainer.name))
  1805.     else
  1806.       Kernel.pbMessage(_INTL("\\w[]\\wm\\c[8]\\l[3]{1} scurried home, protecting the exhausted and fainted Pokémon from further harm.",$Trainer.name))
  1807.     end
  1808.     if homedata
  1809.       Kernel.pbCancelVehicles
  1810.       pbRemoveDependencies() if !$game_switches[Following_Activated_Switch]
  1811.       $game_switches[STARTING_OVER_SWITCH]=true
  1812.       $game_temp.player_new_map_id=homedata[0]
  1813.       $game_temp.player_new_x=homedata[1]
  1814.       $game_temp.player_new_y=homedata[2]
  1815.       $game_temp.player_new_direction=homedata[3]
  1816.       $scene.transfer_player if $scene.is_a?(Scene_Map)
  1817.       $game_map.refresh
  1818.     else
  1819.       pbHealAll()
  1820.     end
  1821.   end
  1822.   pbEraseEscapePoint
  1823. end
  1824.  
  1825. #Fix Escape Rope
  1826. ItemHandlers::UseInField.add(:ESCAPEROPE,proc{|item|
  1827.    escape=($PokemonGlobal.escapePoint rescue nil)
  1828.    if !escape || escape==[]
  1829.      Kernel.pbMessage(_INTL("Can't use that here."))
  1830.      next
  1831.    end
  1832.    if $game_player.pbHasDependentEvents? && !$game_switches[Following_Activated_Switch]
  1833.      Kernel.pbMessage(_INTL("It can't be used when you have someone with you."))
  1834.      next
  1835.    end
  1836.    Kernel.pbMessage(_INTL("{1} used the {2}.",$Trainer.name,PBItems.getName(item)))
  1837.    pbFadeOutIn(99999){
  1838.       Kernel.pbCancelVehicles
  1839.       $game_temp.player_new_map_id=escape[0]
  1840.       $game_temp.player_new_x=escape[1]
  1841.       $game_temp.player_new_y=escape[2]
  1842.       $game_temp.player_new_direction=escape[3]
  1843.       $scene.transfer_player
  1844.       $game_map.autoplay
  1845.       $game_map.refresh
  1846.    }
  1847.    pbEraseEscapePoint
  1848. })
  1849.  
  1850.  
  1851. ItemHandlers::UseFromBag.add(:ESCAPEROPE,proc{|item|
  1852.    if $game_player.pbHasDependentEvents? && !$game_switches[Following_Activated_Switch]
  1853.      Kernel.pbMessage(_INTL("It can't be used when you have someone with you."))
  1854.      next 0
  1855.    end
  1856.    if ($PokemonGlobal.escapePoint rescue false) && $PokemonGlobal.escapePoint.length>0
  1857.      next 4 # End screen and consume item
  1858.    else
  1859.      Kernel.pbMessage(_INTL("Can't use that here."))
  1860.      next 0
  1861.    end
  1862. })
  1863.  
  1864.  
  1865. #Update sprites on give item
  1866. class PokemonPartyScreen
  1867.  
  1868.   alias follow_pbPokemonGiveScreen pbPokemonGiveScreen
  1869.   def pbPokemonGiveScreen(item)
  1870.     ret=follow_pbPokemonGiveScreen(item)
  1871.     $PokemonTemp.dependentEvents.refresh_sprite(false) if ret
  1872.     return ret
  1873.   end
  1874.  
  1875. end
  1876.  
  1877. #Update sprites on use item
  1878. module ItemHandlers
  1879.  
  1880.   class << self
  1881.     alias follow_triggerUseOnPokemon triggerUseOnPokemon
  1882.   end
  1883.  
  1884.   def self.triggerUseOnPokemon(item,pokemon,scene)
  1885.     ret = follow_triggerUseOnPokemon(item,pokemon,scene)
  1886.     $PokemonTemp.dependentEvents.refresh_sprite(false) if ret
  1887.     return ret
  1888.   end
  1889.  
  1890. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top