Advertisement
thiago_d_d

Terrain Tags

Jan 15th, 2013
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 3.10 KB | None | 0 0
  1. #===============================================================================
  2. #   http://thiagodd.blogspot.com.br
  3. # [TSDA] Terrain Tags
  4. #   --> Version 1.1
  5. #   by thiago_d_d
  6. #
  7. # -----------------------------------------------------------------------------
  8. # * Features
  9. # -----------------------------------------------------------------------------
  10. #  This script changes one variable value or executes a code based on the terrain
  11. #  the player steps. This is nearly identical with the RPG Maker XP terrain tags.
  12. # -----------------------------------------------------------------------------
  13. # * Install
  14. # -----------------------------------------------------------------------------
  15. #  Paste the script in the aditional scripts section.
  16. # -----------------------------------------------------------------------------
  17. # * Configuration
  18. # -----------------------------------------------------------------------------
  19. #  Para implementar uma ação que irá acontecer num tile, é necessário
  20. #  Seguir os seguintes passos:
  21. #  ----------------------
  22. #   ===> If the tile is contained in the Tileset - A
  23. #  ----------------------
  24. #  Go to TILES_A_VALUE and add an code in this format
  25. #   [x,y] => k
  26. #  In x place, put the x position of tile tile in the Tileset A.
  27. #  In y place, put the y position of tile tile in the Tileset A
  28. #  In place of k, put an value to atribute to the variable, or put an code to execute.
  29. #----------------------
  30. #   ===> If the tile is not contained in the Tileset - A
  31. #  ----------------------
  32. # You have to discover the index. First, put that tile on any map.
  33. # After that, create an event with that script code:
  34. # p $game_map.data[x,y,2]
  35. # Test the game, activate the event, and the tile index will be printed.
  36. # Use the tile index and go to TILES_OTHER_VALUE, and add an line like this:
  37. #    Found_index => action
  38. # in place of action, put an value to atribute to the variable,
  39. # or put an code to execute.
  40. #
  41. # If you have any question, see the examples below.
  42. #===============================================================================
  43. module TSDA
  44.   #Id of the variable that will be changed
  45.   TILES_VAR_ID = 1
  46.   TILES_A_VALUE =
  47.   {
  48.      [0,0] => 1,
  49.      [0,1] => 2
  50.   }
  51.   TILES_OTHER_VALUE =
  52.   {
  53.     7 => 1
  54.   }
  55. end
  56.  
  57. class Game_Player
  58.   include TSDA
  59.   def var_change
  60.     @changed = 0
  61.     tile_id = $game_map.data[@x,@y,0]
  62.     tile_id2 = $game_map.data[@x,@y,2]
  63.     x = (tile_id / 128 % 2 * 8 + tile_id % 8)
  64.     y = tile_id % 256 / 8 % 16
  65.     pos = [x,y]
  66.     if !TILES_A_VALUE[pos].nil?
  67.       value = TILES_A_VALUE[pos]
  68.       if value.is_a?(Integer)
  69.         $game_variables[TILES_VAR_ID] = value
  70.       elsif value != nil
  71.         eval(value)
  72.       end
  73.     end
  74.     if !TILES_OTHER_VALUE[tile_id2].nil?
  75.       value = TILES_OTHER_VALUE[tile_id2]
  76.       if value.is_a?(Integer)
  77.         $game_variables[TILES_VAR_ID] = value
  78.       else
  79.         eval(value)
  80.       end
  81.     end
  82.   end
  83.   alias tiles_th_updt update
  84.   def update
  85.     if !@changed.nil? & !moving?
  86.       @changed = nil
  87.     end
  88.     var_change if (moving? and @changed.nil?)
  89.     tiles_th_updt
  90.   end
  91. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement