Event Wrapper
-Tsukihime
Overview
This script provides a wrapper for the RPG::Event object. It adds additional methods to allow you to create event commands directly without having to go through the event editor, and provides intuitive names that are based on the command names available on the event editor.
This is mainly a scripting tool, and is not intended to replace the event editor.
If something can be achieved using the event editor, use it.
Features
Downloads
Script: http://db.tt/QiaEiAN2
Demo: http://db.tt/TavscwIB
If you are not sure where to start, I've provided some examples in the demo.
Usage
Currently, your scripted events are just scripts, so they are not very accessible. You must have an event on the map to be able to use a script call to create more events, though after that your custom events can create their own events provided that you've written the logic into their command list.
You can choose to write methods in Game_Interpreter or just a custom module. As long as you can call the methods that will create the event.
Creating an event is simple.
1. Instantiate an Event object, passing in x,y coordinates
2. Set some page properties. For a list of properties, refer to the help manual, or look through the Event class. You can either access the properties directly, or use some convenience methods defined in the Event class. So for example, assuming we are on page 0,
Both do the same thing.
Some common properties you might set are
Note that the convenience methods always operate on the "current" page.
When you first initialize a new event, the "current" page is 0.
You can change the page by calling
For some integer n. Thus, you may want to work on one page a time, as such:
3. Set some page conditions. Refer to the Event_Condition class for details.
4. Add the event to the map
That should create an event on the map at the designated x,y coords when we make a script call to create this event, but it's not very useful. We want to add some event commands.
I've provided an "Event Builder" that allows you to use a custom syntax to create your events in addition to regular ruby syntax.
I have written a set of methods that essentially alias Game_Interpreter methods, except instead of using command codes, I use the common editor names to identify what the command is. All of the methods are available in the EventCommands class. So for example, let's write an event that will display a simple message
When you create this event, you can talk to it and it will say "Hello World"
Note that `add_message` can take multiple strings. Each string will be treated as a new line.
The event builder supports branching, which is used in various commands such as showing a list of choices, conditional branching, and other things.
This example demonstrates how to using branching to create a list of choices that the player can select from, and how to define the commands that should be executed depending on the choice.
Naturally, you can provide an unlimited number of branches, though the choice window is not designed for that (meaning, you might have choices that are drawn outside the screen if there are just too many)
It is also possible to use typical ruby syntax when building your commands.
You know, take advantage of loops and variables.
This example demonstrates how you would write an event that will go through all of the actors in your party, display their names in a choice list, and then when you select an actor, it will display information about the actor in a text box.
However, note that because this code is run only when the event is created, the event commands have already been hardcoded into the event. It is no different from manually creating an event and writing your own choice branches and such.
One of the goals of this script is to eventually allow you to create completely dynamic events whose commands may change at any time.
I am currently working on a way for you to specify that an event should be "rebuilt" everytime you enter the map, or your refresh the event. By rebuilding the event, you are basically clearing out the command list and re-running the script, which will correctly reflect the current state of the game.
Reference
The objects of interest are
RPG::Event
RPG::Event:
age
RPG::Event:
age::Condition
RPG::Event:
age::Graphic
RPG::EventCommand
RPG::MoveRoute
RPG::MoveCommand
All of these are described in the help manual under RGSS Reference Manual -> Game Library -> RPGVXAce Data Structures.
-Tsukihime
Overview
This script provides a wrapper for the RPG::Event object. It adds additional methods to allow you to create event commands directly without having to go through the event editor, and provides intuitive names that are based on the command names available on the event editor.
This is mainly a scripting tool, and is not intended to replace the event editor.
If something can be achieved using the event editor, use it.
Features
- Easily create events using scripts
- An Event Builder that helps you create your list of command events
- Use the Event Builder to mix scripting with event commands to create all sorts of event processing
- Create move routes using a Move Builder, using the same syntax as the Event Builder with intuitive move commands and some custom move commands for convenience (eg: move strings)
Downloads
Script: http://db.tt/QiaEiAN2
Demo: http://db.tt/TavscwIB
If you are not sure where to start, I've provided some examples in the demo.
Usage
Currently, your scripted events are just scripts, so they are not very accessible. You must have an event on the map to be able to use a script call to create more events, though after that your custom events can create their own events provided that you've written the logic into their command list.
You can choose to write methods in Game_Interpreter or just a custom module. As long as you can call the methods that will create the event.
Code:
class Game_Interpreter
def make_my_event
# your event building code
end
end
Creating an event is simple.
1. Instantiate an Event object, passing in x,y coordinates
Code:
event = Event.new(2, 4)
Code:
event.page[0].character_name = "actor1"
event.character_name = "actor1"
Some common properties you might set are
Code:
event.priority_type = 1 # 1 is "same as characters". You can choose 0, 1, or 2
event.trigger = 2 # 2 is "event touch". It goes from 0 to 4, same order as in the editor
event.direction_fix = true
When you first initialize a new event, the "current" page is 0.
You can change the page by calling
Code:
event.set_page(n)
Code:
event.set_page(0)
#do stuff for page 0
event.set_page(1)
# do stuff for page 1
event.set_page(2)
# do stuff for page 2
Code:
event.condition.switch1_id = 2 # this means switch 2 must be ON
event.condition.switch2_id = 3 # remember that the event supports two switches
event.condition.actor_id = 4 # actor 4 must be in party
Code:
$game_map.add_event(event)
I've provided an "Event Builder" that allows you to use a custom syntax to create your events in addition to regular ruby syntax.
I have written a set of methods that essentially alias Game_Interpreter methods, except instead of using command codes, I use the common editor names to identify what the command is. All of the methods are available in the EventCommands class. So for example, let's write an event that will display a simple message
Code:
event = Event.new(3, 3)
event.character_name = "actor1"
event.character_index = 2
event.build {
show_text("actor1", 2)
add_message("Hello World")
}
$game_map.add_event(event)
Note that `add_message` can take multiple strings. Each string will be treated as a new line.
Code:
event.build {
show_text("actor1", 2)
add_message("Hello World", "Goodbye")
}
Code:
event.build {
show_text("actor1", 1)
add_message("What do you like?")
show_choices(["Health", "Mana"], 0)
choice_branch(0) {
show_text("actor1", 1)
add_message("So you prefer health")
}
choice_branch(1) {
show_text("actor1", 1)
add_message("Mana is ok too")
}
}
Naturally, you can provide an unlimited number of branches, though the choice window is not designed for that (meaning, you might have choices that are drawn outside the screen if there are just too many)
It is also possible to use typical ruby syntax when building your commands.
You know, take advantage of loops and variables.
Code:
event = Event.new(x, y)
event.character_name = "actor2"
event.character_index = 5
event.build {
show_text("actor2", 5)
add_message("Which party member do you wish to view?")
actors = $game_party.members.collect {|actor| actor.name }
show_choices(actors, 0)
$game_party.members.each_with_index { |actor, i|
choice_branch(i) {
show_text(actor.face_name, actor.face_index)
add_message("%s is a level %d %s" %[actor.name, actor.level, actor.class.name])
}
}
}
$game_map.add_event(event)
However, note that because this code is run only when the event is created, the event commands have already been hardcoded into the event. It is no different from manually creating an event and writing your own choice branches and such.
One of the goals of this script is to eventually allow you to create completely dynamic events whose commands may change at any time.
I am currently working on a way for you to specify that an event should be "rebuilt" everytime you enter the map, or your refresh the event. By rebuilding the event, you are basically clearing out the command list and re-running the script, which will correctly reflect the current state of the game.
Reference
The objects of interest are
RPG::Event
RPG::Event:
RPG::Event:
RPG::Event:
RPG::EventCommand
RPG::MoveRoute
RPG::MoveCommand
All of these are described in the help manual under RGSS Reference Manual -> Game Library -> RPGVXAce Data Structures.
Last edited by a moderator:

