TechSkylander1518

Overworld Encounters v19 (original script by derFischae)

Jun 8th, 2021 (edited)
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 47.24 KB | None | 0 0
  1. #===============================================================================
  2. # * Visible Overworld Encounters V2.0.2 for PEv18 - by derFischae (Credits if used please) *
  3. #===============================================================================
  4. #
  5. # UPDATED TO VERSION 2.0.2.
  6. #
  7. # As in Pokemon Let's go Pikachu/Eevee or Pokemon Shield and Sword
  8. # random encounters pop up on the overworld,
  9. # they move around and you can start the battle
  10. # with them simply by moving to the pokemon.
  11. # Clearly, you also can omit the battle by circling around them.
  12. #
  13. # This script is for Pokémon Essentials v18 (for short PEv18).
  14. #
  15. # FEATURES INCLUDED:
  16. #   - see the pokemon on the overworld before going into battle
  17. #   - no forced battling against random encounters
  18. #   - plays the pokemon cry while spawning
  19. #   - Choose whether encounters occure on all terrains or only on
  20. #     the terrain of the player
  21. #   - you can have instant wild battle and overworld spawning at the same time and set the propability of that by default
  22. #     and change it ingame and store it with a $game_variable
  23. #   - In caves, pokemon don't spawn on impassable Rock-Tiles, which have the Tile-ID 4
  24. #   - You can check during the events @@OnWildPokemonCreate, @@OnStartBattle, ... if you are battling a spawned pokemon with the global variable $PokemonGlobal.battlingSpawnedPokemon
  25. #   - You can check during the event @@OnWildPokemonCreate if the pokemon is created for spawning on the map or created for a different reason with the Global variable $PokemonGlobal.creatingSpawningPokemon
  26. #   - If you want to add a procedure that modifies a pokemon only for spawning but not before battling
  27. #     then you can use the Event @@OnWildPokemonCreateForSpawning.
  28. #
  29. # There are various add-ons and modifications of this script for Pokemon Essentials v17.2.
  30. # But I don't know jet, which one still work with Pokemon Essentials v18.
  31. # And probably there are some bugs due to the update to PEv18.
  32. # So feel free to post your bugs.
  33.  
  34. # ADD-ONS OF THIS SCRIPT:
  35. # In the post https://www.pokecommunity.com/showthread.php?t=429019 you will also find add-ons, including
  36. #  - Vendilys Rescue Chain and JoelMatthews Add-Ons for Vendilys Rescue Chain,
  37. #    See https://www.pokecommunity.com/showthread.php?t=415524 and
  38. #    https://www.pokecommunity.com/showthread.php?t=422513 for original scripts
  39. #  - Let's go chiny hunting by chaining a pokemon, inspired by Diego Mertens script
  40. #    https://www.pokecommunity.com/showthread.php?p=10011513
  41. #  - Automatic Spawning
  42. #  - randomized spawning
  43. #  - always shiny spawning
  44. #  - instructions on how to make your own Add-On or to modify an already existing script
  45. #    to make it work with the visible overworld wild encounter script.
  46. #    This includes modifying a pokemon on spawning but not on battling again,
  47. #    by using the events OnStartBattle, OnWildPokemonCreate and OnWildPokemonCreateForSpawning
  48. #  - Joltiks Level Balance, see https://www.pokecommunity.com/showthread.php?t=409828 for original post
  49. #
  50. # MODIFICATIONS OF THIS SCRIPT FOR PEv17.2:
  51. # Read the whole thread https://www.pokecommunity.com/showthread.php?t=429019 for more features and modifications, including
  52. #  - adding shiny sparkle animation to spawned overworld shinys, especially useful if you want to sign out the shiny encounters on the map without using overworld shiny sprites
  53. #  - removing grass rustle animation on water and in caves
  54. #  - forbidding pokemon to spawn on specific terrain tiles in caves
  55. #  - adding new encounter types, eg. desert, shallow water
  56. #  - instructions on how to have different encounters for overworld spawning and original encountering on the same map
  57. #  - error solutions
  58. # Feel free to test it with PEv18.
  59. #
  60. # NEW FEATURES FROM VERSION 2.0.2 FOR PEv18:
  61. #   - added new global variable $PokemonGlobal.creatingSpawningPokemon to check during the event @@OnWildPokemonCreate if the pokemon is created for spawning on the map or created for a different reason
  62. #
  63. # UPSCALED FEATURES FROM VERSION 2.0.1 FOR PEv17.2:
  64. #   - less lag
  65. #   - supports sprites for alternative forms of pokemon
  66. #   - supports sprites for female/male/genderless pokemon
  67. #   - bug fixes for roaming encounter and double battles
  68. #   - more options in settings
  69. #   - roaming encounters working correctly
  70. #   - more lag reduction
  71. #   - included automatic spawning of pokemon, i.e. spawning without having to move the player
  72. #   - included vendilys rescue chain, i. e. if pokemon of the same species family spawn in a row and will be battled in a row, then you increase the chance of spawning
  73. #     an evolved pokemon of that species family. Link: https://www.pokecommunity.com/showthread.php?t=415524
  74. #   - removed bug occuring after fainting against wild overworld encounter
  75. #   - for script-developers, shortened the spawnEvent method for better readablitiy
  76. #   - removed bugs from version 1.9
  77. #   - added shapes of overworld encounter for rescue chain users
  78. #   - supports spawning of alternate forms while chaining
  79. #   - if overworld sprites for alternative, female or shiny forms are missing,
  80. #     then the standard sprite will be displayed instead of an invisible event
  81. #   - bug fix for shiny encounters
  82. #   - respecting shiny state for normal encounters when using overworld and normal encounters at the same time
  83. #   - easier chaining concerning Vendilys Rescue chain, i.e. no more resetting of the chain when spawning of a pokemon of different family but when fighting with a pokemon of different family
  84. #   - Added new Event @@OnPokemonCreateForSpawning which only triggers on spawning
  85. #   - Added new global variable $PokemonGlobal.battlingSpawnedShiny to check if an active battle is against a spawned pokemon.
  86. #   - removed bug to make the new features in version 1.11 work
  87. #   - reorganised and thin out the code to organise code as add-ons
  88. #   - removed Vendilys Rescue Chain, Let's Go Shiny Hunting and automatic spawning as hard coded feature and provide it as Add-Ons instead
  89. #   - Now, using overworld and normal encounters at the same time is a standard feature
  90. #   - autospawning will not trigger instant battles anymore
  91. #   - removed a bug that came from reorganising the code in original code and add-ons concerning Let's go shiny hunting add-on
  92. #
  93. # INSTALLATION:
  94. # Installation as simple as it can be.
  95. # Step 1) You need sprites for the overworld pokemon in your \Graphics\Characters
  96. # folder named by there number 001.png, 002.png, ...,
  97. # For instance you can use Gen 1-7 OV SPrites or whatever you want for your fakemon
  98. # If you want to use shiny overworld sprites for shiny encounters, then make sure
  99. # to also have the corresponding shiny versions in your \Graphics\Characters
  100. # folder named by 001s.png, 002s.png, ....
  101. # If you want to use alternative forms as overworld sprites, then make sure that
  102. # you also have a sprite for each alternative form, e. g. for Unown 201_1.png,
  103. # 201s_1.png, 201_2.png, 201s_2.png, ...
  104. # Please note that Scatterbug has 18 alternative forms in Pokemon Essentials.
  105. # But you will only see one form depending on your trainerID.
  106. # So, you also have to include 664_1.png, ..., 664_19.png and 664s_1.png, ..., 664s_19.png.
  107. # Same needs to be done for Pokemon Spewpa with number 665 and Vivillon with number 666.
  108. # If you want to use female forms as overworld sprites, then make sure that you
  109. # also have a female sprite for each pokemon named 001f.png, 001fs.png, 002f.png,
  110. # 002fs.png, ... (excluding genderless pokemon of course)
  111. # Step 2) Insert a new file in the script editor above main,
  112. # name it Overworld_Random_Encounters and copy this code into it.
  113. # Step 3) If you want then you can also install the script always in bush and in water
  114. # to obtain that the overworld encounter don't stand on water anymore but sink in.
  115. # You can find it at https://www.pokecommunity.com/showthread.php?p=10109060
  116. #
  117. # PROPERTIES:
  118. # 1) If you want to have water encounters only while surfing,
  119. # you also have to change the value of the
  120. # upcoming parameter RESTRICTENCOUNTERSTOPLAYERMOVEMENT to
  121. #     RESTRICTENCOUNTERSTOPLAYERMOVEMENT = true
  122. # 2) You can choose how many steps the encounter moves before vanishing
  123. # in parameter
  124. #     STEPSBEFOREVANISHING
  125. # 3) You can choose whether the overworld sprite of an shiny encounter
  126. # is always the standard sprite or is the corresponding shiny overworld sprite  in parameter
  127. #     USESHINYSPRITES
  128. # 4) You can choose whether the sprite of your overworld encounter
  129. # is always the standard sprite or can be an alternative form in parameter
  130. #     USEALTFORMS
  131. # 5) You can choose whether the sprites depend on the gender of the encounter
  132. # or are always neutral in parameter
  133. #     USEFEMALESPRITES
  134. # 6) You can choose whether the overworld encounters have a stop/ step-animation
  135. # similar to following pokemon in the parameter
  136. #     USESTOPANIMATION
  137. # 7) You can choose how many overworld encounters are aggressive and run to the
  138. # player in the parameter
  139. #     AGGRESSIVEENCOUNTERPROBABILITY
  140. # 8) You can choose the move-speed and move-frequency of  normal and aggressive
  141. # encounters in parameters
  142. #     ENCMOVESPEED, ENCMOVEFREQ, AGGRENCMOVESPEED, AGGRENCMOVEFREQ
  143. # 9) You can have normal and overworld encountering at the same time.
  144. # You can set the default propability in percentage in the parameter
  145. #     INSTANT_WILD_BATTLE_PROPABILITY
  146. # 10) The actual propability of normal to overworld encountering during game is stored in
  147. #     $game_variables[OVERWORLD_ENCOUNTER_VARIABLE]
  148. # and you can change its value during playtime.
  149. # 11) If you want to change the ID of the $game_variable that saves the current propability of normal to overworld encountering,
  150. # then you can change it in parameter
  151. #     OVERWORLD_ENCOUNTER_VARIABLE
  152. # Make sure that no other script uses and overrides the value of the game_variable with that ID.
  153. # 12) If you have impassable tiles in a cave, where you don't want pokemon to spawn there. Then choose the Tile-ID 4 for that tile in the tile-editor.
  154. #
  155. # THANKS to BulbasaurLvl5 for bringing me to pokemon essentials
  156.  
  157. #===============================================================================
  158. #                             Settings            
  159. #===============================================================================
  160.  
  161. OVERWORLD_ENCOUNTER_VARIABLE = 79 # default is an ID which is not used anywhere else
  162. # This parameter stores the ID of the $game_variable which holds the propability
  163. # of normal to overworld encountering.
  164. # Make sure that no other script uses the $game_variable with this ID,
  165. # except for the visible overworld wild encounter script itself and its add-ons.
  166. #
  167. # The $game_variable with the ID equal to OVERWORLD_ENCOUNTER_VARIABLE is used
  168. # to store the propability of an instant (normal) wild battle.
  169. # You can modify the value of that $game_variable during game or with events as usual. It is similar to use
  170. # game switches. See the Pokemon Essentials manual for more informations.
  171. # The propability is stored the following way
  172. # $game_variables[OVERWORLD_ENCOUNTER_VARIABLE] = 0
  173. #    - the propability of instant battle to spawning will be equal to the value
  174. # of INSTANT_WILD_BATTLE_PROPABILITY in percentage, see below
  175. # $game_variables[OVERWORLD_ENCOUNTER_VARIABLE] < 0
  176. #    - means only overworld encounters, no instant battles
  177. # $game_variables[OVERWORLD_ENCOUNTER_VARIABLE] > 0 and < 100
  178. #    - means overworld encounters and normal encounters at the same time,
  179. #      where the value equals the propability of normal encounters in percentage
  180. # $game_variables[OVERWORLD_ENCOUNTER_VARIABLE] >= 100
  181. #    - means only normal encounters and instant battles as usual, no overworld spawning
  182.  
  183. INSTANT_WILD_BATTLE_PROPABILITY = 0 # default 0.
  184. # It will be used when starting the game the first time. Changing this value later on will not affect the propability anymore.
  185. # However, you can still change the propability stored in the $game_variable with ID above during runtime.
  186. # This parameter holds the DEFAULT propability of normal to overworld encountering.
  187. # The propability is stored in percentage with possible values 0,1,2,...,100.
  188. # <= 0           - means only overworld encounters, no instant battles
  189. # > 0 and < 100  - means overworld encounters and normal encounters at the same time.
  190. # >= 100         - means only normal encounters and instant battles as usual, no overworld spawning
  191. # You can still change the propability stored in the $game_variable with ID above during runtime.
  192. # But if you don't change the propability ingame, then it will be this INSTANT_WILD_BATTLE_PROPABILITY
  193. # Note that, if $game_variables[OVERWORLD_ENCOUNTER_VARIABLE] = 0 then the propability stored in that $game_variable will be reset to
  194. # the value of INSTANT_WILD_BATTLE_PROPABILITY, unless this is also 0.
  195.  
  196. RESTRICTENCOUNTERSTOPLAYERMOVEMENT = false
  197. #true - means that water encounters are popping up
  198. #       if and only if player is surfing
  199. #       (perhaps decreases encounter rate)
  200. #false - means that all encounter types can pop up
  201. #        close to the player (as long as there is a suitable tile)
  202.  
  203. STEPSBEFOREVANISHING = 6 # default 10
  204. #      STEPSBEFOREVANISHING is the number of steps a wild Encounter goes
  205. #      before vanishing on the map.
  206.  
  207. USESHINYSPRITES = true # default true
  208. #false - means that you don't use shiny sprites for your overworld encounter
  209. #true - means that a shiny encounter will have a its special shiny overworld sprite
  210. #       make sure that you have the shiny sprites named with an "s" (e.g. 001s.png)
  211. #       for the shiny forms in your \Graphics\Characters folder      
  212.  
  213. USEALTFORMS = true # default true
  214. #false - means that you don't use alternative forms for your overworld sprite
  215. #true - means that the sprite of overworld encounter varies by the form of that pokemon
  216. #       make sure that you have the sprites with the right name
  217. #       for your alternative forms in your \Graphics\Characters folder      
  218.  
  219. USEFEMALESPRITES = true # default true
  220. #false - means that you use always a neutral overworld sprite
  221. #true - means that female pokemon have there own female overworld sprite
  222. #       make sure that you have the sprites with the right name 001f.png,
  223. #       001fs.png, ... for the female forms in your \Graphics\Characters folder
  224.  
  225. USESTOPANIMATION = true # default true
  226. #false - means that overworld encounters don't have a stop- animation
  227. #true - means that overworld encounters have a stop- animation similar as  
  228. #       following pokemon
  229.  
  230. ENCMOVESPEED = 3 # default 3
  231. # this is the movement speed (compare to autonomous movement of events) of an overworld encounter
  232. #1   - means lowest movement
  233. #6   - means highest movement
  234.  
  235. ENCMOVEFREQ = 3 # default 3
  236. # this is the movement frequenzy (compare to autonomous movement of events) of an overworld encounter
  237. #1   - means lowest movement
  238. #6   - means highest movement
  239.  
  240. AGGRESSIVEENCOUNTERPROBABILITY = 20 # default 20
  241. #this is the probability in percent of spawning of an agressive encounter
  242. #0   - means that there are no aggressive encounters
  243. #100 - means that all encounter are aggressive
  244.  
  245. AGGRENCMOVESPEED = 3 # default 3
  246. # this is the movement speed (compare to autonomous movement of events) of an aggressive encounter
  247. #1   - means lowest movement
  248. #6   - means highest movement
  249.  
  250. AGGRENCMOVEFREQ = 5 # default 5
  251. # this is the movement frequenzy (compare to autonomous movement of events) of an aggressive encounter
  252. #1   - means lowest movement
  253. #6   - means highest movement
  254.  
  255. SHINY_ANIMATION_ID = 5
  256. DUST_ANIMATION_ID = 2
  257. SPLASH_ANIMATION_ID = 6
  258.  
  259. #===============================================================================
  260. #                              THE SCRIPT
  261. #===============================================================================
  262.  
  263.           #########################################################
  264.           #                                                       #
  265.           #      1. PART: SPAWNING THE OVERWORLD ENCOUNTER        #
  266.           #                                                       #
  267.           #########################################################
  268. #===============================================================================
  269. # We override the original method "pbOnStepTaken" in Script PField_Field it was
  270. # originally used for random encounter battles
  271. #===============================================================================
  272. def pbOnStepTaken(eventTriggered)
  273.   #Should it be possible to search for pokemon nearby?
  274.   if $game_player.move_route_forcing || pbMapInterpreterRunning? # || !$Trainer
  275.     Events.onStepTakenFieldMovement.trigger(nil,$game_player)
  276.     return
  277.   end
  278.   $PokemonGlobal.stepcount = 0 if !$PokemonGlobal.stepcount
  279.   $PokemonGlobal.stepcount += 1
  280.   $PokemonGlobal.stepcount &= 0x7FFFFFFF
  281.   repel = ($PokemonGlobal.repel>0)
  282.   Events.onStepTaken.trigger(nil)
  283.   handled = [nil]
  284.   Events.onStepTakenTransferPossible.trigger(nil,handled)
  285.   return if handled[0]
  286.   if !eventTriggered && !$game_temp.in_menu
  287.     if $game_variables[OVERWORLD_ENCOUNTER_VARIABLE] == 0
  288.       if INSTANT_WILD_BATTLE_PROPABILITY > 0 && INSTANT_WILD_BATTLE_PROPABILITY < 100
  289.         $game_variables[OVERWORLD_ENCOUNTER_VARIABLE] = INSTANT_WILD_BATTLE_PROPABILITY
  290.       elsif INSTANT_WILD_BATTLE_PROPABILITY >= 100
  291.         $game_variables[OVERWORLD_ENCOUNTER_VARIABLE] = 100
  292.       else
  293.         $game_variables[OVERWORLD_ENCOUNTER_VARIABLE] = -1
  294.       end
  295.     end
  296.     if $game_variables[OVERWORLD_ENCOUNTER_VARIABLE]>0 && ($game_variables[OVERWORLD_ENCOUNTER_VARIABLE]>=100 || rand(100) < $game_variables[OVERWORLD_ENCOUNTER_VARIABLE])
  297.       #STANDARD WILDBATTLE
  298.       pbBattleOnStepTaken(repel)
  299.     else
  300.       #OVERWORLD ENCOUNTERS
  301.       #we choose the tile on which the pokemon appears
  302.       pos = pbChooseTileOnStepTaken
  303.       return if !pos
  304.       #we choose the random encounter
  305.       encounter,gender,form,isShiny = pbChooseEncounter(pos[0],pos[1],repel)
  306.       return if !encounter
  307.       #we generate an random encounter overworld event
  308.       pbPlaceEncounter(pos[0],pos[1],encounter,gender,form,isShiny)
  309.     end
  310.   end
  311. end
  312.  
  313. #===============================================================================
  314. # new method pbChooseTileOnStepTaken to choose the tile on which the pkmn spawns
  315. #===============================================================================
  316. def pbChooseTileOnStepTaken
  317.   # Choose 1 random tile from 1 random ring around the player
  318.   i = rand(4)
  319.   r = rand((i+1)*8)
  320.   x = $game_player.x
  321.   y = $game_player.y
  322.   if r<=(i+1)*2
  323.     x = $game_player.x-i-1+r
  324.     y = $game_player.y-i-1
  325.   elsif r<=(i+1)*6-2
  326.     x = [$game_player.x+i+1,$game_player.x-i-1][r%2]
  327.     y = $game_player.y-i+((r-1-(i+1)*2)/2).floor
  328.   else
  329.     x = $game_player.x-i+r-(i+1)*6
  330.     y = $game_player.y+i+1
  331.   end
  332.   #check if it is possible to encounter here
  333.   return if x<0 || x>=$game_map.width || y<0 || y>=$game_map.height #check if the tile is on the map
  334.   #check if it's a valid grass, water or cave etc. tile
  335.   #tile_id = $game_map.data[x, y, i]
  336.  # terrain = $game_map.terrain_tag(x,y)
  337.   return if GameData::TerrainTag.try_get($game_map.terrain_tag(x,y)).id == :Ice
  338.   return if GameData::TerrainTag.try_get($game_map.terrain_tag(x,y)).id == :Ledge
  339.   return if GameData::TerrainTag.try_get($game_map.terrain_tag(x,y)).id == :Waterfall
  340.   return if GameData::TerrainTag.try_get($game_map.terrain_tag(x,y)).id == :Rock
  341.   return if GameData::TerrainTag.try_get($game_map.terrain_tag(x,y)).id == :OWNoSpawn
  342.   return if GameData::TerrainTag.try_get($game_map.terrain_tag(x,y)).id == :SurfNoSpawn
  343.   if RESTRICTENCOUNTERSTOPLAYERMOVEMENT
  344.     return if !GameData::TerrainTag.try_get($game_map.terrain_tag(x,y)).id == :Water &&
  345.               $PokemonGlobal && $PokemonGlobal.surfing
  346.     return if GameData::TerrainTag.try_get($game_map.terrain_tag(x,y)).id == :Water &&
  347.               !($PokemonGlobal && $PokemonGlobal.surfing)
  348.   end
  349.   return [x,y]
  350. end
  351.  
  352. #===============================================================================
  353. # defining new method pbChooseEncounter to choose the pokemon on the tile (x,y)
  354. #===============================================================================
  355. def pbChooseEncounter(x,y,repel=false)
  356.   return if $Trainer.able_pokemon_count==0   #check if trainer has pokemon
  357.   encounterType = $PokemonEncounters.pbEncounterTypeOnTile(x,y)
  358.   return if encounterType==nil #check if there are encounters
  359.   return if !$PokemonEncounters.isEncounterPossibleHereOnTile?(x,y)
  360.   $PokemonTemp.encounterType = encounterType
  361.   for event in $game_map.events.values
  362.     if event.x==x && event.y==y
  363.       return
  364.     end
  365.   end
  366.   #tech changed this
  367.   encounter = $PokemonEncounters.choose_wild_pokemon(encounterType)
  368.   encounter = EncounterModifier.trigger(encounter)
  369.   if !$PokemonEncounters.allow_encounter?(encounter,repel)
  370.     $PokemonTemp.forceSingleBattle = false
  371.     EncounterModifier.triggerEncounterEnd()
  372.     return
  373.   end
  374.   form = nil
  375.   gender = nil
  376.   $PokemonGlobal.creatingSpawningPokemon = true
  377.   pokemon = pbGenerateWildPokemon(encounter[0],encounter[1])
  378.   # trigger event on spawning of pokemon
  379.   Events.onWildPokemonCreateForSpawning.trigger(nil,pokemon)
  380.   $PokemonGlobal.creatingSpawningPokemon = false
  381.   encounter = [pokemon.species,pokemon.level]
  382.   gender = pokemon.gender if USEFEMALESPRITES==true
  383.   form = pokemon.form if USEALTFORMS == true  
  384.   isShiny = pokemon.shiny?
  385.   return encounter,gender,form,isShiny
  386. end
  387.  
  388. #===============================================================================
  389. # defining new method pbPlaceEncounter to add/place and visualise the pokemon
  390. # "encounter" on the overworld-tile (x,y)
  391. #===============================================================================
  392. def pbPlaceEncounter(x,y,encounter,gender = nil,form = nil,isShiny = nil)
  393.   # place event with random movement with overworld sprite
  394.   # We define the event, which has the sprite of the pokemon and activates the wildBattle on touch
  395.   if !$MapFactory
  396.     $game_map.spawnEvent(x,y,encounter,gender,form,isShiny)
  397.   else
  398.     mapId = $game_map.map_id
  399.     spawnMap = $MapFactory.getMap(mapId)
  400.     spawnMap.spawnEvent(x,y,encounter,gender,form,isShiny)
  401.   end
  402.   # Show spawn animations
  403.   if GameData::TerrainTag.try_get($game_map.terrain_tag(x,y)).id == :Grass
  404.   # Show grass rustling animations when on grass
  405.     $scene.spriteset.addUserAnimation(Settings::RUSTLE_NORMAL_ANIMATION_ID,x,y,true,1)
  406.   end
  407.   if GameData::TerrainTag.try_get($game_map.terrain_tag(x,y)).id == :CaveTile
  408.   # Show cave dust animations when in cave
  409.     $scene.spriteset.addUserAnimation(Settings::DUST_ANIMATION_ID,x,y,true,1)
  410.   end
  411.   if GameData::TerrainTag.try_get($game_map.terrain_tag(x,y)).id == :Water
  412.   # Show water splashing animations when in water
  413.     $scene.spriteset.addUserAnimation(Settings::SPLASH_ANIMATION_ID,x,y,true,1)
  414.   end
  415.   # Play the pokemon cry of encounter
  416.   pbPlayCryOnOverworld(encounter[0])
  417.   # For roaming encounters we have to do the following:
  418.   if $PokemonTemp.roamerIndex != nil &&
  419.      $PokemonGlobal.roamEncounter != nil
  420.     $PokemonGlobal.roamEncounter = nil
  421.     $PokemonGlobal.roamedAlready = true
  422.   end
  423.   $PokemonTemp.forceSingleBattle = false
  424.   EncounterModifier.triggerEncounterEnd()
  425. end
  426.  
  427. #===============================================================================
  428. # adding new Methods pbEncounterTypeOnTile and isEncounterPossibleHereOnTile?
  429. # in Class PokemonEncounters in Script PField_Encounters
  430. #===============================================================================
  431. class PokemonEncounters
  432.   def pbEncounterTypeOnTile(x,y)
  433.     event = $game_player
  434.     thistile = $MapFactory.getRealTilePos(event.map.map_id,event.x,event.y)
  435.   map = $MapFactory.getMap(thistile[0])
  436.     for i in [2, 1, 0]
  437.       tile_id = map.data[thistile[1],thistile[2],i]
  438.       time = pbGetTimeNow
  439.       enctype = -1
  440.        if GameData::TerrainTag.try_get($game_map.terrain_tag(x,y)).id == :Water && self.has_water_encounters?
  441.           enctype = $PokemonEncounters.find_valid_encounter_type_for_time(:Water, time)          
  442.         elsif self.has_cave_encounters?
  443.           enctype = $PokemonEncounters.find_valid_encounter_type_for_time(:Cave, time)  
  444.         elsif self.has_normal_land_encounters?
  445.           enctype = $PokemonEncounters.find_valid_encounter_type_for_time(:Land, time)
  446.           if pbInBugContest? && self.has_encounter_type?(:BugContest)
  447.             enctype = :BugContest
  448.           end
  449.         end
  450.       return  enctype
  451.     end
  452.   end
  453.  
  454.   def isEncounterPossibleHereOnTile?(x,y)
  455.   event = $game_player
  456.   thistile = $MapFactory.getRealTilePos(event.map.map_id,event.x,event.y)
  457.   map = $MapFactory.getMap(thistile[0])
  458.     for i in [2, 1, 0]
  459.       tile_id = map.data[thistile[1],thistile[2],i]
  460.       if GameData::TerrainTag.try_get($game_map.terrain_tag(x,y)).id == :Water
  461.         return true
  462.       elsif self.has_cave_encounters?
  463.         return true
  464.       elsif self.has_normal_land_encounters?
  465.         return GameData::TerrainTag.try_get($game_map.terrain_tag(x,y)).id == :Grass
  466.       end
  467.       return false
  468.     end
  469.   end
  470. end
  471.  
  472. #===============================================================================
  473. # new Method spawnEvent in Class Game_Map in Script Game_Map
  474. #===============================================================================
  475. class Game_Map
  476.   def spawnEvent(x,y,encounter,gender = nil,form = nil, isShiny = nil)
  477.     #------------------------------------------------------------------
  478.     # generating a new event
  479.     event = RPG::Event.new(x,y)
  480.     # naming the event "vanishingEncounter" for PART 3
  481.     event.name = "vanishingEncounter"
  482.     #setting the nessassary properties
  483.     key_id = (@events.keys.max || -1) + 1
  484.     event.id = key_id
  485.     event.x = x
  486.     event.y = y
  487.     #event.pages[0].graphic.tile_id = 0
  488.     species = GameData::Species.get(encounter[0]).id
  489.     character_name = species.to_s
  490.     # use shiny-sprite if probability & killcombo is high or shiny-switch is on
  491.     shinysprite = nil
  492.     if isShiny==true
  493.       folder = "Followers shiny" if USESHINYSPRITES == true and pbResolveBitmap("Graphics/Characters/Followers shiny"+character_name)
  494.       shinysprite = true
  495.       $scene.spriteset.addUserAnimation(SHINY_ANIMATION_ID,event.x,event.y,true,2)
  496.    else
  497.       folder = "Followers"
  498.       shinysprite = false
  499.     end
  500.     # use sprite of female pokemon
  501.     character_name += "_female" if USEFEMALESPRITES == true and gender==1 and pbResolveBitmap("Graphics/Characters/#{folder}/"+character_name+"female")
  502.    if !pbResolveBitmap("Graphics/Characters/#{folder}/"+character_name) && gender==0
  503.       character_name+="_male"
  504.    end
  505.     # use sprite of alternative form
  506.     if USEALTFORMS==true #and form!=nil and form!=0
  507.       character_name += "+form.to_s" if pbResolveBitmap("Graphics/Characters/#{folder}/"+character_name+"_"+form.to_s)
  508.     end
  509.     event.pages[0].graphic.character_name = "#{folder}/"+character_name
  510.     # we configure the movement of the overworld encounter
  511.     if rand(100) < AGGRESSIVEENCOUNTERPROBABILITY
  512.       event.pages[0].move_type = 3
  513.       event.pages[0].move_speed = AGGRENCMOVESPEED
  514.       event.pages[0].move_frequency = AGGRENCMOVEFREQ
  515.       event.pages[0].move_route.list[0].code = 10
  516.       event.pages[0].move_route.list[1] = RPG::MoveCommand.new
  517.     else
  518.       event.pages[0].move_type = 1
  519.       event.pages[0].move_speed = ENCMOVESPEED
  520.       event.pages[0].move_frequency = ENCMOVEFREQ
  521.     end
  522.     event.pages[0].step_anime = true if USESTOPANIMATION
  523.     event.pages[0].trigger = 2
  524.     #------------------------------------------------------------------
  525.     # we add the event commands to the event of the overworld encounter
  526.     # set roamer
  527.     if $PokemonGlobal.roamEncounter!=nil
  528.       #[i,species,poke[1],poke[4]]
  529.       parameter1 = $PokemonGlobal.roamEncounter[0].to_s
  530.       parameter2 = $PokemonGlobal.roamEncounter[1].to_s
  531.       parameter3 = $PokemonGlobal.roamEncounter[2].to_s
  532.       $PokemonGlobal.roamEncounter[3] != nil ? (parameter4 = '"'+$PokemonGlobal.roamEncounter[3].to_s+'"') : (parameter4 = "nil")
  533.       parameter = " $PokemonGlobal.roamEncounter = ["+parameter1+","+parameter2+","+parameter3+","+parameter4+"] "
  534.     else
  535.       parameter = " $PokemonGlobal.roamEncounter = nil "
  536.     end
  537.     pbPushScript(event.pages[0].list,sprintf(parameter))
  538.     parameter = ($PokemonTemp.roamerIndex!=nil) ? " $PokemonTemp.roamerIndex = "+$PokemonTemp.roamerIndex.to_s : " $PokemonTemp.roamerIndex = nil "
  539.     pbPushScript(event.pages[0].list,sprintf(parameter))
  540.     #parameter = ($PokemonGlobal.nextBattleBGM!=nil) ? " $PokemonGlobal.nextBattleBGM = '"+$PokemonGlobal.nextBattleBGM.to_s+"'" : " $PokemonGlobal.nextBattleBGM = nil "
  541.     #pbPushScript(event.pages[0].list,sprintf(parameter))
  542.     parameter = ($PokemonTemp.forceSingleBattle!=nil) ? " $PokemonTemp.forceSingleBattle = "+$PokemonTemp.forceSingleBattle.to_s : " $PokemonTemp.forceSingleBattle = nil "
  543.     pbPushScript(event.pages[0].list,sprintf(parameter))
  544.     #tech - fix this
  545.     #parameter = ($PokemonTemp.encounterType!=nil) ? " $PokemonTemp.encounterType = "+$PokemonTemp.encounterType.to_s : " $PokemonTemp.encounterType = nil "
  546.     pbPushScript(event.pages[0].list,sprintf(parameter))
  547.     # setting $PokemonGlobal.battlingSpawnedPokemon = true
  548.     pbPushScript(event.pages[0].list,sprintf(" $PokemonGlobal.battlingSpawnedPokemon = true"))    
  549.     #pbSingleOrDoubleWildBattle(encounter[0],encounter[1])
  550.     gender = "nil" if gender==nil
  551.     form = "nil" if form==nil
  552.     shinysprite = "nil" if shinysprite==nil
  553.     pbPushScript(event.pages[0].list,sprintf(" pbSingleOrDoubleWildBattle(:"+encounter[0].to_s+","+encounter[1].to_s+", $game_map.events["+key_id.to_s+"].map.map_id, $game_map.events["+key_id.to_s+"].x, $game_map.events["+key_id.to_s+"].y,"+gender.to_s+","+form.to_s+","+shinysprite.to_s+")"))
  554.     # setting $PokemonGlobal.battlingSpawnedPokemon = false
  555.     pbPushScript(event.pages[0].list,sprintf(" $PokemonGlobal.battlingSpawnedPokemon = false"))        
  556.     if !$MapFactory
  557.       parameter = "$game_map.removeThisEventfromMap(#{key_id})"
  558.     else
  559.       mapId = $game_map.map_id
  560.       parameter = "$MapFactory.getMap("+mapId.to_s+").removeThisEventfromMap(#{key_id})"
  561.     end
  562.     pbPushScript(event.pages[0].list,sprintf(parameter))
  563.     pbPushEnd(event.pages[0].list)
  564.     #------------------------------------------------------------------
  565.     # creating and adding the Game_Event
  566.     gameEvent = Game_Event.new(@map_id, event, self)
  567.     key_id = (@events.keys.max || -1) + 1
  568.     gameEvent.id = key_id
  569.     gameEvent.moveto(x,y)
  570.     @events[key_id] = gameEvent
  571.     #-------------------------------------------------------------------------
  572.     #updating the sprites
  573.     sprite = Sprite_Character.new(Spriteset_Map.viewport,@events[key_id])
  574.     $scene.spritesets[self.map_id].character_sprites.push(sprite)
  575.   end
  576. end
  577.  
  578. #===============================================================================
  579. # adding new Method pbSingleOrDoubleWildBattle to reduce the code in spawnEvent
  580. #===============================================================================
  581. def pbSingleOrDoubleWildBattle(species,level,map_id,x,y,gender = nil,form = nil,shinysprite = nil)
  582.   if $MapFactory
  583.     terrainTag = $MapFactory.getTerrainTag(map_id,x,y)
  584.   else
  585.     terrainTag = $game_map.terrain_tag(x,y)
  586.   end
  587.   ##if species.is_a?(String)
  588.  #   species = species.to_sym
  589.  # end
  590.   species = GameData::Species.get(species).id
  591.   if !$PokemonTemp.forceSingleBattle && !pbInSafari? && ($PokemonGlobal.partner ||
  592.        ($Trainer.able_pokemon_count>1 && GameData::TerrainTag.try_get($game_map.terrain_tag(x,y)).double_wild_encounters == true && rand(100)<30))
  593.       encounter2 = $PokemonEncounters.pbEncounteredPokemon($PokemonTemp.encounterType)
  594.       encounter2 = EncounterModifier.trigger(encounter2)
  595.       pbDoubleWildBattle(species,level,encounter2[0],encounter2[1],nil,true,false,gender,form,shinysprite,nil,nil,nil)
  596.   else
  597.     pbWildBattle(species,level,nil,true,false,gender,form,shinysprite)
  598.   end
  599.   #tech- figure out what this was
  600.   #$PokemonTemp.encounterType = -1
  601.   $PokemonTemp.forceSingleBattle = false
  602.   EncounterModifier.triggerEncounterEnd
  603. end
  604.  
  605. #===============================================================================
  606. # overriding Method pbWildBattleCore in Script PField_Battles
  607. # to include alternate forms of the wild pokemon
  608. #===============================================================================
  609. def pbWildBattleCore(*args)
  610.   outcomeVar = $PokemonTemp.battleRules["outcomeVar"] || 1
  611.   canLose    = $PokemonTemp.battleRules["canLose"] || false
  612.   # Skip battle if the player has no able Pokémon, or if holding Ctrl in Debug mode
  613.   if $Trainer.able_pokemon_count==0 || ($DEBUG && Input.press?(Input::CTRL))
  614.     pbMessage(_INTL("SKIPPING BATTLE...")) if $Trainer.pokemon_count>0
  615.     pbSet(outcomeVar,1)   # Treat it as a win
  616.     $PokemonTemp.clearBattleRules
  617.     $PokemonGlobal.nextBattleBGM       = nil
  618.     $PokemonGlobal.nextBattleME        = nil
  619.     $PokemonGlobal.nextBattleCaptureME = nil
  620.     $PokemonGlobal.nextBattleBack      = nil
  621.     pbMEStop
  622.     return 1   # Treat it as a win
  623.   end
  624.   # Record information about party Pokémon to be used at the end of battle (e.g.
  625.   # comparing levels for an evolution check)
  626.   Events.onStartBattle.trigger(nil)
  627.   # Generate wild Pokémon based on the species and level
  628.   foeParty = []
  629.   sp = nil
  630.   for arg in args
  631.     if arg.is_a?(Pokemon)
  632.       foeParty.push(arg)
  633.     elsif arg.is_a?(Array)
  634.       species = GameData::Species.get(arg[0]).id
  635.       pkmn = pbGenerateWildPokemon(species,arg[1])
  636.       #tech- make sure this stuff works
  637.       #-----------------------------------------------------------------------------
  638.       #added by derFischae to set the gender, form and shinyflag
  639.       if arg.length()==5
  640.         gender = arg[2]
  641.         pkmn.gender = gender if USEFEMALESPRITES==true and gender!=nil and gender>=0 and gender<3
  642.         form = arg[3]
  643.         pkmn.form = form if USEALTFORMS==true and form!=nil and form>0
  644.         shinyflag = arg[4]
  645.         pkmn.shiny = shinyflag if shinyflag!=nil
  646.       end
  647.       # well actually it is not okay to test if form>0, we should also test if form
  648.       # is smaller than the maximal form, but for now I keep it that way.
  649.       #-----------------------------------------------------------------------------
  650.       foeParty.push(pkmn)
  651.     elsif sp
  652.       species = GameData::Species.get(sp).id
  653.       pkmn = pbGenerateWildPokemon(species,arg)
  654.       foeParty.push(pkmn)
  655.       sp = nil
  656.     else
  657.       sp = arg
  658.     end
  659.   end
  660.   raise _INTL("Expected a level after being given {1}, but one wasn't found.",sp) if sp
  661.   # Calculate who the trainers and their party are
  662.   playerTrainers    = [$Trainer]
  663.   playerParty       = $Trainer.party
  664.   playerPartyStarts = [0]
  665.   room_for_partner = (foeParty.length > 1)
  666.   if !room_for_partner && $PokemonTemp.battleRules["size"] &&
  667.      !["single", "1v1", "1v2", "1v3"].include?($PokemonTemp.battleRules["size"])
  668.     room_for_partner = true
  669.   end
  670.   if $PokemonGlobal.partner && !$PokemonTemp.battleRules["noPartner"] && room_for_partner
  671.     ally = NPCTrainer.new($PokemonGlobal.partner[1],$PokemonGlobal.partner[0])
  672.     ally.id    = $PokemonGlobal.partner[2]
  673.     ally.party = $PokemonGlobal.partner[3]
  674.     playerTrainers.push(ally)
  675.     playerParty = []
  676.     $Trainer.party.each { |pkmn| playerParty.push(pkmn) }
  677.     playerPartyStarts.push(playerParty.length)
  678.     ally.party.each { |pkmn| playerParty.push(pkmn) }
  679.     setBattleRule("double") if !$PokemonTemp.battleRules["size"]
  680.   end
  681.   # Create the battle scene (the visual side of it)
  682.   scene = pbNewBattleScene
  683.   # Create the battle class (the mechanics side of it)
  684.   battle = PokeBattle_Battle.new(scene,playerParty,foeParty,playerTrainers,nil)
  685.   battle.party1starts = playerPartyStarts
  686.   # Set various other properties in the battle class
  687.   pbPrepareBattle(battle)
  688.   $PokemonTemp.clearBattleRules
  689.   # Perform the battle itself
  690.   decision = 0
  691.   pbBattleAnimation(pbGetWildBattleBGM(foeParty),(foeParty.length==1) ? 0 : 2,foeParty) {
  692.     pbSceneStandby {
  693.       decision = battle.pbStartBattle
  694.     }
  695.     pbAfterBattle(decision,canLose)
  696.   }
  697.   Input.update
  698.   # Save the result of the battle in a Game Variable (1 by default)
  699.   #    0 - Undecided or aborted
  700.   #    1 - Player won
  701.   #    2 - Player lost
  702.   #    3 - Player or wild Pokémon ran from battle, or player forfeited the match
  703.   #    4 - Wild Pokémon was caught
  704.   #    5 - Draw
  705.   pbSet(outcomeVar,decision)
  706.   return decision
  707. end
  708.  
  709.  
  710. #===============================================================================
  711. # overriding Method pbWildBattle in Script PField_Battles
  712. # to include alternate forms of the wild pokemon
  713. #===============================================================================
  714.   #-----------------------------------------------------------------------------
  715.   #added by derFischae to set the gender, form and shinyflag
  716.   #genwildpoke.gender = gender if USEFEMALESPRITES==true and gender!=nil and gender>=0 and gender<3
  717.   #genwildpoke.form = form if USEALTFORMS==true and form!=nil and form>0
  718.   #genwildpoke.shinyflag = shinysprite if shinysprite!=nil
  719.   # well actually it is not okay to test if form>0, we should also test if form
  720.   # is smaller than the maximal form, but for now I keep it that way.
  721.   #-----------------------------------------------------------------------------
  722.  
  723. #===============================================================================
  724. # Standard methods that start a wild battle of various sizes
  725. #===============================================================================
  726. # Used when walking in tall grass, hence the additional code.
  727. def pbWildBattle(species, level, outcomeVar=1, canRun=true, canLose=false,gender = nil,form = nil,shinysprite = nil)
  728.   species = GameData::Species.get(species).id
  729.   # Potentially call a different pbWildBattle-type method instead (for roaming
  730.   # Pokémon, Safari battles, Bug Contest battles)
  731.   handled = [nil]
  732.   Events.onWildBattleOverride.trigger(nil,species,level,handled)
  733.   return handled[0] if handled[0]!=nil
  734.   # Set some battle rules
  735.   setBattleRule("outcomeVar",outcomeVar) if outcomeVar!=1
  736.   setBattleRule("cannotRun") if !canRun
  737.   setBattleRule("canLose") if canLose
  738.   # Perform the battle
  739.   decision = pbWildBattleCore([species,level,gender,form,shinysprite])
  740.   # Used by the Poké Radar to update/break the chain
  741.   Events.onWildBattleEnd.trigger(nil,species,level,decision)
  742.   # Return false if the player lost or drew the battle, and true if any other result
  743.   return (decision!=2 && decision!=5)
  744. end
  745.  
  746. #===============================================================================
  747. # overriding Method pbDoubleWildBattle in Script PField_Battles
  748. # to include alternate forms of the wild pokemon in double battles
  749. #===============================================================================
  750.   #-----------------------------------------------------------------------------
  751.   #added by derFischae to set the gender, form and shinyflag
  752.   # well actually it is not okay to test if form>0, we should also test if form
  753.   # is smaller than the maximal form, but for now I keep it that way.
  754.   #genwildpoke.gender = gender1 if USEFEMALESPRITES==true and gender1!=nil and gender1>=0 and gender1<3
  755.   #if USEALTFORMS==true and form1!=nil and form1>0
  756.   #  genwildpoke.form = form1  
  757.   #  genwildpoke.shinyflag = shinysprite1 if shinysprite1!=nil
  758.   #  genwildpoke.resetMoves
  759.   #end
  760.   #genwildpoke2.gender = gender if USEFEMALESPRITES==true and gender2!=nil and gender2>=0 and gender2<3
  761.   #if USEALTFORMS==true and form2!=nil and form2>0
  762.   #  genwildpoke2.form = form2 if USEALTFORMS==true and form2!=nil and form2>0  
  763.   #  genwildpoke2.shinyflag = shinysprite2 if shinysprite2!=nil
  764.   #  genwildpoke2.resetMoves
  765.   #end
  766.   #-----------------------------------------------------------------------------
  767.  
  768. def pbDoubleWildBattle(species1, level1, species2, level2,
  769.                        outcomeVar=1, canRun=true, canLose=false,
  770.                        gender1 = nil,form1 = nil,shinysprite1 = nil,gender2 = nil,form2 = nil,shinysprite2 = nil)
  771.   # Set some battle rules
  772.   setBattleRule("outcomeVar",outcomeVar) if outcomeVar!=1
  773.   setBattleRule("cannotRun") if !canRun
  774.   setBattleRule("canLose") if canLose
  775.   setBattleRule("double")
  776.   # Perform the battle
  777.   decision = pbWildBattleCore([species1,level1,gender1,form1,shinysprite1], [species2,level2,gender2,form2,shinysprite2])
  778.   # Return false if the player lost or drew the battle, and true if any other result
  779.   return (decision!=2 && decision!=5)
  780. end
  781.  
  782. #===============================================================================
  783. # adding new method PBTerrain.isRock? to module PBTerrain in script PBTerrain
  784. # to check if the terrainTag "tag" is rock
  785. #===============================================================================
  786. module PBTerrain
  787.   def PBTerrain.isRock?(tag)
  788.     return tag==PBTerrain::Rock
  789.   end
  790. end
  791.  
  792. #===============================================================================
  793. # adding new method pbPlayCryOnOverworld to load/play Pokémon cry files
  794. # SPECIAL THANKS TO "Ambient Pokémon Cries" - by Vendily
  795. # actually it's not used, but that code helped to include the pkmn cries faster
  796. #===============================================================================
  797. def pbPlayCryOnOverworld(pokemon,volume=90,pitch=nil)
  798.   return if !pokemon
  799.   if pokemon.is_a?(Symbol)
  800.     Pokemon.play_cry(pokemon)
  801. #    pbPlayCrySpecies(pokemon,0,volume,pitch)
  802.   elsif !pokemon.egg?
  803.     if pokemon.respond_to?("chatter") && pokemon.chatter
  804.       pokemon.chatter.play
  805.     else
  806.       pkmnwav = pbCryFile(pokemon)
  807.       if pkmnwav
  808.         pbBGSPlay(RPG::AudioFile.new(pkmnwav,volume,
  809.            (pitch) ? pitch : (pokemon.hp*25/pokemon.totalhp)+75)) rescue nil
  810.       end
  811.     end
  812.   end
  813. end
  814.  
  815. #===============================================================================
  816. # adding a new method attr_reader to the Class Spriteset_Map in Script
  817. # Spriteset_Map to get access to the variable @character_sprites of a
  818. # Spriteset_Map
  819. #===============================================================================
  820. class Spriteset_Map
  821.   attr_reader :character_sprites
  822. end
  823.  
  824. #===============================================================================
  825. # adding a new method attr_reader to the Class Scene_Map in Script
  826. # Scene_Map to get access to the Spriteset_Maps listed in the variable
  827. # @spritesets of a Scene_Map
  828. #===============================================================================
  829. class Scene_Map
  830.   attr_reader :spritesets
  831. end
  832.  
  833.           #########################################################
  834.           #                                                       #
  835.           #      2. PART: VANISHING OF OVERWORLD ENCOUNTER        #
  836.           #                                                       #
  837.           #########################################################
  838. #===============================================================================
  839. # adding a new variable stepCount and replacing the method increase_steps
  840. # in class Game_Event in script Game_Event to count the steps of
  841. # overworld encounter and to make them disappear after taking more then
  842. # STEPSBEFOREVANISHING steps
  843. #===============================================================================
  844. class Game_Event < Game_Character
  845.   attr_accessor :event
  846.   attr_accessor :stepCount #counts the steps of an overworld encounter
  847.  
  848.   alias original_increase_steps increase_steps
  849.   def increase_steps
  850.     if self.name=="vanishingEncounter" && @stepCount && @stepCount>=STEPSBEFOREVANISHING
  851.       removeThisEventfromMap
  852.     else
  853.       @stepCount=0 if (!@stepCount || @stepCount<0)
  854.       @stepCount+=1
  855.       original_increase_steps
  856.     end
  857.   end
  858.  
  859.   def removeThisEventfromMap
  860.     if $game_map.events.has_key?(@id) and $game_map.events[@id]==self
  861.       for sprite in $scene.spritesets[$game_map.map_id].character_sprites
  862.         if sprite.character==self
  863.           $scene.spritesets[$game_map.map_id].character_sprites.delete(sprite)
  864.           sprite.dispose
  865.           break
  866.         end
  867.       end
  868.       $game_map.events.delete(@id)        
  869.     else
  870.       if $MapFactory
  871.         for map in $MapFactory.maps
  872.           if map.events.has_key?(@id) and map.events[@id]==self
  873.             for sprite in $scene.spritesets[self.map_id].character_sprites
  874.               if sprite.character==self
  875.                 $scene.spritesets[map.map_id].character_sprites.delete(sprite)
  876.                 sprite.dispose
  877.                 break
  878.               end
  879.             end
  880.             map.events.delete(@id)
  881.             break
  882.           end
  883.         end
  884.       else
  885.         pbMessage("Actually, this should not be possible")
  886.       end
  887.     end
  888.   end
  889. end
  890.  
  891. class Game_Map
  892.   def removeThisEventfromMap(id)
  893.     if @events.has_key?(id)
  894.       for sprite in $scene.spritesets[@map_id].character_sprites
  895.         if sprite.character == @events[id]
  896.           $scene.spritesets[@map_id].character_sprites.delete(sprite)
  897.           sprite.dispose
  898.           break
  899.         end
  900.       end
  901.       @events.delete(id)        
  902.     end
  903.   end  
  904. end
  905.  
  906.           #########################################################
  907.           #                                                       #
  908.           #             3. PART: ADDITIONAL FEATURES              #
  909.           #                                                       #
  910.           #########################################################
  911.  
  912. #===============================================================================
  913. # Adding Event OnWildPokemonCreateForSpawning to Module Events in Script PField_Field.
  914. # This Event is triggered  when a new pokemon spawns. Use this Event instead of OnWildPokemonCreate
  915. # if you want to add a new procedure that modifies a pokemon on spawning
  916. # but not on creation while going into battle with an already spawned pokemon.
  917. #Note that OnPokemonCreate is also triggered when a pokemon is created for spawning,
  918. #But OnPokemonCreateForSpawning is not triggered when a pokemon is created in other situations than for spawning
  919. #===============================================================================
  920. module Events
  921.   @@OnWildPokemonCreateForSpawning          = Event.new
  922.  
  923.   # Triggers whenever a wild Pokémon is created for spawning
  924.   # Parameters:
  925.   # e[0] - Pokémon being created for spawning
  926.   def self.onWildPokemonCreateForSpawning; @@OnWildPokemonCreateForSpawning; end
  927.   def self.onWildPokemonCreateForSpawning=(v); @@OnWildPokemonCreateForSpawning = v; end
  928.  
  929. end
  930.  
  931. #===============================================================================
  932. # adds new parameter battlingSpawnedPokemon to the class PokemonGlobalMetadata
  933. # defined in script section PField_Metadata. Also overrides initialize include that parameter there.
  934. #===============================================================================
  935.  
  936. class PokemonGlobalMetadata
  937.   attr_accessor :battlingSpawnedPokemon
  938.   attr_accessor :creatingSpawningPokemon
  939.  
  940.   alias original_initialize initialize
  941.   def initialize
  942.     battlingSpawnedPokemon = false
  943.     creatingSpawningPokemon = false
  944.     original_initialize
  945.   end
  946. end
  947.  
  948.  
  949.  
  950. def pbPushScript(list,script,indent=0)
  951.   return if !script
  952.   first = true
  953.   textsplit2 = script.split(/\n/)
  954.   for i in 0...textsplit2.length
  955.     textchunk = textsplit2[i].gsub(/\s+$/,"")
  956.     if textchunk && textchunk!=""
  957.       list.push(RPG::EventCommand.new((first) ? 355 : 655,indent,[textchunk]))
  958.       first = false
  959.     end
  960.   end
  961. end
  962.  
  963.  
  964. def pbPushEnd(list)
  965.   list.push(RPG::EventCommand.new(0,0,[]))
  966. end
Add Comment
Please, Sign In to add comment