=begin
===============================================================================
Enemy Event Trigger Condition Checking Ver. 1.01
- By KK20 [10/26/12]
===============================================================================
[ Updates ]
Version:
1.01 [10/26/12]
- There was an issue with running events when enemies died
===============================================================================
[Information]
Blizzard ABS allows the creator to make event triggers for map battlers. It
was possible for players to allow multiple triggers for one event page,
meaning that the events would run if any ONE of those triggers was satisfied.
With this script, the creator can now make conditional branches for each
trigger.
[Example]
The event can be triggered via ActionButton and Weapon. If player presses
ActionButton, the event will say "Hi." If the player attacks with his weapon,
the event says "Ouch!"
-------------------------------------------------------------------------------
[How to Use]
Create triggers as you would normally (at the top of the event list as a
comment line--read the BlizzABS manual for details). In a conditional branch,
use the 'Script' option. Then, type this line:
$game_map.events[@SELF].triggered?(trigger_id, object_id)
>> trigger_id : The ID of the trigger type (i.e. CETPlayerTouch, CETWeapon)
[[** NOTE **]]
If you want to learn more of the types of triggers, refer to the manual.
Also, it is MANDATORY to add this code before the trigger variable:
BlizzABS::
>> object_id : The ID of the object (i.e weapon ID, skill ID, item ID)
[[** NOTE **]]
This parameter is 'nil' by default. Thus, this parameter can be entirely
skipped. Only specify a value if necessary.
[Examples of Usage]
$game_map.events[@SELF].triggered?(BlizzABS::CETActionButton)
=> If the player pressed the ActionButton to trigger the event
$game_map.events[@SELF].triggered?(BlizzABS::CETWeapon, 5)
=> If the player attacked with the weapon of ID 5
$game_map.events[@SELF].triggered?(BlizzABS::CETSkill)
=> If the player attacked with any skill
===============================================================================
Credits
KK20 : Creating this script edit
Blizzard : So that you can use this script in BlizzABS (duh :P)
Sin86 : For the idea and bug report
===============================================================================
=end
class Map_Enemy < Map_Battler
#----------------------------------------------------------------------------
# triggered?
# trigger_id : The ID of the trigger type (i.e. CETPlayerTouch, CETWeapon)
# object_id : The ID of the object (i.e weapon ID, skill ID, item ID)
# Returns if the event was triggered by a certain trigger.
#----------------------------------------------------------------------------
def triggered?(trigger_id, object_id = nil)
return (@event_trigger[0] == trigger_id) if object_id.nil?
return @event_trigger == [trigger_id, object_id]
end
#----------------------------------------------------------------------------
# Initialization
# ** Initialize variable 'event_trigger'
#----------------------------------------------------------------------------
alias init_map_enemy_after initialize
def initialize(map_id, event, id = 0, group = 0, attributes = 0x00,
move = false, immortal = false, full_passable = false,
custom = false, delay = 40, view = 5, hear = 40, nojump = false)
@event_trigger = [-1, -1]
init_map_enemy_after(map_id, event, id, group, attributes,
move, immortal, full_passable,
custom, delay, view, hear, nojump)
end
#----------------------------------------------------------------------------
# start
# Setups the starting event code.
# ** Removed the line -> @trigger = 1 **
#----------------------------------------------------------------------------
def start
# if event code exists
return if @list.size <= 1
# set starting and execution flag
@starting = @execute = true
end
#----------------------------------------------------------------------------
# event_execution?
# Tests if the enemy died and is executing an event now.
# ** Added @event_trigger = [-1, -1] **
#----------------------------------------------------------------------------
def event_execution?
# stop if not executing
return false if !@execute
# if about to start or running already
if @starting || $game_system.map_interpreter.running?
# reset blending type
@blend_type = 0 if @starting
# reset moving route
@force_move = []
# executing event
return true
end
# if enemy revived with event command
if valid? && !battler.dead?
# reset opacity
@opacity = 255
# reset blending type
@blend_type = 0
# reset execute flag
@execute = false
# recreate data pack for new enemy
@ai = BlizzABS::AI::Data_Enemy.new(self, @ai.group, @ai.attributes,
@ai.custom, @ai.delay_time, @ai.view_range, @ai.hearing_range_ratio)
# reset moving route
@force_move = []
# if opacity is 0
elsif (!valid? || battler.dead?) && @opacity == 0
# set execute flag and erased flag
@execute, @erased = false, true
# refresh
refresh
end
@event_trigger = [-1, -1]
# not executing event
return false
end
#----------------------------------------------------------------------------
# attack_effect
# character - the character that holds attack data (can be projectile)
# _battler - the attacking battler
# Executes attack upon a map character.
#----------------------------------------------------------------------------
def attack_effect(character, _battler)
# call superclass method
result = super
# if actor
if _battler.is_a?(Game_Actor)
# get weapon ID and custom event trigger type
id, cet = _battler.weapon_id, BlizzABS::CETWeapon
# if enemy
elsif _battler.is_a?(Game_Enemy)
# get weapon ID and custom event trigger type
id, cet = _battler.id, BlizzABS::CETEnemy
end
# if can be activated by this weapon / enemy
if result && @custom_triggers.has_key?(cet) &&
(@custom_triggers[cet].size == 0 ||
@custom_triggers[cet].include?(id))
# run this enemy as event
@event_trigger = [cet, id]
self.start
end
# return result
return result
end
#----------------------------------------------------------------------------
# skill_effect
# character - the character that holds skill use (can be projectile)
# _battler - the skill using battler
# skill - the skill
# Executes skill use upon a map character.
#----------------------------------------------------------------------------
def skill_effect(character, _battler, skill)
# call superclass method
result = super
# if can be activated by this skill
if result && @custom_triggers.has_key?(BlizzABS::CETSkill) &&
(@custom_triggers[BlizzABS::CETSkill].size == 0 ||
@custom_triggers[BlizzABS::CETSkill].include?(skill.id))
# run this enemy as event
@event_trigger = [BlizzABS::CETSkill, id]
self.start
end
# return result
return result
end
#----------------------------------------------------------------------------
# item_effect
# character - the character that holds item use (can be projectile)
# item - the item
# Executes item use upon a map character.
#----------------------------------------------------------------------------
def item_effect(character, _battler, item)
# call superclass method
result = super
# if can be activated by this item
if result && @custom_triggers.has_key?(BlizzABS::CETItem) &&
(@custom_triggers[BlizzABS::CETItem].size == 0 ||
@custom_triggers[BlizzABS::CETItem].include?(item.id))
# run this enemy as event
@event_trigger = [BlizzABS::CETItem, id]
self.start
end
# return result
return result
end
#----------------------------------------------------------------------------
# check_event_trigger_touch
# x - x-coordinate
# y - y-coordinate
# Checks event touching. Called when event moves into player.
#----------------------------------------------------------------------------
def check_event_trigger_touch(x, y)
# get pixel movement rate
pix = $BlizzABS.pixel
# stop if an event is being executed already
return false if $game_system.map_interpreter.running?
# if any battler in the way
if @trigger == BlizzABS::CETEventTouch && !jumping? && !over_trigger? &&
!$game_player.through && $game_player.character_name != '' &&
$BlizzABS.util.rect_intersection(Rect.new(x, y, pix, pix),
Rect.new($game_player.x, $game_player.y, pix, pix))
# start
@event_trigger = [BlizzABS::CETEventTouch, id]
start
# started
return true
end
# not started
return false
end
#----------------------------------------------------------------------------
# check_event_trigger_at
# x - x-coordinate
# y - y-coordinate
# Check event if it was triggered at a specific position. (pixel movement)
# Called when player presses action button or walks into event.
#----------------------------------------------------------------------------
def check_event_trigger_at(x, y)
# get pixel movement rate
pix = $BlizzABS.pixel
# if player touched this event and not jumping and not over_trigger
if !jumping? && !over_trigger? && $BlizzABS.util.rect_intersection(
Rect.new(@x, @y, pix, pix), Rect.new(x, y, pix, pix))
# start
@event_trigger = Input.trigger?(Input::C) ? [BlizzABS::CETActionButton, -1] : [BlizzABS::CETPlayerTouch, -1]
start
# started
return true
end
# not started
return false
end
end
#==============================================================================
# ** Interpreter
#------------------------------------------------------------------------------
# This interpreter runs event commands. This class is used within the
# Game_System class and the Game_Event class.
#==============================================================================
class Interpreter
#--------------------------------------------------------------------------
# * Starting Event Setup
# Editted 'if event.trigger < 3' to be '!= 3'
#--------------------------------------------------------------------------
def setup_starting_event
# Refresh map if necessary
if $game_map.need_refresh
$game_map.refresh
end
# If common event call is reserved
if $game_temp.common_event_id > 0
# Set up event
setup($data_common_events[$game_temp.common_event_id].list, 0)
# Release reservation
$game_temp.common_event_id = 0
return
end
# Loop (map events)
for event in $game_map.events.values
# If running event is found
if event.starting
# If not auto run
if event.trigger != 3 # if event.trigger < 3
# Clear starting flag
event.clear_starting
# Lock
event.lock
end
# Set up event
setup(event.list, event.id)
return
end
end
# Loop (common events)
for common_event in $data_common_events.compact
# If trigger is auto run, and condition switch is ON
if common_event.trigger == 1 and
$game_switches[common_event.switch_id] == true
# Set up event
setup(common_event.list, 0)
return
end
end
end
end