Custom Event Triggers

Custom Event Triggers Version: 1.1
By: ForeverZer0

Introduction

Allows you to easily create custom triggers for events. Uses simple commentcode in their event page to create a new trigger. If trigger evaluates as 'true', their code will execute. Work differently than conditions, since the page conditions must still be met and they are what actually what begin execution of the event commands for that page.

Features
  • Very easy to use (requires very simple script statements)
  • Can use ABSOLUTELY anything to trigger an event.
  • No longer confined to the few basic triggers.

Screenshots

None.

Script

  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
Expand to see the code.


Instructions

See script. Even if you have no scripting experience, you can will likely still be able to create the triggers, so do not let that turn you off to the script.

Compatibility

No known compatibility issues.

Author's Notes

Please report any bugs/issues so that they can be resolved. Enjoy!

Terms and Conditions

Creative Commons - Attribution-NonCommercial-ShareAlike 3.0 Unported
Content Hidden Spoiler
You are free:

to Share - to copy, distribute and transmit the work
to Remix - to adapt the work

Under the following conditions:

Attribution. You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work).

Noncommercial. You may not use this work for commercial purposes.

Share alike. If you alter, transform, or build upon this work, you may distribute the resulting work only under the same or similar license to this one.

- For any reuse or distribution, you must make clear to others the license terms of this work. The best way to do this is with a link to this web page.

- Any of the above conditions can be waived if you get permission from the copyright holder.

- Nothing in this license impairs or restricts the author's moral rights.
This is quite a useful addition! Such a simple way to make that extra Conditional Branch unnecessary. Quick question: does this override triggers like "Player Touch", "Autorun", etc.?
Very neat! I'll definitely give this a try. I have the same question as regi though. It says in the script description that it runs when the conditions are met, as well as the page conditions, but at the bottom it says that it will disable all other triggers for the page.
He means if you use a custom trigger, it's going to disable the other triggers for that page. You can still use the default triggers, just not with custom triggers.

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=74936