Advertisement
ForeverZer0

[RMXP] Custom Event Triggers 1.1

May 21st, 2011
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 3.59 KB | None | 0 0
  1. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  2. # Custom Event Triggers
  3. # Author: ForeverZer0
  4. # Version: 1.1
  5. # Date: 10.13.2010
  6. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  7. #                              VERSION HISTORY
  8. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  9. # v.1.0  7.14.2010
  10. #   - Original release
  11. # v.1.1  10.13.2010
  12. #   - Shortened and made more efficient. Added comments.
  13. #   - Eliminated bug and removed an unnecessary Regular Expression.
  14. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  15. #
  16. # Explanation:
  17. #
  18. #   Allows you to easily create custom triggers for events. Uses simple comment
  19. #   code in their event page to create a new trigger. If trigger evaluates as
  20. #   'true', their code will execute. Work differently than conditions, since the
  21. #   page conditions must still be met and they are what actually what begin
  22. #   execution of the event commands for that page.
  23. #
  24. # Instructions:
  25. #
  26. #   - Very simple. Make a comment at the TOP of the page you want the custom
  27. #     trigger to execute that simply reads "Custom Trigger". Now in the same
  28. #     comment on the next line, or in another comment directly below the first,
  29. #     simply write the a scripted true/false statement. If this line ever results
  30. #     in a true statement, and the page conditions are met, the page will execute
  31. #     its commands.  
  32. #   - You can use as many comment boxes you need to script the trigger, but they
  33. #     must be consecutive and immediately after the "Custom Trigger" comment. Do
  34. #     not use an arbitrary comment right after these comments, else the game will
  35. #     attempt to include them in the trigger.
  36. #   - This will also disable all other triggers for this page.
  37. #
  38. #     Here's an example:
  39. #
  40. #     Comment: Custom Trigger
  41. #            : Input.press?(Input::L) && Input.press?(Input::R) &&
  42. #            : Input.trigger?(Input::C)
  43. #
  44. #   This will execute the event if the C button is pressed while the L and R
  45. #   buttons are being held down (if page conditions are met).
  46. #
  47. #     Another example:
  48. #
  49. #     Comment: Custom Trigger
  50. #            : $game_party.steps == 23423
  51. #
  52. #   This executes if the party step count is equal to 23423.
  53. #
  54. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  55.  
  56. #===============================================================================
  57. # ** Game_Event
  58. #===============================================================================
  59.  
  60. class Game_Event
  61.  
  62.   attr_accessor :trigger
  63.  
  64.   alias zer0_custom_trigger_refresh refresh
  65.   def refresh
  66.     # Normal refresh method.
  67.     zer0_custom_trigger_refresh
  68.     # Search top of current page for the string "Custom Trigger".
  69.     if @page != nil && @page.list[0].code == 108 &&
  70.       @page.list[0].parameters[0] == 'Custom Trigger'
  71.       trigger, list_index = '', 1
  72.       # If found, loop until the next command is not a comment, adding each line
  73.       # of the comments into a single string.
  74.       while [108, 408].include?(@page.list[list_index].code)
  75.         trigger += @page.list[list_index].parameters[0] + ' '
  76.         list_index += 1
  77.       end
  78.       # Set event trigger to -1, which no method exists for by default.
  79.       @custom_trigger, @trigger = trigger, -1
  80.     end
  81.   end
  82.  
  83.   alias zer0_custom_trigger_upd update
  84.   def update
  85.     zer0_custom_trigger_upd
  86.     # If trigger is -1, and the created string evaluates as true, start event.
  87.     if @trigger == -1 && !@erased && eval(@custom_trigger)
  88.       start
  89.     end
  90.   end
  91. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement