[XP] Enemy Event Trigger Condition Checking

Started by KK20, August 12, 2012, 04:28:30 am

Previous topic - Next topic

KK20

August 12, 2012, 04:28:30 am Last Edit: August 16, 2018, 05:43:23 pm by KK20
Enemy Event Trigger Condition Checking
Authors: KK20
Version: 1.01
Type: Event Modification
Key Term: Blizz-ABS Plugin



Introduction

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


Features


  • Allows enemy events with multiple custom event triggers to have conditional branches, meaning more diverse event customization

  • No configuration required!




Screenshots
https://www.youtube.com/watch?v=PORaXNi4yiI



Demo

None.


Script

Post below the Blizz-ABS scripts.
Spoiler: ShowHide

=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



Instructions

Details found in the script. Primary script call is
$game_map.events[@SELF].triggered?(trigger_id, object_id)

where 'trigger_id' is the trigger type (BlizzABS::CETActionButton, BlizzABS::CETWeapon, etc.)
      'object_id' is the ID of the item in the database (Weapon ID, Item ID, Skill ID, Enemy ID)


Compatibility

This is for Blizz-ABS, so make sure to have Blizz-ABS!
Written during the time of Blizz-ABS Version 2.84.
Overwrites a few methods in Map_Enemy regarding to event activation. I'm pretty sure there aren't any scripts out there that modify these methods, so it should be fairly compatible. 


Credits and Thanks


  • KK20 - For creating the script

  • Sin86 - For the idea/inspiration/bug report




Author's Notes

dat script name :V: Also my first ever submitted script here. Wooo!
Feedback or ideas are appreciated. If winkio approves it, this might be an official feature for Blizz-ABS in the future. Until then, have fun with this. :)





   


   
   


   
   

Other Projects
RPG Maker XP AceUpgrade RMXP to RMVXA performance!
XPA TilemapTilemap rewrite with many features, including custom resolution!



Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

Sin86

October 23, 2012, 12:52:11 pm #1 Last Edit: October 23, 2012, 12:56:26 pm by Sin86
Very awesome script, except I'm having a few issues with enemies and variables.

I'm trying to make a room to where you have to kill all enemies and each variable represents an enemy killed. For example, a room with 3 enemies. To get out, you have to kill all 3 enemies.

On each enemy, I set a variable with a constant +1. However, as soon as I kill that enemy that has that variable, the game locks up and freezes.



I posted this in the Blizz ABS thread but deleted the post after experimenting to see if any external scripts were causing this and apparently this one, sadly is causing it. Also, this happens even if the triggers aren't being used, yet happens as long as the script is installed. Any way to fix it?

KK20

I found out what the problem is, but I'm going to have to research it a bit more. It's been a while since I've done this script and I kinda forgot what I did.

Anyways, a temp fix, find def start in my script and make it look like so:
  def start
    # if event code exists
    return if @list.size <= 1
    # set starting and execution flag
    @starting = @execute = true
    @trigger = 1
  end
It has something to do with @trigger. I'll try and get this updated.





   


   
   


   
   

Other Projects
RPG Maker XP AceUpgrade RMXP to RMVXA performance!
XPA TilemapTilemap rewrite with many features, including custom resolution!



Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

KK20






   


   
   


   
   

Other Projects
RPG Maker XP AceUpgrade RMXP to RMVXA performance!
XPA TilemapTilemap rewrite with many features, including custom resolution!



Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!