Remote Control Over Events?

Woa! Thanks Bird Eater. This tip gonna be really useful!

I never thought of a event triggering another by proximity. You could use this to make a big chain-reaction-style event? Even though I didn't had this idea, now that you mention it, it made me curious. I sure wouldn't mind having that kind of knowledge if you are willing to share it! =D
Uhm yeah, sure thing.

I submitted the script to the rgss3 subforum thingy, but it has to be approved of first...

So here it is:

Spoiler
##############################################################################

# A small script that lets you activate surrounding events and flip their #

# self switches. #

# Version 1.0.0.0.0.0 #

# #

# Use "activate(dir)" to activate a surrounding event. #

# 'dir' can be either up, left, down, right or an array of coordinates [x,y] #

# #

# Use "self_switch_dir(switch, state, dir)" to flip the self switch of a #

# surrounding event. #

# 'switch' can be 'A', 'B', 'C', 'D' or others if you have a script that #

# allows you to have more self switches (don't forget the quotation marks! #

# 'state' can be either true or false #

# 'dir' can be either up, left, down, right or an array of coordinates [x,y] #

# #

# Use "check_self_switch(switch, dir)" to check the state of a self switch #

# of an event. #

# 'switch' can be 'A', 'B', 'C', 'D' or others if you have a script that #

# allows you to have more self switches (don't forget the quotation marks!) #

# 'dir' can be either up, left, down, right or an array of coordinates [x,y] #

# To use this in a conditional branch, insert this in the small script box: #

# check_self_switch(switch, dir) == state #

# 'state' can be either true or false #

# #

# #

# Knock yourself out! #

# #

# Credits and stuff: #

# gloot for requesting me to extract this from a big pile of dump #

# Bird Eater for making it #

##############################################################################

class Game_Interpreter

# This is the script call to activate the event next to the running event.

# "activate(down)" would activate the event directly south.

def activate(dir)

ev = gevat(dir)

if ev != nil

getev(ev).start

end

end

# Returns the ID of the event at x, y.

def evat(x,y)

w = [x,y]

ev = gevat(w)

if ev != nil

return $game_map.events_xy(x,y)[0].id

end

end

# Checks if there's actually an event and then returns the event.

def gevat(w)

events = $game_map.events_xy(w[0],w[1])

return nil if events.empty?

events.each{ |e|

return e.id if e.priority_type > 0

}

return events[0].id

end

# Checks for the event next to it and returns coords.

# This also supports longer distances; z defines the distance.

def pick(e,z,dir)

ev = getev(e)

v = [ev.x,ev.y]

case dir

when 2; v[1] += z

when 4; v[0] -= z

when 6; v[0] += z

when 8; v[1] -= z

end

return v

end

# Defines if it's an event or the player and return accordingly.

def getev(i) i > 0 ? $game_map.events : $game_player

end

# Define the commands 'down', 'left', 'right' and 'up'.

def down(e=@event_id)

return pick(e,1,2)

end

def left(e=@event_id)

return pick(e,1,4)

end

def right(e=@event_id)

return pick(e,1,6)

end

def up(e=@event_id)

return pick(e,1,8)

end

# Flips a self switch 'switch' to 'state' (true or false) of the event with

# id 'evid'.

def self_switch(switch, state, evid=@event_id)

if @event_id > 0

key = [$game_map.map_id, evid, switch]

$game_self_switches[key] = state

end

$game_map.need_refresh = true

end

# Checks the state of the self switch 'switch' of event with id 'evid'.

def self_switch_state(switch, evid=@event_id)

key = [$game_map.map_id, evid, switch]

return $game_self_switches[key]

end

# Checks the state of the self switch 'switch' of the event in direction 'dir'.

def check_self_switch(switch, dir)

evid = gevat(dir)

return self_switch_state(switch, evid)

end

# Flips a self switch 'switch' to 'state' (true or false) of the event in

# direction 'dir'.

def self_switch_dir(switch, state, dir)

evid = gevat(dir)

return self_switch(switch, state, evid)

end

end
Hey! That's great! The fact that you can use a switch instead of activating make it really easy to make the event inaccessible to the action button of the user. Thanks, Bird Eater!
Thank you for your help, Bird Eater.

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/remote-control-over-events.2601/