Home > RGSS Script Reference > Game_Event
Game_Event
Inherits from: Game_Character
Description: This class contains information about a map event, as well as methods to check if an event has been triggered.
class Game_Event < Game_Character
# ------------------------------------
attr_reader :trigger
attr_reader :list
attr_reader :starting
# ------------------------------------
def initialize(map_id, event)
super()
@map_id = map_id
@event = event
@id = @event.id
@erased = false
@starting = false
moveto(@event.x, @event.y)
refresh
end
# ------------------------------------
def clear_starting
@starting = false
end
# ------------------------------------
def over_trigger?
if @character_name != "" and not @through
return false
end
unless $game_map.passable?(@x, @y, 0)
return false
end
return true
end
# ------------------------------------
def start
if @list.size > 1
@starting = true
end
end
# ------------------------------------
def erase
@erased = true
refresh
end
# ------------------------------------
def refresh
new_page = nil
unless @erased
for page in @event.pages.reverse
c = page.condition
if c.switch1_valid
if $game_switches[c.switch1_id] == false
next
end
end
if c.switch2_valid
if $game_switches[c.switch2_id] == false
next
end
end
if c.variable_valid
if $game_variables[c.variable_id] < c.variable_value
next
end
end
if c.self_switch_valid
key = [@map_id, @event.id, c.self_switch_ch]
if $game_self_switches[key] != true
next
end
end
new_page = page
break
end
end
if new_page == @page
return
end
@page = new_page
clear_starting
if @page == nil
@tile_id = 0
@character_name = ""
@character_hue = 0
@move_type = 0
@trigger = nil
@list = nil
@interpreter = nil
return
end
@tile_id = @page.graphic.tile_id
@character_name = @page.graphic.character_name
@character_hue = @page.graphic.character_hue
if @original_direction != @page.graphic.direction
@direction = @page.graphic.direction
@original_direction = @direction
@prelock_direction = 0
end
if @original_pattern != @page.graphic.pattern
@pattern = @page.graphic.pattern
@original_pattern = @pattern
end
@opacity = @page.graphic.opacity
@blend_type = @page.graphic.blend_type
@move_type = @page.move_type
@move_speed = @page.move_speed
@move_frequency = @page.move_frequency
@move_route = @page.move_route
@move_route_index = 0
@move_route_forcing = false
@walk_anime = @page.walk_anime
@step_anime = @page.step_anime
@direction_fix = @page.direction_fix
@through = @page.through
@always_on_top = @page.always_on_top
@trigger = @page.trigger
@list = @page.list
@interpreter = nil
if @trigger == 4
@interpreter = Interpreter.new
end
check_event_trigger_auto
end
# ------------------------------------
def check_event_trigger_touch(x, y)
if $game_system.map_interpreter.running?
return
end
if @trigger == 2 and x == $game_player.x and y == $game_player.y
unless over_trigger?
start
end
end
end
# ------------------------------------
def check_event_trigger_auto
if @trigger == 2
if @x == $game_player.x and @y == $game_player.y and over_trigger?
start
end
end
if @trigger == 3
start
end
end
# ------------------------------------
def update
super
check_event_trigger_auto
if @interpreter != nil
unless @interpreter.running?
@interpreter.setup(@list, @event.id)
end
@interpreter.update
end
end
end
|
Trigger: The event's trigger (0 = Action Key, 1 = Hero Touch, 2 = Collision with Hero, 3 = Auto-Start, 4 = Parallel Process).
List: The list of event commands for the event.
Starting: This flag is set if the event has been triggered.
Map_ID: The ID of the current map.
Event: An RPG::Event object representing the event.
ID: The ID number of the event on the map.
Erased: This flag is set if the event has been erased by the "Erase Event" command.
Interpreter: The interpreter object associated with the event.
Initialize
Arguments:
Map_ID: The ID of the current map.
Event: The event object.
Local Variables: None
How it Works: Set up the event on the map. The moveto(@event.x, @event.y) statement moves the event to its initial location on the map.
Clear_Starting
Arguments: None
Local Variables: None
How it Works: This method sets the event's @starting flag to false.
Over_Trigger?
Arguments: None
Local Variables: None
How it Works: This method decides if an event should be triggered because the hero is standing on the same tile as the event. This is possible if either the event in question is a transparent event, or it has the "Phasing" property. The if @character_name != "" and not @through statement checks to see if the event is both non-transparent and not Phasing. If it is, then the method returns false. The method next checks to see if the tile on which it is standing is passable. If it isn't, then the event won't be triggered. Otherwise, the event is triggered.
Start
Arguments: None
Local Variables: None
How it Works: This method sets the event's @starting flag as long as there is at least one event command in its command list.
Erase
Arguments: None
Local Variables: None
How it Works: This method sets the event's @erased flag and then refreshes the event's state.
Refresh
Arguments: None
Local Variables:
New_Page: The new page to activate. If there are multiple pages in the event for which the preconditions have been met, the highest-numbered page takes precedence.
How it Works: This method refreshes the event's state, changing its graphic and event settings if a new page has been activated. If the new page is a parallel process event, this method also sets up the interpreter object. The value of new_page is set to nil. If the event's @erased flag is set, the next part of the method is skipped. Otherwise, the for page in @event.pages.reverse clause checks the preconditions for each event page in order, starting with the highest-numbered page. The two switch conditions are checked first, then the variable, then the local switch. If any of these checks fail, the next statement jumps to the next iteration of the loop. The new_page == @page clause checks to see if the new page is equal to the current page. If it is, then the method returns without doing anything. Otherwise, the value of @page is updated to reflect the new page. If this new value is nil (that is, either the event has been erased or every page in the event has preconditions that have not been met), then the event's state is "blanked out". Otherwise, the event's graphic, hue, direction, trigger, move speed/frequency, flags, and event list are updated to reflect the new page's settings. The final part of the method checks to see if the event's @trigger value is 4 (Parallel Process). If it is, then the method sets up the event's @interpreter object to begin running. The call to check_event_trigger_auto checks to see if the event should be automatically started because it appeared directly under the hero and has the "Collision with Hero" trigger, or has the "Auto-Start" trigger.
Check_Event_Trigger_Touch
Arguments:
X: The event's X coordinate in tiles.
Y: The event's Y coordinate in tiles.
Local Variables: None
How it Works: This method checks to see if an event with the "Collision with Hero" trigger should start. The method first checks to see if an interpreter is running. If one is, then the method returns without doing any further processing. Otherwise, it checks to see if the event's X and Y coordinates are equal to those of the hero. If they are, and the requirements for over_trigger? are not met, then the event is triggered and its starting flag is set.
Check_Event_Trigger_Auto
Arguments: None
Local Variables: None
How it Works: This method decides if an event should start automatically due to either being an event with the "Auto-Start" trigger, or having the "Collision with Hero" property and being on the same tile as the player due to either being a transparent event or having the "Phasing" property. The first if statement checks to see if the event trigger is 2 (Collision with Hero) and the event's X and Y coordinates match up with the hero's. If they do and the requirements for over_trigger? are met, then the event's starting flag is set. Otherwise, the method goes on to the next check. If the event's trigger is 3 (Auto-Start), its starting flag is set.
Update
Arguments: None
Local Variables: None
How it Works: This method updates the frame with respect to the event. The method first calls Game_Character#update in order to deal with any graphical effects a change in the event's state might have caused. It then checks to see if any new Auto-Start events have been triggered. The if @interpreter != nil clause deals with events with the "Parallel Process" trigger that have finished executing. If the event's interpreter is not running, the event is executed again from the beginning.
|
|