Checking for any Event ID that is in an Array

I'm working with RMXP, I'm hoping someone with scripting knowledge can help me out. For some quick background, this is for projectiles in an ABS I'm working on. Every time a projectile is fired, an event spawns, and the event ID is added to an array ($projectiles_array). Once the projectile has run its course, the even ID is erased from the array.

What I'm trying to do now with the collision detection, is check each event ID that is currently in $projectiles_array. For example, on a map with no events, the hero fires 3 arrows, meaning $projectile_array == [1, 2, 3] In pseudo-code, I'd need something like this:

  1. unless $projectiles_array.empty?
  2.    e = $game_map.events[1] or $game_map.events[2] or $game_map.events[3]
  3. end
Expand to see the code.


Can someone help me out?
Something along the lines of this?
  1. def check_projectile_collision(id)
  2.     for ev in $game_map.events.values
  3.         next if id == ev.id
  4.         next if $game_map.events[id] == nil
  5.         return true if (ev.x == $game_map.events[id].x) and (ev.y == $game_map.events[id].y)
  6.     end
  7.     return false
  8. end
  9.  
Expand to see the code.

Then you'd just run something like:
  1. #other code
  2. if $projectiles_array.length > 0
  3.     for id in $projectiles_array
  4.         if check_projectile_collision(id)
  5.             #if it hit something
  6.         else
  7.             #nothing collided
  8.         end
  9.     end
  10. end
  11. #continue
Expand to see the code.


This is rough and untested, but should work, in theory.
I appreciate the effort ZenVirZan, but I already have the collision code working. I'm working with a pixel-based script, so unfortunately event.x==projectile.x doesn't work. Basically what I did was give every object/enemy a certain width and height, and it'll actually use those dimensions to make hit-boxes. Anyways, I digress; perhaps I should post the full script I'm working with and maybe you or someone else can take a look.

  1. #==============================================================================
  2. # ■ Sticky Switches
  3. #------------------------------------------------------------------------------
  4. # This is the script for Sticky Switches.
  5. #==============================================================================
  6. # Version 3 by Astro_mech
  7. # Version 3 Update by Ace of Spades
  8.  
  9. #==============================================================================
  10. # ■ Game_Character
  11. #------------------------------------------------------------------------------
  12. #   With Facing Detection by: Astro_mech
  13. #   New Facing Detections by:  Ace of Spades
  14. #==============================================================================
  15.  
  16. class Game_Character
  17. DOWN  = 2
  18. LEFT  = 4
  19. RIGHT = 6
  20. UP    = 8
  21. #--------------------------------------------------------------------------
  22. def facing?(event)
  23.   case @direction
  24.   when DOWN
  25.     return (self.y < event.y and event.direction == UP)
  26.   when LEFT
  27.     return (self.x < event.x and event.direction == RIGHT)
  28.   when RIGHT
  29.     return (self.x > event.x and event.direction == LEFT)
  30.   when UP
  31.     return (self.y > event.y and event.direction == DOWN)
  32.   end
  33. end
  34. #--------------------------------------------------------------------------
  35. def opposite_dir?(event)
  36.   case @direction
  37.   when DOWN
  38.     return (self.y > event.y and event.direction == UP)
  39.   when LEFT
  40.     return (self.x > event.x and event.direction == RIGHT)
  41.   when RIGHT
  42.     return (self.x < event.x and event.direction == LEFT)
  43.   when UP
  44.     return (self.y < event.y and event.direction == DOWN)
  45.   end
  46. end
  47. #--------------------------------------------------------------------------
  48.  def sourcefacing?(event)
  49.   case @direction
  50.   when DOWN
  51.     return (self.y < event.y)
  52.   when LEFT
  53.     return (self.x < event.x)
  54.   when RIGHT
  55.     return (self.x > event.x)
  56.   when UP
  57.     return (self.y > event.y)
  58.   end
  59. end
  60. #--------------------------------------------------------------------------
  61. def facingsource?(event)
  62.    if event.direction == DOWN
  63.      return (self.y > event.y)
  64.    end
  65.    if event.direction == LEFT
  66.      return (self.x < event.x)
  67.    end
  68.    if event.direction == RIGHT
  69.     return (self.x > event.x)
  70.     end
  71.    if event.direction == UP
  72.     return (self.y < event.y)
  73.   end
  74. end
  75.  #--------------------------------------------------------------------------
  76. def facingawaysource?(event)
  77.    if event.direction == UP
  78.      return (self.y > event.y)
  79.    end
  80.    if event.direction == RIGHT
  81.      return (self.x < event.x)
  82.    end
  83.    if event.direction == LEFT
  84.     return (self.x > event.x)
  85.     end
  86.    if event.direction == DOWN
  87.     return (self.y < event.y)
  88.   end
  89. end
  90.  #--------------------------------------------------------------------------
  91.  def sourcefacingaway?(event)
  92.   case @direction
  93.   when UP
  94.     return (self.y < event.y)
  95.   when RIGHT
  96.     return (self.x < event.x)
  97.   when LEFT
  98.     return (self.x > event.x)
  99.   when DOWN
  100.     return (self.y > event.y)
  101.   end
  102. end
  103. #------------------------------------------------------------------------------
  104. end
  105. #==============================================================================
  106. # ■ Game_Event
  107. #------------------------------------------------------------------------------
  108. #  With Sticky Keys by Astro_mech
  109. #==============================================================================
  110.  
  111. class Game_Event < Game_Character
  112. #--------------------------------------------------------------------------
  113. alias ss_initialize initialize
  114. def initialize(*args)
  115.   @sticky_switches = []
  116.   ss_initialize(*args)
  117. end
  118. #--------------------------------------------------------------------------
  119. def refresh
  120.   new_page = nil
  121.   unless @erased
  122.     for page in @event.pages.reverse
  123.       c = page.condition
  124.       if c.switch1_valid
  125.         if $game_switches[c.switch1_id] == false
  126.           next
  127.         end
  128.       end
  129.       if c.switch2_valid
  130.         if $game_switches[c.switch2_id] == false
  131.           next
  132.         end
  133.       end
  134.       if c.variable_valid
  135.         if $game_variables[c.variable_id] < c.variable_value
  136.           next
  137.         end
  138.       end
  139.       if c.self_switch_valid
  140.         key = [@map_id, @event.id, c.self_switch_ch]
  141.         if $game_self_switches[key] != true
  142.           next
  143.         end
  144.       end
  145.       new_page = page
  146.       break
  147.     end
  148.   end
  149.   if new_page == @page
  150.     return
  151.   end
  152.   @page = new_page
  153.   clear_starting
  154.   if @page == nil
  155.     @tile_id = 0
  156.     @character_name = ""
  157.     @character_hue = 0
  158.     @move_type = 0
  159.     @through = true
  160.     @trigger = nil
  161.     @list = nil
  162.     @interpreter = nil
  163.     return
  164.   end
  165.   @tile_id = @page.graphic.tile_id
  166.   @character_name = @page.graphic.character_name
  167.   @character_hue = @page.graphic.character_hue
  168.   if @original_direction != @page.graphic.direction
  169.     @direction = @page.graphic.direction
  170.     @original_direction = @direction
  171.     @prelock_direction = 0
  172.   end
  173.   if @original_pattern != @page.graphic.pattern
  174.     @pattern = @page.graphic.pattern
  175.     @original_pattern = @pattern
  176.   end
  177.   @opacity = @page.graphic.opacity
  178.   @blend_type = @page.graphic.blend_type
  179.   @move_type = @page.move_type
  180.   @move_speed = @page.move_speed
  181.   @move_frequency = @page.move_frequency
  182.   @move_route = @page.move_route
  183.   @move_route_index = 0
  184.   @move_route_forcing = false
  185.   @walk_anime = @page.walk_anime
  186.   @step_anime = @page.step_anime
  187.   @direction_fix = @page.direction_fix
  188.   @through = @page.through
  189.   @always_on_top = @page.always_on_top
  190.   @trigger = @page.trigger
  191.   @list = @page.list
  192.   @interpreter = nil
  193.   if @trigger == 4
  194.     @interpreter = Interpreter.new
  195.   end
  196.   check_event_trigger_auto
  197.   @sticky_switches = []
  198.   for line in @list.find_all {|i| i.code == 108}
  199.     a = line.parameters[0].strip.split(' ')
  200.     if a[0] == "sticky_switch"
  201.       if ["A", "B", "C", "D"].include?(a[1].upcase)
  202.         id = a[1].upcase
  203.      end
  204.     if a[2] == nil or a[2].to_i < 0
  205.         e = "$game_player"
  206. #Start Edits
  207.     else
  208.       if a[2] == "projectile"
  209.         unless $projectiles_array.empty?
  210.         $projectiles_array.each do |i|
  211.         e = "$game_map.events[#{i}]"
  212.         end
  213.         end
  214. #End Edits
  215.       else
  216.           e = "$game_map.events[#{a[2]}]"
  217.         end
  218.       end
  219.       if a[3] == nil
  220.         d = 1
  221.       else
  222.         d = a[3].to_i
  223.       end
  224.       if a[4] == nil
  225.         look = 0
  226.       else
  227.         look = a[4].to_i
  228.       end
  229.       @sticky_switches.push([id, e, d, look])
  230.     end
  231.   end
  232. end
  233. #--------------------------------------------------------------------------
  234. alias ss_update update
  235. def update
  236.   ss_update
  237.   update_sticky_switches
  238. end
  239. #--------------------------------------------------------------------------
  240. def update_sticky_switches
  241.   for sswitch in @sticky_switches
  242.     event = eval(sswitch[1])
  243.     if sswitch[2] >= 0
  244.       v = (event.x.between?(self.x-sswitch[2], self.x+sswitch[2]) and
  245.            event.y.between?(self.y-sswitch[2], self.y+sswitch[2]))
  246.     else
  247.       v = true
  248.     end
  249.     if sswitch[3] != 0
  250.       case sswitch[3]
  251.       when +1 # Both Events Facing Eachother
  252.         v &= self.facing?(event)
  253.       when -1 # Both Events Facing Opposite Directions
  254.         v &= self.opposite_dir?(event)
  255.       when +2 # Event/Player is Facing Source Event
  256.         v &= self.facingsource?(event)
  257.        when -2 # Source Event is Facing Event/Player
  258.         v &= self.sourcefacing?(event)
  259.        when +3 # Event/Player is Facing Away from Event/Player
  260.         v &= self.facingawaysource?(event)
  261.        when -3 # Source Event is Facing Away from Event/Player
  262.         v &= self.sourcefacingaway?(event)
  263.       end
  264.     end
  265.     if sswitch[0].is_a?(String) # Self Switches
  266.       key = [@map_id, @id, sswitch[0]]
  267.       $game_map.need_refresh |= (v != $game_self_switches[key])
  268.       $game_self_switches[key] = v
  269.     else                        # Switches
  270.       $game_map.need_refresh |= (v != $game_switches[sswitch[0]])
  271.       $game_switches[sswitch[0]] = v
  272.     end
  273.   end
  274. end
  275. end
  276.  
  277. # 1.  Place any event on the map. I'll call this event self to avoid confusion.
  278. # 2.  Open the event editor, and create a comment anywhere in the event (self).
  279. # 3.  Type "sticky_switch" (without the quotes) in the top line of the event.
  280. # 4.  Type a space, and then the id of the switch to become one of self's sticky switches. To use a local switch, type A, B, C, or D for the respective local switch.
  281. # 5.  Type another space, and then the id of the event on the map to be checked to see if it is close to self. Type -1 or leave this blank to set the event to be the player.
  282. # 6.  Type another space, and then the distance you want self to be able to detect the event. Leave this blank or enter 0 for no distance detection.
  283. # 7.  Type another space, and then a number for the direction check mode: 0 (or blank) for no direction check, 1 to check if self is facing the event, and -1 to check if self is facing opposite of the event.
  284. # 8.  Remember not to leave areas blank if you use something after it. For instance, fill in distance if you want to use direction checking.
  285. # 9.  Repeat steps 2-8 to add any other sticky switches, on the same page or otherwise.
  286. #10.  Click "Ok" on the event editor page, and test your game. The switch should turn on when the event is close to self.
  287. #       View Types  0 = Event/Player is Within Sources Range
  288. #                         1 = Both Events Are Facing Each Other
  289. #                        -1 = Both Events Are Facing Away From Each Other
  290. #                         2 = Event/Player is Facing Source
  291. #                        -2 = Source is Facing Event/Player
  292. #                         3 = Event/Player is Facing Away from Event/Player
  293. #                        -3 = Source Event is Facing Away from Event/Player
Expand to see the code.

 
This script is called Sticky_Switches.  Basically what this does is allow you to put a comment into an event, and that event will automatically turn a switch on if certain conditions are met.  For example, commenting
Quote:
sticky_switch A -1 64 2
in an event would turn on local switch A if the player is within 64 pixels of the event (or two tiles), and the player is currently facing the event.  Once local switch A is on, it begins checking for melee collision, allowing me to save processing power by not constantly checking for collision on every single event on the map.  Hope that makes sense!
 
Anyways, the problem I'm having is that I need an option in the script to check if a projectile is in proximity.  So if I were to comment
Quote:
sticky_switch A projectile 64 0
inside an event, local switch A would turn on if any event ID that is currently in $projectiles_array is within 64 pixels of the event. The edits I've made are between lines 206 and 214, but the code I have there obviously isn't accomplishing what I need it to. I've just been experimenting, but I don't really know how to go about doing what I'm trying to accomplish. Anyone willing to take a look?
It sounds to me like all you need is this:
  1. for projectile in $projectiles
  2.   # do stuff
  3. end
Expand to see the code.

Unless I get you totally wrong :ouch: But you kind of have that with your .each method...
The method I wrote doesn't actually accomplish what I want it to, but it was the best I could come up with. Unfortunately my scripting knowledge is little to none, so I don't really understand how to accomplish what I'm trying to do, that just happened to be my best attempt. I'm confused with what you posted, where could I apply that in the script I posted?

I'm beginning to suspect this might not have been as simple of a question as I thought. At this point, I need the sticky switches script to check the event ID of each projectile, in the format of "$game_map.events[#{i}]", where i is any value currently listed in $projectiles_array (this would replace lines 209-213). Although the more I look at it, the more I realize their may be a problem elsewhere in the script that's holding me back.
If anyone else is willing to take a look at this, I'd really appreciate it. I'm still trying to work around this, but ideally I'd love to get this to work. I don't feel it's too far out of the realm of possibility, if someone with some scripting knowledge could offer any suggestions.
The problem is in your each loop:
  1. $projectiles_array.each do |i|
  2.   e = "$game_map.events[#{i}]"
  3. end
Expand to see the code.

You cycle through all the projectiles in the array, but each time you set it to e, the previous projectile is erased; so in the end, you're only checking for the last projectile in the array, rather than the whole array.

Try this instead:
  1. #==============================================================================
  2. # ■ Sticky Switches
  3. #------------------------------------------------------------------------------
  4. # This is the script for Sticky Switches.
  5. #==============================================================================
  6. # Version 3 by Astro_mech
  7. # Version 3 Update by Ace of Spades
  8.  
  9. #==============================================================================
  10. # ■ Game_Character
  11. #------------------------------------------------------------------------------
  12. #   With Facing Detection by: Astro_mech
  13. #   New Facing Detections by:  Ace of Spades
  14. #==============================================================================
  15.  
  16. class Game_Character
  17.   DOWN  = 2
  18.   LEFT  = 4
  19.   RIGHT = 6
  20.   UP    = 8
  21.   #--------------------------------------------------------------------------
  22.   def facing?(event)
  23.     case @direction
  24.     when DOWN
  25.       return (self.y < event.y and event.direction == UP)
  26.     when LEFT
  27.       return (self.x < event.x and event.direction == RIGHT)
  28.     when RIGHT
  29.       return (self.x > event.x and event.direction == LEFT)
  30.     when UP
  31.       return (self.y > event.y and event.direction == DOWN)
  32.     end
  33.   end
  34.   #--------------------------------------------------------------------------
  35.   def opposite_dir?(event)
  36.     case @direction
  37.     when DOWN
  38.       return (self.y > event.y and event.direction == UP)
  39.     when LEFT
  40.       return (self.x > event.x and event.direction == RIGHT)
  41.     when RIGHT
  42.       return (self.x < event.x and event.direction == LEFT)
  43.     when UP
  44.       return (self.y < event.y and event.direction == DOWN)
  45.     end
  46.   end
  47.   #--------------------------------------------------------------------------
  48.    def sourcefacing?(event)
  49.     case @direction
  50.     when DOWN
  51.       return (self.y < event.y)
  52.     when LEFT
  53.       return (self.x < event.x)
  54.     when RIGHT
  55.       return (self.x > event.x)
  56.     when UP
  57.       return (self.y > event.y)
  58.     end
  59.   end
  60.   #--------------------------------------------------------------------------
  61.   def facingsource?(event)
  62.      if event.direction == DOWN
  63.        return (self.y > event.y)
  64.      end
  65.      if event.direction == LEFT
  66.        return (self.x < event.x)
  67.      end
  68.      if event.direction == RIGHT
  69.       return (self.x > event.x)
  70.       end
  71.      if event.direction == UP
  72.       return (self.y < event.y)
  73.     end
  74.   end
  75.    #--------------------------------------------------------------------------
  76.   def facingawaysource?(event)
  77.      if event.direction == UP
  78.        return (self.y > event.y)
  79.      end
  80.      if event.direction == RIGHT
  81.        return (self.x < event.x)
  82.      end
  83.      if event.direction == LEFT
  84.       return (self.x > event.x)
  85.       end
  86.      if event.direction == DOWN
  87.       return (self.y < event.y)
  88.     end
  89.   end
  90.    #--------------------------------------------------------------------------
  91.    def sourcefacingaway?(event)
  92.     case @direction
  93.     when UP
  94.       return (self.y < event.y)
  95.     when RIGHT
  96.       return (self.x < event.x)
  97.     when LEFT
  98.       return (self.x > event.x)
  99.     when DOWN
  100.       return (self.y > event.y)
  101.     end
  102.   end
  103.   #------------------------------------------------------------------------------
  104. end
  105. #==============================================================================
  106. # ■ Game_Event
  107. #------------------------------------------------------------------------------
  108. #  With Sticky Keys by Astro_mech
  109. #==============================================================================
  110.  
  111. class Game_Event < Game_Character
  112.   #--------------------------------------------------------------------------
  113.   alias ss_initialize initialize
  114.   def initialize(*args)
  115.     @sticky_switches = []
  116.     ss_initialize(*args)
  117.   end
  118.   #--------------------------------------------------------------------------
  119.   def refresh
  120.     new_page = nil
  121.     unless @erased
  122.       for page in @event.pages.reverse
  123.         c = page.condition
  124.         if c.switch1_valid
  125.           if $game_switches[c.switch1_id] == false
  126.             next
  127.           end
  128.         end
  129.         if c.switch2_valid
  130.           if $game_switches[c.switch2_id] == false
  131.             next
  132.           end
  133.         end
  134.         if c.variable_valid
  135.           if $game_variables[c.variable_id] < c.variable_value
  136.             next
  137.           end
  138.         end
  139.         if c.self_switch_valid
  140.           key = [@map_id, @event.id, c.self_switch_ch]
  141.           if $game_self_switches[key] != true
  142.             next
  143.           end
  144.         end
  145.         new_page = page
  146.         break
  147.       end
  148.     end
  149.     if new_page == @page
  150.       return
  151.     end
  152.     @page = new_page
  153.     clear_starting
  154.     if @page == nil
  155.       @tile_id = 0
  156.       @character_name = ""
  157.       @character_hue = 0
  158.       @move_type = 0
  159.       @through = true
  160.       @trigger = nil
  161.       @list = nil
  162.       @interpreter = nil
  163.       return
  164.     end
  165.     @tile_id = @page.graphic.tile_id
  166.     @character_name = @page.graphic.character_name
  167.     @character_hue = @page.graphic.character_hue
  168.     if @original_direction != @page.graphic.direction
  169.       @direction = @page.graphic.direction
  170.       @original_direction = @direction
  171.       @prelock_direction = 0
  172.     end
  173.     if @original_pattern != @page.graphic.pattern
  174.       @pattern = @page.graphic.pattern
  175.       @original_pattern = @pattern
  176.     end
  177.     @opacity = @page.graphic.opacity
  178.     @blend_type = @page.graphic.blend_type
  179.     @move_type = @page.move_type
  180.     @move_speed = @page.move_speed
  181.     @move_frequency = @page.move_frequency
  182.     @move_route = @page.move_route
  183.     @move_route_index = 0
  184.     @move_route_forcing = false
  185.     @walk_anime = @page.walk_anime
  186.     @step_anime = @page.step_anime
  187.     @direction_fix = @page.direction_fix
  188.     @through = @page.through
  189.     @always_on_top = @page.always_on_top
  190.     @trigger = @page.trigger
  191.     @list = @page.list
  192.     @interpreter = nil
  193.     if @trigger == 4
  194.       @interpreter = Interpreter.new
  195.     end
  196.     check_event_trigger_auto
  197.     @sticky_switches = []
  198.     for line in @list.find_all {|i| i.code == 108}
  199.       a = line.parameters[0].strip.split(' ')
  200.       if a[0] == "sticky_switch"
  201.         if ["A", "B", "C", "D"].include?(a[1].upcase)
  202.           id = a[1].upcase
  203.         end
  204.         # Start Edits
  205.         e = []
  206.         if a[2] == nil or a[2].to_i < 0
  207.           e.push("$game_player")
  208.        
  209.         else
  210.           if a[2] == "projectile"
  211.             unless $projectiles_array.empty?
  212.               $projectiles_array.each do |i|
  213.                 e.push("$game_map.events[#{i}]")
  214.               end
  215.             end
  216.           else
  217.             e.push("$game_map.events[#{a[2]}]")
  218.           end
  219.         end
  220.         # End Edits
  221.         if a[3] == nil
  222.           d = 1
  223.         else
  224.           d = a[3].to_i
  225.         end
  226.         if a[4] == nil
  227.           look = 0
  228.         else
  229.           look = a[4].to_i
  230.         end
  231.         @sticky_switches.push([id, e, d, look])
  232.       end
  233.     end
  234.   end
  235.   #--------------------------------------------------------------------------
  236.   alias ss_update update
  237.   def update
  238.     ss_update
  239.     update_sticky_switches
  240.   end
  241.   #--------------------------------------------------------------------------
  242.   def update_sticky_switches
  243.     for sswitch in @sticky_switches
  244.       # Start Edits
  245.       v = false
  246.       for e in sswitch[1]
  247.         event = eval(e) # change from string to object
  248.         if sswitch[2] >= 0
  249.           v = (event.x.between?(self.x-sswitch[2], self.x+sswitch[2]) and
  250.                event.y.between?(self.y-sswitch[2], self.y+sswitch[2]))
  251.         else
  252.           v = true
  253.         end
  254.         if sswitch[3] != 0
  255.           case sswitch[3]
  256.           when +1 # Both Events Facing Eachother
  257.             v &= self.facing?(event)
  258.           when -1 # Both Events Facing Opposite Directions
  259.             v &= self.opposite_dir?(event)
  260.           when +2 # Event/Player is Facing Source Event
  261.             v &= self.facingsource?(event)
  262.            when -2 # Source Event is Facing Event/Player
  263.             v &= self.sourcefacing?(event)
  264.            when +3 # Event/Player is Facing Away from Event/Player
  265.             v &= self.facingawaysource?(event)
  266.            when -3 # Source Event is Facing Away from Event/Player
  267.             v &= self.sourcefacingaway?(event)
  268.           end
  269.         end
  270.         break if v == true
  271.       end
  272.       # End Edits
  273.       if sswitch[0].is_a?(String) # Self Switches
  274.         key = [@map_id, @id, sswitch[0]]
  275.         $game_map.need_refresh |= (v != $game_self_switches[key])
  276.         $game_self_switches[key] = v
  277.       else                        # Switches
  278.         $game_map.need_refresh |= (v != $game_switches[sswitch[0]])
  279.         $game_switches[sswitch[0]] = v
  280.       end
  281.     end
  282.   end
  283. end
  284.  
  285. # 1.  Place any event on the map. I'll call this event self to avoid confusion.
  286. # 2.  Open the event editor, and create a comment anywhere in the event (self).
  287. # 3.  Type "sticky_switch" (without the quotes) in the top line of the event.
  288. # 4.  Type a space, and then the id of the switch to become one of self's sticky switches. To use a local switch, type A, B, C, or D for the respective local switch.
  289. # 5.  Type another space, and then the id of the event on the map to be checked to see if it is close to self. Type -1 or leave this blank to set the event to be the player.
  290. # 6.  Type another space, and then the distance you want self to be able to detect the event. Leave this blank or enter 0 for no distance detection.
  291. # 7.  Type another space, and then a number for the direction check mode: 0 (or blank) for no direction check, 1 to check if self is facing the event, and -1 to check if self is facing opposite of the event.
  292. # 8.  Remember not to leave areas blank if you use something after it. For instance, fill in distance if you want to use direction checking.
  293. # 9.  Repeat steps 2-8 to add any other sticky switches, on the same page or otherwise.
  294. #10.  Click "Ok" on the event editor page, and test your game. The switch should turn on when the event is close to self.
  295. #       View Types  0 = Event/Player is Within Sources Range
  296. #                         1 = Both Events Are Facing Each Other
  297. #                        -1 = Both Events Are Facing Away From Each Other
  298. #                         2 = Event/Player is Facing Source
  299. #                        -2 = Source is Facing Event/Player
  300. #                         3 = Event/Player is Facing Away from Event/Player
  301. #                        -3 = Source Event is Facing Away from Event/Player
Expand to see the code.


I changed two sections. The first part is where you made your edits; instead of setting e to one event, I made it an array that pushes (adds) each item in the projectiles array.

The second edit is in "def update_sticky_switches"; because it's an array, not a single event, I added a for loop that checks each event. If at the end of one check "v" (your switch check variable) is true, it will break and not bother to check the other elements in the array.

Let me know if that works out!

PS I helped indent the script for you; one of my pet peeves is messy code! (No worries, yours was relatively clean compared to the mess of XAS_ABS...)
Thank you so much for you help Regi! That's what I love about this place, knowledgable, friendly users, and quick response times. However, I did run into some errors with the code you provided. I ran through a few scenarios, and these are the errors I came up with:

Checking for player
Quote:
line 246: No Method Error occured
undefined method 'values' for ["$game_player"]:Array


Checking when no projectiles are on the map
Quote:
line 246: No Method Error occured
undefined method 'values' for []:Array


Checked with two projectiles on the map, events 4 and 5
Quote:
undefined method 'values' for [$game_map.events[4]", "$game_map.events[5]"]:Array


I really appreciate you taking the time to look at this for me, it'd mean a lot to the progress of my game if I could get this working properly. I'd be able to put more interactive objects on each map with less lag processing it. If you could take another look to see what might have went wrong, I'd be really thankful.
Oops, you can get rid of the ".values" on line 246. I have a habit of adding that since I always work with arrays with events :x

I also fixed indentation from lines 213-216, if you care about that :P The new code is in my previous post, or you can make the edits yourself.

Let me know if that works!
So I tried out the revised code, and two things I noticed:
It still isn't detecting the event id's that are projectiles, and when I try to check for both the player and a projectile in the same event, nothing will register. The player detection by itself still works fine though. There weren't any script errors this time around, but projectiles still aren't being detected.
Hrm... do you update $projectiles_array continuously? The way the script is currently set up, it only adds projectiles to the sticky switch whenever the event refreshes (each time it changes a page). This means if you add an event to $projectiles_array after the event has been set up, the new event won't register.

Try this:
  1. #==============================================================================
  2. # ■ Sticky Switches
  3. #------------------------------------------------------------------------------
  4. # This is the script for Sticky Switches.
  5. #==============================================================================
  6. # Version 3 by Astro_mech
  7. # Version 3 Update by Ace of Spades
  8. #==============================================================================
  9. # ■ Game_Character
  10. #------------------------------------------------------------------------------
  11. #   With Facing Detection by: Astro_mech
  12. #   New Facing Detections by: Ace of Spades
  13. #==============================================================================
  14.  
  15. class Game_Character
  16.   DOWN  = 2
  17.   LEFT  = 4
  18.   RIGHT = 6
  19.   UP    = 8
  20.   #--------------------------------------------------------------------------
  21.   def facing?(event)
  22.     case @direction
  23.     when DOWN
  24.       return (self.y < event.y and event.direction == UP)
  25.     when LEFT
  26.       return (self.x < event.x and event.direction == RIGHT)
  27.     when RIGHT
  28.       return (self.x > event.x and event.direction == LEFT)
  29.     when UP
  30.       return (self.y > event.y and event.direction == DOWN)
  31.     end
  32.   end
  33.   #--------------------------------------------------------------------------
  34.   def opposite_dir?(event)
  35.     case @direction
  36.     when DOWN
  37.       return (self.y > event.y and event.direction == UP)
  38.     when LEFT
  39.       return (self.x > event.x and event.direction == RIGHT)
  40.     when RIGHT
  41.       return (self.x < event.x and event.direction == LEFT)
  42.     when UP
  43.       return (self.y < event.y and event.direction == DOWN)
  44.     end
  45.   end
  46.   #--------------------------------------------------------------------------
  47.    def sourcefacing?(event)
  48.     case @direction
  49.     when DOWN
  50.       return (self.y < event.y)
  51.     when LEFT
  52.       return (self.x < event.x)
  53.     when RIGHT
  54.       return (self.x > event.x)
  55.     when UP
  56.       return (self.y > event.y)
  57.     end
  58.   end
  59.   #--------------------------------------------------------------------------
  60.   def facingsource?(event)
  61.      if event.direction == DOWN
  62.        return (self.y > event.y)
  63.      end
  64.      if event.direction == LEFT
  65.        return (self.x < event.x)
  66.      end
  67.      if event.direction == RIGHT
  68.       return (self.x > event.x)
  69.       end
  70.      if event.direction == UP
  71.       return (self.y < event.y)
  72.     end
  73.   end
  74.    #--------------------------------------------------------------------------
  75.   def facingawaysource?(event)
  76.      if event.direction == UP
  77.        return (self.y > event.y)
  78.      end
  79.      if event.direction == RIGHT
  80.        return (self.x < event.x)
  81.      end
  82.      if event.direction == LEFT
  83.       return (self.x > event.x)
  84.       end
  85.      if event.direction == DOWN
  86.       return (self.y < event.y)
  87.     end
  88.   end
  89.    #--------------------------------------------------------------------------
  90.    def sourcefacingaway?(event)
  91.     case @direction
  92.     when UP
  93.       return (self.y < event.y)
  94.     when RIGHT
  95.       return (self.x < event.x)
  96.     when LEFT
  97.       return (self.x > event.x)
  98.     when DOWN
  99.       return (self.y > event.y)
  100.     end
  101.   end
  102.   #------------------------------------------------------------------------------
  103. end
  104. #==============================================================================
  105. # ■ Game_Event
  106. #------------------------------------------------------------------------------
  107. #  With Sticky Keys by Astro_mech
  108. #==============================================================================
  109.  
  110. class Game_Event < Game_Character
  111.   #--------------------------------------------------------------------------
  112.   alias ss_initialize initialize
  113.   def initialize(*args)
  114.     @sticky_switches = []
  115.     @last_projectiles = []
  116.     ss_initialize(*args)
  117.   end
  118.   #--------------------------------------------------------------------------
  119.   def refresh
  120.     new_page = nil
  121.     unless @erased
  122.       for page in @event.pages.reverse
  123.         c = page.condition
  124.         if c.switch1_valid
  125.           if $game_switches[c.switch1_id] == false
  126.             next
  127.           end
  128.         end
  129.         if c.switch2_valid
  130.           if $game_switches[c.switch2_id] == false
  131.             next
  132.           end
  133.         end
  134.         if c.variable_valid
  135.           if $game_variables[c.variable_id] < c.variable_value
  136.             next
  137.           end
  138.         end
  139.         if c.self_switch_valid
  140.           key = [@map_id, @event.id, c.self_switch_ch]
  141.           if $game_self_switches[key] != true
  142.             next
  143.           end
  144.         end
  145.         new_page = page
  146.         break
  147.       end
  148.     end
  149.     if new_page == @page
  150.       return
  151.     end
  152.     @page = new_page
  153.     clear_starting
  154.     if @page == nil
  155.       @tile_id = 0
  156.       @character_name = ""
  157.       @character_hue = 0
  158.       @move_type = 0
  159.       @through = true
  160.       @trigger = nil
  161.       @list = nil
  162.       @interpreter = nil
  163.       return
  164.     end
  165.     @tile_id = @page.graphic.tile_id
  166.     @character_name = @page.graphic.character_name
  167.     @character_hue = @page.graphic.character_hue
  168.     if @original_direction != @page.graphic.direction
  169.       @direction = @page.graphic.direction
  170.       @original_direction = @direction
  171.       @prelock_direction = 0
  172.     end
  173.     if @original_pattern != @page.graphic.pattern
  174.       @pattern = @page.graphic.pattern
  175.       @original_pattern = @pattern
  176.     end
  177.     @opacity = @page.graphic.opacity
  178.     @blend_type = @page.graphic.blend_type
  179.     @move_type = @page.move_type
  180.     @move_speed = @page.move_speed
  181.     @move_frequency = @page.move_frequency
  182.     @move_route = @page.move_route
  183.     @move_route_index = 0
  184.     @move_route_forcing = false
  185.     @walk_anime = @page.walk_anime
  186.     @step_anime = @page.step_anime
  187.     @direction_fix = @page.direction_fix
  188.     @through = @page.through
  189.     @always_on_top = @page.always_on_top
  190.     @trigger = @page.trigger
  191.     @list = @page.list
  192.     @interpreter = nil
  193.     if @trigger == 4
  194.       @interpreter = Interpreter.new
  195.     end
  196.     check_event_trigger_auto
  197.     @sticky_switches = []
  198.     for line in @list.find_all {|i| i.code == 108}
  199.       a = line.parameters[0].strip.split(' ')
  200.       if a[0] == "sticky_switch"
  201.         if ["A", "B", "C", "D"].include?(a[1].upcase)
  202.           id = a[1].upcase
  203.         end
  204.         # Start Edits
  205.         e = []
  206.         if a[2] == nil or a[2].to_i < 0
  207.           e.push("$game_player")
  208.        
  209.         elsif a[2] == "projectile"
  210.           unless $projectiles_array.empty?
  211.             $projectiles_array.each do |i|
  212.               e.push("$game_map.events[#{i}]")
  213.             end
  214.           end
  215.         else
  216.           e.push("$game_map.events[#{a[2]}]")
  217.         end
  218.         # End Edits
  219.         if a[3] == nil
  220.           d = 1
  221.         else
  222.           d = a[3].to_i
  223.         end
  224.         if a[4] == nil
  225.           look = 0
  226.         else
  227.           look = a[4].to_i
  228.         end
  229.         @sticky_switches.push([id, e, d, look])
  230.       end
  231.     end
  232.   end
  233.   #--------------------------------------------------------------------------
  234.   alias ss_update update
  235.   def update
  236.     ss_update
  237.    
  238.     return if @sticky_switches.empty?
  239.     if @last_projectiles != $projectiles_array
  240.       refresh
  241.       @last_projectiles = $projectiles_array
  242.     end
  243.     update_sticky_switches
  244.   end
  245.   #--------------------------------------------------------------------------
  246.   def update_sticky_switches
  247.     for sswitch in @sticky_switches
  248.       # Start Edits
  249.       v = false
  250.       for e in sswitch[1]
  251.         event = eval(e) # change from string to object
  252.         if sswitch[2] >= 0
  253.           v = (event.x.between?(self.x-sswitch[2], self.x+sswitch[2]) and
  254.                event.y.between?(self.y-sswitch[2], self.y+sswitch[2]))
  255.         else
  256.           v = true
  257.         end
  258.         if sswitch[3] != 0
  259.           case sswitch[3]
  260.           when +1 # Both Events Facing Eachother
  261.             v &= self.facing?(event)
  262.           when -1 # Both Events Facing Opposite Directions
  263.             v &= self.opposite_dir?(event)
  264.           when +2 # Event/Player is Facing Source Event
  265.             v &= self.facingsource?(event)
  266.            when -2 # Source Event is Facing Event/Player
  267.             v &= self.sourcefacing?(event)
  268.            when +3 # Event/Player is Facing Away from Event/Player
  269.             v &= self.facingawaysource?(event)
  270.            when -3 # Source Event is Facing Away from Event/Player
  271.             v &= self.sourcefacingaway?(event)
  272.           end
  273.         end
  274.         break if v == true
  275.       end
  276.       # End Edits
  277.       if sswitch[0].is_a?(String) # Self Switches
  278.         key = [@map_id, @id, sswitch[0]]
  279.         $game_map.need_refresh |= (v != $game_self_switches[key])
  280.         $game_self_switches[key] = v
  281.       else                        # Switches
  282.         $game_map.need_refresh |= (v != $game_switches[sswitch[0]])
  283.         $game_switches[sswitch[0]] = v
  284.       end
  285.     end
  286.   end
  287. end
  288.  
  289. # 1.  Place any event on the map. I'll call this event self to avoid confusion.
  290. # 2.  Open the event editor, and create a comment anywhere in the event (self).
  291. # 3.  Type "sticky_switch" (without the quotes) in the top line of the event.
  292. # 4.  Type a space, and then the id of the switch to become one of self's sticky switches. To use a local switch, type A, B, C, or D for the respective local switch.
  293. # 5.  Type another space, and then the id of the event on the map to be checked to see if it is close to self. Type -1 or leave this blank to set the event to be the player.
  294. # 6.  Type another space, and then the distance you want self to be able to detect the event. Leave this blank or enter 0 for no distance detection.
  295. # 7.  Type another space, and then a number for the direction check mode: 0 (or blank) for no direction check, 1 to check if self is facing the event, and -1 to check if self is facing opposite of the event.
  296. # 8.  Remember not to leave areas blank if you use something after it. For instance, fill in distance if you want to use direction checking.
  297. # 9.  Repeat steps 2-8 to add any other sticky switches, on the same page or otherwise.
  298. #10.  Click "Ok" on the event editor page, and test your game. The switch should turn on when the event is close to self.
  299. #       View Types  0 = Event/Player is Within Sources Range
  300. #                         1 = Both Events Are Facing Each Other
  301. #                        -1 = Both Events Are Facing Away From Each Other
  302. #                         2 = Event/Player is Facing Source
  303. #                        -2 = Source is Facing Event/Player
  304. #                         3 = Event/Player is Facing Away from Event/Player
  305. #                        -3 = Source Event is Facing Away from Event/Player
Expand to see the code.

I added a @last_projectiles variable that is compared to $projectiles_array in the update function, which refreshes the event (and sticky-switch) if $projectile_array changes.

This still doesn't fix testing a player AND a projectile simultaneously, but if you let me know how you want the syntax to be, I can help you.
Okay, so it seemed you were correct about the problem. However, it still only detects projectiles that have entered the map before the event page is activated. The way I have everything set up now, is the collision of objects is detected with parallel process events. So every object (bush, rock, enemy, etc) that the player interacts with, is constantly checking for collision. The idea of this script is to have all those events set up as action key events on the first page, with a sticky switch that activates a local switch whenever the player or a projectile is in range, so they aren't constantly checking for collision. So essentially, yes, I'd need it to refresh what the event is checking for whenever a new projectile is added or removed. As far as the syntax goes, it doesn't matter if I could use two separate commands to check for both the player and projectiles, or if there would be one command to check for the player and projectiles in a two tile range simultaneously
Hopefully this should do it.
  1. #==============================================================================
  2. # ■ Sticky Switches
  3. #------------------------------------------------------------------------------
  4. # This is the script for Sticky Switches.
  5. #==============================================================================
  6. # Version 3 by Astro_mech
  7. # Version 3 Update by Ace of Spades
  8. #==============================================================================
  9. # ■ Game_Character
  10. #------------------------------------------------------------------------------
  11. #   With Facing Detection by: Astro_mech
  12. #   New Facing Detections by: Ace of Spades
  13. #==============================================================================
  14.  
  15. class Game_Character
  16.   DOWN  = 2
  17.   LEFT  = 4
  18.   RIGHT = 6
  19.   UP    = 8
  20.   #--------------------------------------------------------------------------
  21.   def facing?(event)
  22.     case @direction
  23.     when DOWN
  24.       return (self.y < event.y and event.direction == UP)
  25.     when LEFT
  26.       return (self.x < event.x and event.direction == RIGHT)
  27.     when RIGHT
  28.       return (self.x > event.x and event.direction == LEFT)
  29.     when UP
  30.       return (self.y > event.y and event.direction == DOWN)
  31.     end
  32.   end
  33.   #--------------------------------------------------------------------------
  34.   def opposite_dir?(event)
  35.     case @direction
  36.     when DOWN
  37.       return (self.y > event.y and event.direction == UP)
  38.     when LEFT
  39.       return (self.x > event.x and event.direction == RIGHT)
  40.     when RIGHT
  41.       return (self.x < event.x and event.direction == LEFT)
  42.     when UP
  43.       return (self.y < event.y and event.direction == DOWN)
  44.     end
  45.   end
  46.   #--------------------------------------------------------------------------
  47.    def sourcefacing?(event)
  48.     case @direction
  49.     when DOWN
  50.       return (self.y < event.y)
  51.     when LEFT
  52.       return (self.x < event.x)
  53.     when RIGHT
  54.       return (self.x > event.x)
  55.     when UP
  56.       return (self.y > event.y)
  57.     end
  58.   end
  59.   #--------------------------------------------------------------------------
  60.   def facingsource?(event)
  61.      if event.direction == DOWN
  62.        return (self.y > event.y)
  63.      end
  64.      if event.direction == LEFT
  65.        return (self.x < event.x)
  66.      end
  67.      if event.direction == RIGHT
  68.       return (self.x > event.x)
  69.       end
  70.      if event.direction == UP
  71.       return (self.y < event.y)
  72.     end
  73.   end
  74.    #--------------------------------------------------------------------------
  75.   def facingawaysource?(event)
  76.      if event.direction == UP
  77.        return (self.y > event.y)
  78.      end
  79.      if event.direction == RIGHT
  80.        return (self.x < event.x)
  81.      end
  82.      if event.direction == LEFT
  83.       return (self.x > event.x)
  84.       end
  85.      if event.direction == DOWN
  86.       return (self.y < event.y)
  87.     end
  88.   end
  89.    #--------------------------------------------------------------------------
  90.    def sourcefacingaway?(event)
  91.     case @direction
  92.     when UP
  93.       return (self.y < event.y)
  94.     when RIGHT
  95.       return (self.x < event.x)
  96.     when LEFT
  97.       return (self.x > event.x)
  98.     when DOWN
  99.       return (self.y > event.y)
  100.     end
  101.   end
  102.   #------------------------------------------------------------------------------
  103. end
  104. #==============================================================================
  105. # ■ Game_Event
  106. #------------------------------------------------------------------------------
  107. #  With Sticky Keys by Astro_mech
  108. #==============================================================================
  109.  
  110. class Game_Event < Game_Character
  111.   #--------------------------------------------------------------------------
  112.   alias ss_initialize initialize
  113.   def initialize(*args)
  114.     @sticky_switches = []
  115.     ss_initialize(*args)
  116.   end
  117.   #--------------------------------------------------------------------------
  118.   def refresh
  119.     new_page = nil
  120.     unless @erased
  121.       for page in @event.pages.reverse
  122.         c = page.condition
  123.         if c.switch1_valid
  124.           if $game_switches[c.switch1_id] == false
  125.             next
  126.           end
  127.         end
  128.         if c.switch2_valid
  129.           if $game_switches[c.switch2_id] == false
  130.             next
  131.           end
  132.         end
  133.         if c.variable_valid
  134.           if $game_variables[c.variable_id] < c.variable_value
  135.             next
  136.           end
  137.         end
  138.         if c.self_switch_valid
  139.           key = [@map_id, @event.id, c.self_switch_ch]
  140.           if $game_self_switches[key] != true
  141.             next
  142.           end
  143.         end
  144.         new_page = page
  145.         break
  146.       end
  147.     end
  148.     if new_page == @page
  149.       return
  150.     end
  151.     @page = new_page
  152.     clear_starting
  153.     if @page == nil
  154.       @tile_id = 0
  155.       @character_name = ""
  156.       @character_hue = 0
  157.       @move_type = 0
  158.       @through = true
  159.       @trigger = nil
  160.       @list = nil
  161.       @interpreter = nil
  162.       return
  163.     end
  164.     @tile_id = @page.graphic.tile_id
  165.     @character_name = @page.graphic.character_name
  166.     @character_hue = @page.graphic.character_hue
  167.     if @original_direction != @page.graphic.direction
  168.       @direction = @page.graphic.direction
  169.       @original_direction = @direction
  170.       @prelock_direction = 0
  171.     end
  172.     if @original_pattern != @page.graphic.pattern
  173.       @pattern = @page.graphic.pattern
  174.       @original_pattern = @pattern
  175.     end
  176.     @opacity = @page.graphic.opacity
  177.     @blend_type = @page.graphic.blend_type
  178.     @move_type = @page.move_type
  179.     @move_speed = @page.move_speed
  180.     @move_frequency = @page.move_frequency
  181.     @move_route = @page.move_route
  182.     @move_route_index = 0
  183.     @move_route_forcing = false
  184.     @walk_anime = @page.walk_anime
  185.     @step_anime = @page.step_anime
  186.     @direction_fix = @page.direction_fix
  187.     @through = @page.through
  188.     @always_on_top = @page.always_on_top
  189.     @trigger = @page.trigger
  190.     @list = @page.list
  191.     @interpreter = nil
  192.     if @trigger == 4
  193.       @interpreter = Interpreter.new
  194.     end
  195.     check_event_trigger_auto
  196.     @sticky_switches = []
  197.     for line in @list.find_all {|i| i.code == 108}
  198.       a = line.parameters[0].strip.split(' ')
  199.       if a[0] == "sticky_switch"
  200.         if ["A", "B", "C", "D"].include?(a[1].upcase)
  201.           id = a[1].upcase
  202.         end
  203.         # Start Edits
  204.         events = []
  205.         chars = a[2].strip.split(',')
  206.         for c in chars
  207.           if c == nil or c.to_i < 0
  208.             events.push("$game_player")
  209.           elsif c == "p" or c == "projectiles"
  210.             events.push("projectiles")
  211.           else
  212.             events.push("$game_map.events[#{c}]")
  213.           end
  214.         end
  215.         # End Edits
  216.         if a[3] == nil
  217.           dir = 1
  218.         else
  219.           dir = a[3].to_i
  220.         end
  221.         if a[4] == nil
  222.           look = 0
  223.         else
  224.           look = a[4].to_i
  225.         end
  226.         @sticky_switches.push([id, events, dir, look])
  227.       end
  228.     end
  229.   end
  230.   #--------------------------------------------------------------------------
  231.   alias ss_update update
  232.   def update
  233.     ss_update
  234.     return if @sticky_switches.empty?
  235.     update_sticky_switches
  236.   end
  237.   #--------------------------------------------------------------------------
  238.   def update_sticky_switches
  239.     for sswitch in @sticky_switches
  240.       # Start Edits
  241.       v = false
  242.       events = sswitch[1].dup
  243.       if events.include?("projectiles")
  244.         unless $projectiles_array.empty?
  245.           $projectiles_array.each do |i|
  246.             events.push("$game_map.events[#{i}]")
  247.           end
  248.         end
  249.         events.delete("projectiles")
  250.       end
  251.       for e in events
  252.         event = eval(e) # change from string to object
  253.         if sswitch[2] >= 0
  254.           v = (event.x.between?(self.x-sswitch[2], self.x+sswitch[2]) and
  255.                event.y.between?(self.y-sswitch[2], self.y+sswitch[2]))
  256.         else
  257.           v = true
  258.         end
  259.         if sswitch[3] != 0
  260.           case sswitch[3]
  261.           when +1 # Both Events Facing Eachother
  262.             v &= self.facing?(event)
  263.           when -1 # Both Events Facing Opposite Directions
  264.             v &= self.opposite_dir?(event)
  265.           when +2 # Event/Player is Facing Source Event
  266.             v &= self.facingsource?(event)
  267.           when -2 # Source Event is Facing Event/Player
  268.             v &= self.sourcefacing?(event)
  269.           when +3 # Event/Player is Facing Away from Event/Player
  270.             v &= self.facingawaysource?(event)
  271.           when -3 # Source Event is Facing Away from Event/Player
  272.             v &= self.sourcefacingaway?(event)
  273.           end
  274.         end
  275.         break if v == true
  276.       end
  277.       # End Edits
  278.       if sswitch[0].is_a?(String) # Self Switches
  279.         key = [@map_id, @id, sswitch[0]]
  280.         $game_map.need_refresh |= (v != $game_self_switches[key])
  281.         $game_self_switches[key] = v
  282.       else                        # Switches
  283.         $game_map.need_refresh |= (v != $game_switches[sswitch[0]])
  284.         $game_switches[sswitch[0]] = v
  285.       end
  286.     end
  287.   end
  288. end
  289.  
  290. # 1.  Place any event on the map. I'll call this event self to avoid confusion.
  291. # 2.  Open the event editor, and create a comment anywhere in the event (self).
  292. # 3.  Type "sticky_switch" (without the quotes) in the top line of the event.
  293. # 4.  Type a space, and then the id of the switch to become one of self's sticky switches. To use a local switch, type A, B, C, or D for the respective local switch.
  294. # 5.  Type another space, and then the id of the event on the map to be checked to see if it is close to self. Type -1 or leave this blank to set the event to be the player.
  295. # 6.  Type another space, and then the distance you want self to be able to detect the event. Leave this blank or enter 0 for no distance detection.
  296. # 7.  Type another space, and then a number for the direction check mode: 0 (or blank) for no direction check, 1 to check if self is facing the event, and -1 to check if self is facing opposite of the event.
  297. # 8.  Remember not to leave areas blank if you use something after it. For instance, fill in distance if you want to use direction checking.
  298. # 9.  Repeat steps 2-8 to add any other sticky switches, on the same page or otherwise.
  299. #10.  Click "Ok" on the event editor page, and test your game. The switch should turn on when the event is close to self.
  300. #       View Types  0 = Event/Player is Within Sources Range
  301. #                         1 = Both Events Are Facing Each Other
  302. #                        -1 = Both Events Are Facing Away From Each Other
  303. #                         2 = Event/Player is Facing Source
  304. #                        -2 = Source is Facing Event/Player
  305. #                         3 = Event/Player is Facing Away from Event/Player
  306. #                        -3 = Source Event is Facing Away from Event/Player
Expand to see the code.

The syntax for multiple events should be:
sticky_switch A -1,1,p 64 0

In this case, you'd be checking for the player, event 1, and all projectiles (make sure not to add any spaces between commas, or it'll think you're moving on). You can type either "p" or "projectiles"; I thought the former would be easier.

If you're wondering how, I changed the comment from adding the events themselves to simply adding the string "projectiles". Then in "update_sticky_switches", it checks if the array of events includes "projectiles"; if so, it deletes that and adds all the events in $projectiles_array. This way, there's no need to refresh the page, as it updates every frame, and should catch new projectiles.
Well, I've been using the script for a couple days and everything appears to be working correctly! Hopefully I can start placing more objects on the map and not have to worry about it hurting the performance too much. I just want to thank you again for all your help, I really do appreciate it, and I'll certainly be placing your name in the credits.

In the mean time, if there's anything I can possibly help you with in return, feel free to let me know.
You're welcome, glad I could help! I don't think I need much help other than feedback on ideas and beta-testers, later, but if you're willing I can definitely give you a link to my private subforum.

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=76587