#==============================================================================
# ■ 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
# Start Edits
events = []
chars = a[2].strip.split(',')
for c in chars
if c == nil or c.to_i < 0
events.push("$game_player")
elsif c == "p" or c == "projectiles"
events.push("projectiles")
else
events.push("$game_map.events[#{c}]")
end
end
# End Edits
if a[3] == nil
dir = 1
else
dir = a[3].to_i
end
if a[4] == nil
look = 0
else
look = a[4].to_i
end
@sticky_switches.push([id, events, dir, look])
end
end
end
#--------------------------------------------------------------------------
alias ss_update update
def update
ss_update
return if @sticky_switches.empty?
update_sticky_switches
end
#--------------------------------------------------------------------------
def update_sticky_switches
for sswitch in @sticky_switches
# Start Edits
v = false
events = sswitch[1].dup
if events.include?("projectiles")
unless $projectiles_array.empty?
$projectiles_array.each do |i|
events.push("$game_map.events[#{i}]")
end
end
events.delete("projectiles")
end
for e in events
event = eval(e) # change from string to object
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
break if v == true
end
# End Edits
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