Vendily

Deep Marsh Tiles

Aug 15th, 2020 (edited)
1,564
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #===============================================================================
  2. # Deep Marsh Tiles - By Vendily [v17]
  3. #===============================================================================
  4. # This script adds in Deep Marsh tiles, the annoying classic from DPPt, which
  5. #  cause the player to sink in and get stuck until they wiggle free.
  6. #===============================================================================
  7. # To use it, you must create a new tile with terrain tag MarshDeep.
  8. #  Remember to change the number if you are already using the default 17
  9. # There's also one other edit to "def bush_depth" in Game_Character.
  10. #  This line :
  11. #      return 12 if self.map.bush?(@x,@y) and !moving?
  12. #  Becomes this line :
  13. #      return 12 if (self.map.bush?(@x,@y) and !moving?) || (self==$game_player && $PokemonGlobal.stuck)
  14. # You could instead edit the line above in it in the same manner if you want the
  15. #  player to sink more into the mud. Or even just make the stuck condition on
  16. #  its own line to have it sink a different amount.
  17. #  Not gonna explain that though, it's beyond the scope of the script.
  18. #===============================================================================
  19. # * The number of times the player must turn before becoming freed (Default 5)
  20. # * The sound the player makes on freeing themselves (Default "Player jump")
  21. #===============================================================================
  22.  
  23. MARSHTILES_TURN_TIMES = 5
  24. MARSHTILES_JUMP_SOUND = "Player jump"
  25.  
  26. module PBTerrain
  27.   MarshDeep     = 17
  28. end
  29.  
  30. class PokemonGlobalMetadata
  31.   attr_accessor :stuck
  32.   attr_accessor :mudfree
  33.  
  34.   def stuck
  35.     @stuck=false if !@stuck
  36.     return @stuck
  37.   end
  38. end
  39.  
  40. Events.onStepTakenFieldMovement+=proc {|sender,e|
  41.   event = e[0] # Get the event affected by field movement
  42.   if $scene.is_a?(Scene_Map)
  43.     currentTag = pbGetTerrainTag(event)
  44.     if event==$game_player && currentTag==PBTerrain::MarshDeep && !$PokemonGlobal.mudfree
  45.       Kernel.pbStuckTile(event)
  46.     end
  47.   end
  48. }
  49.  
  50. def Kernel.pbStuckTile(event=nil)
  51.   event = $game_player if !event
  52.   return if !event
  53.   $PokemonGlobal.stuck=true
  54.   event.straighten
  55.   olddir=event.direction
  56.   dir=olddir
  57.   turntimes=0
  58.   loop do
  59.     break if turntimes>=MARSHTILES_TURN_TIMES
  60.     Graphics.update
  61.     Input.update
  62.     pbUpdateSceneMap
  63.     key=Input.dir4
  64.     dir=key if key>0
  65.     if dir!=olddir
  66.       case dir
  67.       when 2; event.turn_down
  68.       when 4; event.turn_left
  69.       when 6; event.turn_right
  70.       when 8; event.turn_up
  71.       end
  72.       olddir=dir
  73.       turntimes+=1
  74.     end
  75.   end
  76.   event.center(event.x,event.y)
  77.   event.straighten
  78.   $PokemonGlobal.stuck=false
  79.   $PokemonGlobal.mudfree=true
  80.   event.jump(0,0)
  81.   pbSEPlay(MARSHTILES_JUMP_SOUND)
  82.   20.times do
  83.     Graphics.update
  84.     Input.update
  85.     pbUpdateSceneMap
  86.   end
  87.   $PokemonGlobal.mudfree=false
  88. end
RAW Paste Data