Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

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

[rgss]#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
# Custom Event Triggers
# Author: ForeverZer0
# Version: 1.1
# Date: 10.13.2010
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
#                              VERSION HISTORY
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
# v.1.0  7.14.2010
#   - Original release
# v.1.1  10.13.2010
#   - Shortened and made more efficient. Added comments.
#   - Eliminated bug and removed an unnecessary Regular Expression.
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
#
# Explanation:
#
#   Allows you to easily create custom triggers for events. Uses simple comment
#   code 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.
#
# Instructions:
#
#   - Very simple. Make a comment at the TOP of the page you want the custom
#     trigger to execute that simply reads "Custom Trigger". Now in the same
#     comment on the next line, or in another comment directly below the first,
#     simply write the a scripted true/false statement. If this line ever results
#     in a true statement, and the page conditions are met, the page will execute
#     its commands.  
#   - You can use as many comment boxes you need to script the trigger, but they
#     must be consecutive and immediately after the "Custom Trigger" comment. Do
#     not use an arbitrary comment right after these comments, else the game will
#     attempt to include them in the trigger.
#   - This will also disable all other triggers for this page.
#
#     Here's an example:
#
#     Comment: Custom Trigger
#            : Input.press?(Input::L) && Input.press?(Input::R) &&
#            : Input.trigger?(Input::C)
#
#   This will execute the event if the C button is pressed while the L and R
#   buttons are being held down (if page conditions are met).
#
#     Another example:
#
#     Comment: Custom Trigger
#            : $game_party.steps == 23423
#
#   This executes if the party step count is equal to 23423.
#
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
 
#===============================================================================
# ** Game_Event
#===============================================================================
 
class Game_Event
  
  attr_accessor :trigger
  
  alias zer0_custom_trigger_refresh refresh
  def refresh
    # Normal refresh method.
    zer0_custom_trigger_refresh
    # Search top of current page for the string "Custom Trigger".
    if @page != nil && @page.list[0].code == 108 &&
      @page.list[0].parameters[0] == 'Custom Trigger'
      trigger, list_index = '', 1
      # If found, loop until the next command is not a comment, adding each line
      # of the comments into a single string.
      while [108, 408].include?(@page.list[list_index].code)
        trigger += @page.list[list_index].parameters[0] + ' '
        list_index += 1
      end
      # Set event trigger to -1, which no method exists for by default.
      @custom_trigger, @trigger = trigger, -1
    end
  end
  
  alias zer0_custom_trigger_upd update
  def update
    zer0_custom_trigger_upd
    # If trigger is -1, and the created string evaluates as true, start event.
    if @trigger == -1 && !@erased && eval(@custom_trigger)
      start
    end
  end
end
[/rgss]

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
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.?
 

SPN

Member

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.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top