- Pokémon Essentials Version
- v20.1 ➖
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!
This mostly uses calls in base RPG Maker XP, with one key difference - pbRange uses event.width and event.height, functions that were added in Essentials v19. Just comment them out if you're using an earlier version/non-Essentials project.
Old version left here for posterity, but I really wouldn't recommend it.
The X and Y values for a tile can be seen in the bottom-right of the map editor.
If you're using v19 or higher, these functions overlap with event sizes in many ways. However, there's some differences that make these still useful IMO.
This script creates some new script calls to use in events when you want to keep the player in a certain area!
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 pbBorder(point,direction)
direction = direction.downcase
case direction
when "up","down"
player = $game_player.y
when "left","right"
player= $game_player.x
end
case direction
when "up","left"
return (point < player)
when "down","right"
return (player > point)
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 pbBoundary(x1,x2,y1,y2)
ret = false
xonly == true if y1 == y2
yonly == true if x1 == x2
xbound = $game_player.x.between?(x1,x2)
ybound = $game_player.y.between?(y1,y2)
ret = true if (xbound && ybound) || (xbound && xonly) || (ybound && yonly)
return ret
end
#=============================================================================
# Ranges
#=============================================================================
#pbRange returns true if the player is within a number of tiles from the event.
#xonly will only check horizontally
#yonly will only check vertically
def pbRange(limit,xonly=false,yonly=false,event=@event_id)
event=$game_map.events[event] if event.is_a?(Integer)
ret = false
leftlimit = event.x - limit
rightlimit = event.x + limit + event.width - 1
downlimit = event.y + limit
uplimit = event.y - limit - event.height + 1
xbound = $game_player.x.between?(leftlimit,rightlimit)
ybound = $game_player.y.between?(uplimit,downlimit)
ret = true if (xbound && ybound) || (xbound && xonly) || (ybound && yonly)
return ret
end
Old version left here for posterity, but I really wouldn't recommend it.
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
The X and Y values for a tile can be seen in the bottom-right of the map editor.
pbBorder(point,direction)
- This returns true if the player is past the given point in the given direction. Direction is "up", "down", "left", or "right". (quotes included, capitalization doesn't matter) For example, pbBorder(11,"down")
would return true if the player was below the 11th row of tiles.pbBoundary(left,right,up,down)
- This returns true if the player is within the boundaries, and false if they're not. If the left/right values are the same, only the up/down values will be checked, and vice versa.pbRange(limit,xonly,yonly,event)
- Returns true if the player is (limit) tiles within the given event. xonly
, yonly
, and event
are all optional arguments. xonly
and yonly
are to restrict it to verticle/horizontal movement, respectively. event
is an event ID number.If you're using v19 or higher, these functions overlap with event sizes in many ways. However, there's some differences that make these still useful IMO.
- Events can't occupy the same space, and NPCs won't pass through an event unless Through is on, even if the event doesn't have a graphic. These calls only affect the player, so NPCs could still pass through just fine, and even be placed on affected areas.
- With a boundary based around the player touching an event, the player could hypothetically pass the barrier if they had some means of passing over tiles. (like a jump function or Pokémon Quantum's teleport item) These boundaries check the coordinates of the player, so they don't need the player to touch them to activate.
- With pbRange, you can have the range of an event be larger than the event itself.
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 or higher, 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!
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
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:
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 or higher, 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.
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 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
- Credit to TechSkylander1518, please!