Event_Listener API Version: 0.1
By: avarisc
Introduction
Event_Listener API is a tool for script developers.
It provides an extremely simple way to have your script react to triggers in game, without having to alias or any of that hackish stuff. In addition, any script that uses this API as its only point of access to RM will automatically work for any RPG Maker, as the Event_Listener script itself supports any of the current makers (XP, VX, or Ace), and the API itself is the same for all versions.
This is an example of the technique, and is easily expandable.
Features
Screenshots
It does absolutely nothing by itself, and therefore screenshots cannot possibly be relevant.
Demo
There is no use for a demo - this is a plug-n-play script that does nothing by itself.
Script
Instructions
Using the script was designed to be absolutely simple as it could be. Simply declare a new class, and have it extend Event_Listener.
E.g. My_Listener < Event_Listener
That line alone is all you need for your listener to receive events. To react to an event, define a class function with the name of the event you would like to react to.
E.g. def self.on_new_game *Note the "self.", as that is required.
This method in your listener class will be called when the related event has been triggered.
Events:
on_new_game - triggers immediately after a new game has been started
on_show_text - triggers before any event uses the "Show Text" command
A demo script that utilizes the Event_Listener API:
That's actually everything you need - those functions will automatically be called at the appropriate times. Obviously, you could rename My_Listener to anything you like.
FAQ
Q: That's not enough events.
A: And that's not a question. I'll be adding more as time permits, in the mean time, please suggest some events you'd like to use! I take suggestions seriously.
Q: What about modifying or cancelling an event?
A: These are features I am considering, but it would cause compatibility issues between this and other scripts, as I would have to modify a great number of methods throughout RGSS to implement modifiable and cancellable events.
Compatibility
As it stands, this should be pretty much universally compatible. The only part of RGSS it actually touches directly is done via single aliasing, and is already set up to be cross compatible between all RPG Maker versions.
Credits and Thanks
Thanks to the HBGames community for challenging me to become a better developer. (I miss those days. :blush
Author's Notes
I know the first version feels a bit premature. I was going to post it in WIP, but it is technically a release. It's documented, functional, and as far as I can tell, bug free. So I decided to promote it to a full release- at version 0.1.
I look forward to growing it, but I'd like some involvement from the community to help shape its future. Let me know what you would like to see.
Change Log
Future Plans
Future plans have been dismissed in favor of my RGSS replacement. This is being left intact as it is a simple demonstration script of how to achieve the core functionality of an event listener.
Terms and Conditions
This work is licensed under a Creative Commons Attribution 3.0 License.
Attribute to: avarisc (http://www.avarisc.com/)
By: avarisc
Introduction
Event_Listener API is a tool for script developers.
It provides an extremely simple way to have your script react to triggers in game, without having to alias or any of that hackish stuff. In addition, any script that uses this API as its only point of access to RM will automatically work for any RPG Maker, as the Event_Listener script itself supports any of the current makers (XP, VX, or Ace), and the API itself is the same for all versions.
This is an example of the technique, and is easily expandable.
Features
- Provides a "maker-independant" way to hook your script to RGSS
- Extremely easy to use
- I actually observed the 80 character line limit against my inner grumblings
Screenshots
It does absolutely nothing by itself, and therefore screenshots cannot possibly be relevant.
Demo
There is no use for a demo - this is a plug-n-play script that does nothing by itself.
Script
Code:
#==============================================================================
# ** Event_Listener v0.1 by avarisc
#------------------------------------------------------------------------------
# This script allows easier integration of scripts without endangering the
# stack limit. It eliminates the need for aliasing, and provides an API
# that is independent of RGSS version (so scripts written using this API as
# an exclusive point of access to RGSS will work across all RPG Maker engines.
#------------------------------------------------------------------------------
# * Usage
# Using the script was designed to be absolutely simple as it could be.
# Simple declare a new class, and have it extend Event_Listener.
#
# E.g. My_Listener < Event_Listener
#
# That line alone is all you need for your listener to receive events.
# To react to an event, define a class function with the name of the event
# you would like to react to.
#
# E.g. def self.on_new_game *Note the "self.", as that is required.
#
# This method in your listener class will be called when the related event
# has been triggered. Keep reading for a list of events.
#------------------------------------------------------------------------------
# * Events
# on_new_game - triggers immediately after a new game has been started
# on_show_text - triggers before any event uses the "Show Text" command
#==============================================================================
class Event_Listener
#--------------------------------------------------------------------------
# * Class Variables
#--------------------------------------------------------------------------
# rgssv - stores the version of RGSS currently in use
@@rgssv = defined?(Graphics.play_movie)?3:defined?(Graphics.brightness)?2:1
# decs - populates at first request for descendants of Event_Listener
@@decs = 0
#--------------------------------------------------------------------------
# * Accessor Method for RGSS Version
# Simply returns a number, 1, 2, or 3, that describes the current RGSS #.
#--------------------------------------------------------------------------
def self.rgssv
@@rgssv
end
#--------------------------------------------------------------------------
# * Accessor / Auto-populator for Descendant Class List
# This returns the cached descendant list once its populated. If it's not
# populated, this populates it. It's important that we populate this array
# on use, rather than on declaration, as descendants have to be defined
# after this script in the script list (and wouldn't get picked up at the
# time of this class' definition).
#--------------------------------------------------------------------------
def self.descendants
return @@decs if(@@decs != 0)
@@decs = []
ObjectSpace.each_object(::Class) {|klass| @@decs << klass if klass < self }
@@decs
end
#--------------------------------------------------------------------------
# * Send Event
# Parameter: Descendant function name as string
# Simply calls class.send(string) to call the event function in descendants
#--------------------------------------------------------------------------
def self.send_event(event)
descendants.each { |c| c.send(event) }
end
#--------------------------------------------------------------------------
# * Dummy Event Fallbacks
# These do nothing at all, and exist so that classes don't have to utilize
# each and every event - omissions will redirect to the parent class (here)
#--------------------------------------------------------------------------
def self.on_new_game() end
def self.on_show_text() end
end
#==============================================================================
if(Event_Listener.rgssv == 1) ################## * RGSS1 EVENT HOOKS
#==============================================================================
class Interpreter
alias_method(:event_listener_command_101, :command_101)
def command_101
Event_Listener.send_event("on_show_text")
event_listener_command_101
end
end
#==============================================================================
else ########################################### * RGSS(2 OR 3) EVENT HOOKS
#==============================================================================
class Game_Interpreter
alias_method(:event_listener_command_101, :command_101)
def command_101
Event_Listener.send_event("on_show_text")
event_listener_command_101
end
end
#==============================================================================
end; if(Event_Listener.rgssv == 2) ############# * RGSS2 EVENT HOOKS
#==============================================================================
#==============================================================================
elsif(Event_Listener.rgssv == 3) ############### * RGSS3 EVENT HOOKS
#==============================================================================
#==============================================================================
end ############################################ * ANY RGSS VERSION EVENT HOOKS
#==============================================================================
class Scene_Title
alias_method(:event_listener_command_new_game, :command_new_game)
def command_new_game
event_listener_command_new_game
Event_Listener.send_event("on_new_game")
end
end
Instructions
Using the script was designed to be absolutely simple as it could be. Simply declare a new class, and have it extend Event_Listener.
E.g. My_Listener < Event_Listener
That line alone is all you need for your listener to receive events. To react to an event, define a class function with the name of the event you would like to react to.
E.g. def self.on_new_game *Note the "self.", as that is required.
This method in your listener class will be called when the related event has been triggered.
Events:
on_new_game - triggers immediately after a new game has been started
on_show_text - triggers before any event uses the "Show Text" command
A demo script that utilizes the Event_Listener API:
Code:
class My_Listener < Event_Listener
def self.on_new_game
p "on_new_game"
end
def self.on_show_text
p "on_show_text"
end
end
FAQ
Q: That's not enough events.
A: And that's not a question. I'll be adding more as time permits, in the mean time, please suggest some events you'd like to use! I take suggestions seriously.
Q: What about modifying or cancelling an event?
A: These are features I am considering, but it would cause compatibility issues between this and other scripts, as I would have to modify a great number of methods throughout RGSS to implement modifiable and cancellable events.
Compatibility
As it stands, this should be pretty much universally compatible. The only part of RGSS it actually touches directly is done via single aliasing, and is already set up to be cross compatible between all RPG Maker versions.
Credits and Thanks
Thanks to the HBGames community for challenging me to become a better developer. (I miss those days. :blush
Author's Notes
I know the first version feels a bit premature. I was going to post it in WIP, but it is technically a release. It's documented, functional, and as far as I can tell, bug free. So I decided to promote it to a full release- at version 0.1.
I look forward to growing it, but I'd like some involvement from the community to help shape its future. Let me know what you would like to see.
Change Log
Code:
v0.1----------------------
Released
Added on_new_game
Added on_show_text
Future Plans
Future plans have been dismissed in favor of my RGSS replacement. This is being left intact as it is a simple demonstration script of how to achieve the core functionality of an event listener.
Terms and Conditions

This work is licensed under a Creative Commons Attribution 3.0 License.
Attribute to: avarisc (http://www.avarisc.com/)