Vendily

Spin Tiles

Aug 10th, 2020 (edited)
1,878
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #===============================================================================
  2. # Spin Tiles - By Vendily, thepsynergist & Barrel's O'Fun [v17]
  3. #===============================================================================
  4. # This script adds in Spin tiles, a Pokémon staple! Once the player steps on
  5. #  one of these tiles, they'll go spinning in the direction on the tile
  6. #  until they hit an impassable object or the a Stop tile. Hitting another
  7. #  spin tile redirects the player.
  8. #===============================================================================
  9. # To use it, you must create 4 new tiles with terrain tags specifing the
  10. #  spun direction. Remember to change the presets if you have other terrain tags
  11. #  installed!
  12. # The newly Added Stop tile is tag 21, but you can set it to -1 if you
  13. #  aren't using it.
  14. # There's also some extra edits:
  15. #  "def character_name" in Game_Player_Visuals.
  16. #  under:
  17. #          # Display running character sprite
  18. #          @character_name = pbGetPlayerCharset(meta,4)
  19. #  put:
  20. #        elsif $PokemonGlobal.spinning
  21. #          @character_name = pbGetPlayerCharset(meta,7)
  22. # If you have another script that also edits the metadata for the player,
  23. #  remember to change the 7 above to the new position in the list.
  24. #
  25. #  Also, in "def pbCanRun?" in Game_Player_Visuals, add a check for
  26. #   $PokemonGlobal.spinning, so you can't run while you're spinning.
  27. #
  28. #  Finally, in "def update" in Game_Player_Visuals.
  29. #  under:
  30. #    if PBTerrain.isIce?(pbGetTerrainTag)
  31. #      @move_speed = ($RPGVX) ? 6.5 : 4.8 # Sliding on ice
  32. #  put:
  33. #    elsif $PokemonGlobal.spinning
  34. #      @move_speed = ($RPGVX) ? 4.5 : 3.8 # Spinning
  35. #  (Adjust the values if you want faster or slower spinning, this is walk speed)
  36. #
  37. # You also have to add a new image to the Player fields in metadata.txt
  38. #  Here's mine
  39. # PlayerA=POKEMONTRAINER_Red,trchar000,boy_bike,boy_surf,boy_run,boy_surf,boy_fish_offset,boy_spin,xxx
  40. #  "boy_spin" is the new one, a graphic that has has each column in a different direction
  41. #  so Down standing, Left standing, Up Standing, Right standing.
  42. #  You can swap left and right, pretty sure, if that looks better.
  43. #
  44. #===============================================================================
  45.  
  46. module PBTerrain
  47.   SpinTileUp    = 17
  48.   SpinTileDown  = 18
  49.   SpinTileLeft  = 19
  50.   SpinTileRight = 20
  51.   SpinTileStop  = 21
  52.  
  53.   def PBTerrain.isSpinTile?(tag)
  54.     return tag==PBTerrain::SpinTileUp ||
  55.            tag==PBTerrain::SpinTileDown ||
  56.            tag==PBTerrain::SpinTileLeft ||
  57.            tag==PBTerrain::SpinTileRight
  58.   end
  59. end
  60.  
  61. class PokemonGlobalMetadata
  62.   attr_accessor :spinning
  63.  
  64.   def spinning
  65.     @spinning=false if !@spinning
  66.     return @spinning
  67.   end
  68. end
  69.  
  70. Events.onStepTakenFieldMovement+=proc {|sender,e|
  71.   event = e[0] # Get the event affected by field movement
  72.   if $scene.is_a?(Scene_Map)
  73.     currentTag = pbGetTerrainTag(event)
  74.     if event==$game_player && PBTerrain.isSpinTile?(currentTag) && !$PokemonGlobal.sliding      
  75.       Kernel.pbSpinTile(event)
  76.     end
  77.   end
  78. }
  79.  
  80. def Kernel.pbSpinTile(event=nil)  
  81.   event = $game_player if !event
  82.   return if !event
  83.   tag=pbGetTerrainTag(event)
  84.   return if !PBTerrain.isSpinTile?(tag)
  85.   oldwalkanime = event.walk_anime
  86.   event.move_speed == 1
  87.   if $PokemonGlobal.spinning == false
  88.     event.straighten
  89.   end
  90.   event.walk_anime = false
  91.   case tag
  92.   when PBTerrain::SpinTileUp
  93.     event.turn_up
  94.    if $PokemonGlobal.spinning == false
  95.       event.pattern=2
  96.    end
  97.   when PBTerrain::SpinTileDown
  98.     event.turn_down
  99.    if $PokemonGlobal.spinning == false
  100.       event.pattern=0
  101.    end
  102.   when PBTerrain::SpinTileRight
  103.     event.turn_right
  104.    if $PokemonGlobal.spinning == false
  105.       event.pattern=1
  106.    end
  107.   when PBTerrain::SpinTileLeft
  108.     event.turn_left
  109.    if $PokemonGlobal.spinning == false
  110.       event.pattern=3
  111.    end
  112.  end
  113.   event.walk_anime = true
  114.   $PokemonGlobal.spinning = true
  115.   loop do
  116.     break if !event.passable?(event.x,event.y,event.direction)
  117.     tag=pbGetTerrainTag(event)
  118.     break if tag==PBTerrain::SpinTileStop
  119.     if PBTerrain.isSpinTile?(tag)
  120.       case tag
  121.       when PBTerrain::SpinTileUp
  122.         event.turn_up
  123.       when PBTerrain::SpinTileDown
  124.         event.turn_down
  125.      when PBTerrain::SpinTileRight
  126.         event.turn_right        
  127.       when PBTerrain::SpinTileLeft
  128.         event.turn_left
  129.       end
  130.     end    
  131.     event.move_forward
  132.     while event.moving?
  133.       Graphics.update
  134.       Input.update
  135.       pbUpdateSceneMap
  136.     end
  137.   end  
  138.   event.center(event.x,event.y)
  139.   event.walk_anime = oldwalkanime  
  140.   $PokemonGlobal.spinning = false
  141.  end
RAW Paste Data