# Better Barriers

Pokémon Essentials Version
I had this all ready to go before Game Jam and forgot to post oops lol

This script creates some new script calls to use in events when you want to keep the player in a certain area! For example, rather than making an event that relies on player touch and copy+pasting that onto every tile where they could step away, you can just make one event that checks if the player has moved past a certain point! And if you're using a script where a player could pass over tiles, like jump functionality or Quantum's teleport item, you don't have to worry about the player passing over your event!

Note- while this was developed in v18.1, the only calls used are things from base RPG Maker, so this should be compatible with any version, or even XP games that don't use Essentials!

Code
Paste in a new script section above Main!
Ruby:
#=============================================================================
# Borders
#=============================================================================

#Borders prevent the player from crossing past a point in a certain direction
#Set the event to parallel process, with conditional script Border(point,"direction")

def Border(point,direction)
event=$game_map.events[@event_id] px=$game_player.x
py=$game_player.y if event case direction when "up" if py<point return true end when "right" if px>point return true end when "down" if py>point return true end when "left" if px<point return true end end end end #============================================================================= # Boundaries #============================================================================= #Boundaries require the player to stay within the limits given. #Set the event to parallel process, with conditional script Boundary(X1,X2,Y1,Y2) # Y1 # X1 (||) X2 # Y2 #Set both Xs to 0 for only Y boundaries, and vice versa def Boundary(x1,x2,y1,y2) event=$game_map.events[@event_id]
px=$game_player.x py=$game_player.y
if event
if y1==y2
if px<x1 || px>x2
return true
else
return false
end
elsif x1==x2
if py<y1 || py>y2
return true
else
return false
end
else
if px<x1 || px>x2 ||
py<y1 || py>y2
return true
else
return false
end
end
end
end

#=============================================================================
# Anchors
#=============================================================================

#Anchors require the player to be within a certain range of their event.
#Set the event to parallel process, with a conditional script Anchor(#), with
#"#" being the number of tiles away the player can be before triggering the event.
#xonly will only restrict the player horizontally
#yonly will only restrict the player vertically

def Anchor(limit,xonly=false,yonly=false)
event=$game_map.events[@event_id] if event x=event.x y=event.y px=$game_player.x
py=\$game_player.y
if xonly==true
if px<=(x-limit) || px>=(x+limit)
return true
end
elsif yonly==true
if py<=(y-limit) || px>=(y+limit)
return true
end
end
if px<=(x-limit) || px>=(x+limit) ||
py<=(y-limit) || py>=(y+limit)
return true
else
return false
end
end
end

Barriers
This script includes three kinds of barriers!

Borders check if the player has gone past a certain line on the map. Create an event set to parallel process, and create a conditional branch with Border(point,direction), with "point" being the x or y limit, and "direction" being either "up", "down", "left", or "right". If this branch is true, your player has crossed the border, and they'll set off the event!

If you're using v19, Borders are a bit obsolete, because you can set an event to any size you want.

Note: This script doesn't know the player's exact position, only if they've gone out-of-bounds. If you want to do any moveroute more complicated than just turning back, I'd recommend pairing this with a pathfinder script!

Let's change the events in the default Pokemon Lab into a border!

Normally, the map looks like this:

If I select the tile of these events, I can see in the bottom-right corner of my screen that their y-coordinate is 8.

So, I know that I just want to make sure the player can't go down past 8!

I'll make a parallel process event that checks for this...

And then I'll just copy the commands that were in the original barriers! I'll also require the same switch to be turned on, so the border is only active when the starter selection scene is on.

It's worth mentioning that, while this was designed with the intent of being a barrier, it doesn't have to be a negative consequence for crossing it! You could use this to design a finish line in a series of obstacles!

Boundaries are basically just a set of four borders! You'll set it up the same way, but now the command is Boundary(x1,x2,y1,y2). X1 is the border to the left, X2 is the border to the right. Y1 is the border up,Y2 is the border down.

If you want to just make a pair of X boundaries, set Y1 and Y2 to 0, and vice versa for Y boundaries!

If you want to do the inverse- that is, create a restricted zone that the player can't enter- then I'd personally suggest just creating a boundary and using the Else branch!

In theory, you might be able to do it by switching the 1s and 2s, but I feel like that'd be awkward to work around.

Anchors require the player to remain within X tiles of a certain event! Use Anchor(limit) for a square around the event, Anchor(limit,xonly=true) to only restrict horizontal movement, and Anchor(limit,yonly=true) to only restrict vertical movement! Unlike boundaries and borders, an anchor can be changed in the middle of gameplay, because you can move the event around!

You could also use an else branch to create a condition that's not activated unless the player gets within the limit of the event! For example:
Credits