SHARE
TWEET

[RMXP] Event Range Conditions 1.1

ForeverZer0 May 21st, 2011 261 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  2. # Event Range Conditions
  3. # Author: ForeverZer0
  4. # Date: 5.1.2011
  5. # Version: 1.1
  6. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  7. #
  8. # Explanation:
  9. #
  10. #   Allows you to set up conditional branches in events that will be based off
  11. #   the event's coordinates in relation to the player's coordinates without
  12. #   having to create any variables for the X and Y of each.
  13. #
  14. #   Here are the new features you can use a conditional branch. Just type these
  15. #   into the script box for the branch.
  16. #
  17. #   range?(RANGE, EVENT_ID) - Will be true if player is anywhere in the radius
  18. #                             defined by RANGE from the event with EVENT_ID
  19. #
  20. #   on_screen?(EVENT_ID)    - Will be true if the event with EVENT_ID is within
  21. #                             the visible screen
  22. #
  23. #   x_dist?(DIST, EVENT_ID) - Returns true if the player's x/y is within DIST
  24. #            OR               of event's x/y with EVENT_ID. These are absolute
  25. #   y_dist?(DIST, EVENT_ID)   values, meaning it doesn't matter which direction,
  26. #                             it just uses the total distance in tiles for that
  27. #                             axis. Use a DIST of 0 to check if that axis is
  28. #                             equal.
  29. #
  30. #   player_above?(EVENT_ID) - Returns true when player is above event.
  31. #   player_below?(EVENT_ID) - Returns true when player is below event.
  32. #   player_right?(EVENT_ID) - Returns true when player is right of the event.
  33. #   player_left?(EVENT_ID)  - Returns true when player is left of the event.
  34. #
  35. #   For all of these, if the conditional branch that is using them is within
  36. #   the event that it applies to, you do not have to include the EVENT_ID, it
  37. #   is assumed to be that event's ID unless otherwise defined.
  38. #
  39. #   You can use these as a condition for just about anything, such as having
  40. #   an event say something, run away, or run toward the player if it is within a
  41. #   specific distance, and it's much easier than using multiple branches and
  42. #   game variables to set it up.
  43. #
  44. #   Remember that if you use a range condition with a parallel trigger, it will
  45. #   continue to execute as long as the condition is met and if the player cannot
  46. #   move during the event's code, the game will effectively be stuck.
  47. #
  48. # Compatability:
  49. #
  50. #   - You may encounter issues if using a Pixel Movement script, though it
  51. #     should still work fine with an 8-Way Movement script. (Not tested)
  52. #
  53. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  54.  
  55. class Interpreter
  56.  
  57.   def range?(range = 4, id = @event_id)
  58.     e = $game_map.events[id]
  59.     radius = (Math.hypot((e.x - $game_player.x), (e.y - $game_player.y))).abs
  60.     return (radius <= range)
  61.   end
  62.  
  63.   def on_screen?(id = @event_id)
  64.     x, y = $game_map.events[id].real_x, $game_map.events[id].real_y
  65.     return ((x - $game_map.display_x + 64) / 4).between?(0, 640) &&
  66.       ((y - $game_map.display_y) / 4).between?(0, 480)
  67.   end
  68.  
  69.   def x_dist?(distance = 0, id = @event_id)
  70.     x_dif = ($game_map.events[id].x - $game_player.x).abs
  71.     return (x_dif <= distance)
  72.   end
  73.  
  74.   def y_dist?(distance = 0, id = @event_id)
  75.     y_dif = ($game_map.events[id].y - $game_player.y).abs
  76.     return (y_dif <= distance)
  77.   end
  78.  
  79.   def player_above?(id = @event_id)
  80.     return ($game_map.events[id].y > $game_player.y)
  81.   end
  82.  
  83.   def player_below?(id = @event_id)
  84.     return ($game_map.events[id].y < $game_player.y)
  85.   end
  86.  
  87.   def player_right?(id = @event_id)
  88.     return ($game_map.events[id].x < $game_player.x)
  89.   end
  90.  
  91.   def player_left?(id = @event_id)
  92.     return ($game_map.events[id].x > $game_player.x)
  93.   end
  94. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top