This is a script which can be used to make events as well as the player to stick to a specific terrain tag or don't allow them to enter a specific terrain tag.
class Game_Character
attr_accessor :terrain_tag
alias_method(:zeriab_terrain_tag_passable, :passable?)
def passable?(x, y, d)
new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
if terrain_tag
if (terrain_tag > 0 && $game_map.terrain_tag(new_x,new_y) != terrain_tag) ||
(terrain_tag < 0 && $game_map.terrain_tag(new_x,new_y) == -terrain_tag)
return false
end
end
return zeriab_terrain_tag_passable(x, y, d)
end
end
class Game_Event < Game_Character
alias_method(:zeriab_terrain_tag_init, :initialize)
def initialize(map_id, event)
zeriab_terrain_tag_init(map_id, event)
if event.name.include?('<t>')
self.terrain_tag = $game_map.terrain_tag(x, y)
elsif !(/<t=(\d*)>/ =~ event.name).nil?
self.terrain_tag = $1.to_i
elsif !(/<t=-(\d*)>/ =~ event.name).nil?
self.terrain_tag = -($1.to_i)
end
end
end
For events:
Put <t> in the name and it will keep to tiles of the same terrain tag as the one it starts on.
Put <t=3> in the name to make it stick to tiles with terrain tags = 3. If it is outside it will simply not move, it can turn, but it cannot move.
Put <t=-1> in the name to prevent it from moving onto tiles with terrain tag = 1.
If you want to change it dynamically you will have to do something like
$game_map.event[42].terrain_tag = 5 to change it. Setting it to
nil removes the terrain tag. Setting it to a negative number prevents entering such a tile.
Note that it will reset on map change. (To whatever is in the name or nil)
For the player:
$game_player.terrain_tag = 2
The player cannot go to a tile which has a different terrain tag than 2.
$game_player.terrain_tag = nil
Disable the terrain tag restriction, the player can now move normally.
$game_player.terrain_tag = -4
The player cannot move to a tile which have terrain tag 4.
*hugs*
- Zeriab