Advertisement
TechSkylander1518

Better Barriers v20

Dec 7th, 2022
1,049
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.19 KB | None | 1 0
  1. #=============================================================================
  2. # Borders
  3. #=============================================================================
  4.  
  5. #Borders prevent the player from crossing past a point in a certain direction
  6. #Set the event to parallel process, with conditional script Border(point,"direction")
  7.  
  8. def pbBorder(point,direction)
  9.   direction = direction.downcase
  10.   case direction
  11.     when "up","down"
  12.       player = $game_player.y
  13.     when "left","right"
  14.       player= $game_player.x
  15.   end
  16.   case direction
  17.     when "up","left"
  18.       return (point < player)
  19.     when "down","right"
  20.       return (player > point)
  21.   end
  22. end
  23.  
  24.  
  25. #=============================================================================
  26. # Boundaries
  27. #=============================================================================
  28.  
  29. #Boundaries require the player to stay within the limits given.
  30. #Set the event to parallel process, with conditional script Boundary(X1,X2,Y1,Y2)
  31. #            Y1
  32. #      X1   (||)      X2
  33. #            Y2
  34. #Set both Xs to 0 for only Y boundaries, and vice versa
  35.  
  36.  
  37. def pbBoundary(x1,x2,y1,y2)
  38.   ret = false
  39.   xonly == true if y1 == y2
  40.   yonly == true if x1 == x2
  41.   xbound = $game_player.x.between?(x1,x2)
  42.   ybound = $game_player.y.between?(y1,y2)
  43.   ret = true if (xbound && ybound) || (xbound && xonly) || (ybound && yonly)
  44.   return ret
  45. end
  46.  
  47. #=============================================================================
  48. # Ranges
  49. #=============================================================================
  50.  
  51. #pbRange returns true if the player is within a number of tiles from the event.
  52. #xonly will only check horizontally
  53. #yonly will only check vertically
  54.  
  55.  
  56. def pbRange(limit,xonly=false,yonly=false,event=@event_id)
  57.   event=$game_map.events[event] if event.is_a?(Integer)
  58.   ret = false
  59.   leftlimit = event.x - limit
  60.   rightlimit = event.x + limit + event.width - 1
  61.   downlimit = event.y + limit
  62.   uplimit = event.y - limit - event.height + 1
  63.   xbound = $game_player.x.between?(leftlimit,rightlimit)
  64.   ybound = $game_player.y.between?(uplimit,downlimit)
  65.   ret = true if (xbound && ybound) || (xbound && xonly) || (ybound && yonly)
  66.   return ret
  67. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement