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.
- #==============================================================================
- # ■ Sticky Switches
- #------------------------------------------------------------------------------
- # This is the script for Sticky Switches.
- #==============================================================================
- # Version 3 by Astro_mech
- # Version 3 Update by Ace of Spades
-
- #==============================================================================
- # ■ Game_Character
- #------------------------------------------------------------------------------
- # With Facing Detection by: Astro_mech
- # New Facing Detections by: Ace of Spades
- #==============================================================================
-
- class Game_Character
- DOWN = 2
- LEFT = 4
- RIGHT = 6
- UP = 8
- #--------------------------------------------------------------------------
- def facing?(event)
- case @direction
- when DOWN
- return (self.y < event.y and event.direction == UP)
- when LEFT
- return (self.x < event.x and event.direction == RIGHT)
- when RIGHT
- return (self.x > event.x and event.direction == LEFT)
- when UP
- return (self.y > event.y and event.direction == DOWN)
- end
- end
- #--------------------------------------------------------------------------
- def opposite_dir?(event)
- case @direction
- when DOWN
- return (self.y > event.y and event.direction == UP)
- when LEFT
- return (self.x > event.x and event.direction == RIGHT)
- when RIGHT
- return (self.x < event.x and event.direction == LEFT)
- when UP
- return (self.y < event.y and event.direction == DOWN)
- end
- end
- #--------------------------------------------------------------------------
- def sourcefacing?(event)
- case @direction
- when DOWN
- return (self.y < event.y)
- when LEFT
- return (self.x < event.x)
- when RIGHT
- return (self.x > event.x)
- when UP
- return (self.y > event.y)
- end
- end
- #--------------------------------------------------------------------------
- def facingsource?(event)
- if event.direction == DOWN
- return (self.y > event.y)
- end
- if event.direction == LEFT
- return (self.x < event.x)
- end
- if event.direction == RIGHT
- return (self.x > event.x)
- end
- if event.direction == UP
- return (self.y < event.y)
- end
- end
- #--------------------------------------------------------------------------
- def facingawaysource?(event)
- if event.direction == UP
- return (self.y > event.y)
- end
- if event.direction == RIGHT
- return (self.x < event.x)
- end
- if event.direction == LEFT
- return (self.x > event.x)
- end
- if event.direction == DOWN
- return (self.y < event.y)
- end
- end
- #--------------------------------------------------------------------------
- def sourcefacingaway?(event)
- case @direction
- when UP
- return (self.y < event.y)
- when RIGHT
- return (self.x < event.x)
- when LEFT
- return (self.x > event.x)
- when DOWN
- return (self.y > event.y)
- end
- end
- #------------------------------------------------------------------------------
- end
- #==============================================================================
- # ■ Game_Event
- #------------------------------------------------------------------------------
- # With Sticky Keys by Astro_mech
- #==============================================================================
-
- class Game_Event < Game_Character
- #--------------------------------------------------------------------------
- alias ss_initialize initialize
- def initialize(*args)
- @sticky_switches = []
- ss_initialize(*args)
- 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
- @through = true
- @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
- @sticky_switches = []
- for line in @list.find_all {|i| i.code == 108}
- a = line.parameters[0].strip.split(' ')
- if a[0] == "sticky_switch"
- if ["A", "B", "C", "D"].include?(a[1].upcase)
- id = a[1].upcase
- end
- if a[2] == nil or a[2].to_i < 0
- e = "$game_player"
- #Start Edits
- else
- if a[2] == "projectile"
- unless $projectiles_array.empty?
- $projectiles_array.each do |i|
- e = "$game_map.events[#{i}]"
- end
- end
- #End Edits
- else
- e = "$game_map.events[#{a[2]}]"
- end
- end
- if a[3] == nil
- d = 1
- else
- d = a[3].to_i
- end
- if a[4] == nil
- look = 0
- else
- look = a[4].to_i
- end
- @sticky_switches.push([id, e, d, look])
- end
- end
- end
- #--------------------------------------------------------------------------
- alias ss_update update
- def update
- ss_update
- update_sticky_switches
- end
- #--------------------------------------------------------------------------
- def update_sticky_switches
- for sswitch in @sticky_switches
- event = eval(sswitch[1])
- if sswitch[2] >= 0
- v = (event.x.between?(self.x-sswitch[2], self.x+sswitch[2]) and
- event.y.between?(self.y-sswitch[2], self.y+sswitch[2]))
- else
- v = true
- end
- if sswitch[3] != 0
- case sswitch[3]
- when +1 # Both Events Facing Eachother
- v &= self.facing?(event)
- when -1 # Both Events Facing Opposite Directions
- v &= self.opposite_dir?(event)
- when +2 # Event/Player is Facing Source Event
- v &= self.facingsource?(event)
- when -2 # Source Event is Facing Event/Player
- v &= self.sourcefacing?(event)
- when +3 # Event/Player is Facing Away from Event/Player
- v &= self.facingawaysource?(event)
- when -3 # Source Event is Facing Away from Event/Player
- v &= self.sourcefacingaway?(event)
- end
- end
- if sswitch[0].is_a?(String) # Self Switches
- key = [@map_id, @id, sswitch[0]]
- $game_map.need_refresh |= (v != $game_self_switches[key])
- $game_self_switches[key] = v
- else # Switches
- $game_map.need_refresh |= (v != $game_switches[sswitch[0]])
- $game_switches[sswitch[0]] = v
- end
- end
- end
- end
-
- # 1. Place any event on the map. I'll call this event self to avoid confusion.
- # 2. Open the event editor, and create a comment anywhere in the event (self).
- # 3. Type "sticky_switch" (without the quotes) in the top line of the event.
- # 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.
- # 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.
- # 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.
- # 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.
- # 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.
- # 9. Repeat steps 2-8 to add any other sticky switches, on the same page or otherwise.
- #10. Click "Ok" on the event editor page, and test your game. The switch should turn on when the event is close to self.
- # View Types 0 = Event/Player is Within Sources Range
- # 1 = Both Events Are Facing Each Other
- # -1 = Both Events Are Facing Away From Each Other
- # 2 = Event/Player is Facing Source
- # -2 = Source is Facing Event/Player
- # 3 = Event/Player is Facing Away from Event/Player
- # -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?