Activate or flip self switches of surrounding events or events with known coordinates

Bird Eater

Boredom is just another thing you want to avoid
Veteran
Joined
Mar 22, 2012
Messages
272
Reaction score
27
First Language
Dutch
Primarily Uses
Activate or flip self switches of surrounding events or events with known coordinates - version 1.0.0.0.0.3

By Bird Eater

Introduction

Well, I made this some time ago, and a gentleman by the name of gloot kind of indirectly asked me to post it.

Features

Activate anything, everything and all that normally requires the player to stand next to the event and press the action button.

Also flips self switches.

Screenshots

Well, not really necessary, I believe...

How to Use

Use "activate(dir)" in a script call 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)" in a script call to flip the self switch of a surrounding event.

'switch' can be 'A', 'B', 'C', 'D' or more 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 more 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

Demo

Whenever I feel like making one.

Script

Code:
##############################################################################
# A small script that lets you activate surrounding events and flip their
# self switches.																																																											
# Version 1.0.0.0.0.3                                                                                                                                                                                            
#																																																																						
# 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
# This is the script call to activate the event which starting coordinates
# are in the array 'dir', for example activate2([9,7]) would activate the event
# which had the coordinates of x=9 and y=7 when it started.
# Directions also work!
# "activate2(down)" would activate the event which had the coordinates of the
# tile directly south.
def activate2(dir)
	 for i in 1...500
		 if getev(i) != nil
			 if getev(i).old_x == dir[0] && getev(i).old_y == dir[1]
				 getev(i).start
			 end
		 end
	 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[i] : $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
# Checks the state of the self switch 'switch' of the event starting in
# direction 'dir'.
def check_self_switch2(switch, dir)
	 for i in 1...500
		 if getev(i) != nil
			 if getev(i).old_x == dir[0] && getev(i).old_y == dir[1]
				 return self_switch_state(switch, i)
			 end
		 end
	 end
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
# Flips a self switch 'switch' to 'state' (true or false) of the event which
# starting coordinates are in the array 'dir'. Directions also work for 'dir'
# See 'def activate2'...
def self_switch_dir2(switch, state, dir)
	 for i in 1...500
		 if getev(i) != nil
			 if getev(i).old_x == dir[0] && getev(i).old_y == dir[1]
				 return self_switch(switch, state, i)
			 end
		 end
	 end
end
end
class Game_Event < Game_Character
# Get old coordinates
def old_x
	 @old_x = @event.x
end
def old_y
	 @old_y = @event.y
end
end
Credit and Thanks

- Bird Eater for making it

- gloot for requesting it

Author's Notes

You could uhm, credit me in your game... I- It- It's not like I want you to, or anything-! But... it would be nice...

Also available for commercial use as long as I receive a message, cookies and a free copy.

Go and be cool, people.

Ask anything you want to ask in this thread.
 
Last edited by a moderator:

Axel Mherkor

Villager
Member
Joined
Sep 2, 2012
Messages
5
Reaction score
1
First Language
Spanish
Primarily Uses
If I want to use it with moving events is there any way to change it to make it use for the original coordinates of the event instead of the current ones?
 

Bird Eater

Boredom is just another thing you want to avoid
Veteran
Joined
Mar 22, 2012
Messages
272
Reaction score
27
First Language
Dutch
Primarily Uses
Done, use 'activate2([x,y])' in a script call to activate the event which started at the tile with coordinates x and y.

You can also use 'activate2(down)', 'activate2(up)', 'activate2(left)', 'activate2(right)' to activate the event which started next to where the event running this command is currently at, in the relevant direction.

Also made 'self_switch_dir2(switch,state,[x,y])' which works the same way as self_switch_dir but now with the original starting position as the [x,y] array, just like 'activate2' did for 'activate'. You can also use directions instead of [x,y].

Have fun, hope you can use it.
 

Axel Mherkor

Villager
Member
Joined
Sep 2, 2012
Messages
5
Reaction score
1
First Language
Spanish
Primarily Uses
It crashes when I use it... I put this to use it:



Code:
self_switch_dir2('A', true, [13,4])
and when I call the event it appears:

Script 'Game_Interpreter' line 1409: NoMethodError ocurred.undefined method `event' for #<Game_Event:0x92c4f1>
this line is this:



Code:
def command_355
script = @list[@index].parameters[0] + "\n"
while next_event_code == 655
	 @index += 1
	 script += @list[@index].parameters[0] + "\n"
end
eval(script) #<-----
end
 
Last edited by a moderator:

Bird Eater

Boredom is just another thing you want to avoid
Veteran
Joined
Mar 22, 2012
Messages
272
Reaction score
27
First Language
Dutch
Primarily Uses
My bad, fixed it. I hope it works now :o
 

Axel Mherkor

Villager
Member
Joined
Sep 2, 2012
Messages
5
Reaction score
1
First Language
Spanish
Primarily Uses
Thaaanks :D It works now :D

Edit: There isn't any function to check the original point.
 
Last edited by a moderator:

Bird Eater

Boredom is just another thing you want to avoid
Veteran
Joined
Mar 22, 2012
Messages
272
Reaction score
27
First Language
Dutch
Primarily Uses
Done, call it with: check_self_switch2(switch,dir)

'switch' is the self-switch you want to check,

'dir' is the array of coordinates or direction the event started at.
 
Last edited by a moderator:

Axel Mherkor

Villager
Member
Joined
Sep 2, 2012
Messages
5
Reaction score
1
First Language
Spanish
Primarily Uses
Thanks :D Now the script works perfect :D

I don't know if I would finish the game I am making, but if I finish it's everything thanks to your script. I really hate having tons of global interrupts in my projects. It makes me feel dizzy :S
 

Riyshn

Villager
Member
Joined
Dec 26, 2012
Messages
8
Reaction score
0
First Language
English
Primarily Uses
Um... Either I'm doing something wrong, it the script doesn't work inside of Move Route commands. Works fine if it's standalone, but crashes if it's called from inside a Move Route.
 

Bird Eater

Boredom is just another thing you want to avoid
Veteran
Joined
Mar 22, 2012
Messages
272
Reaction score
27
First Language
Dutch
Primarily Uses
That's because Move Route commands work differently, they don't use methods from the Game_Interpreter class.

You'll have to break up your Move Route command in two parts, I'm afraid.
 

Riyshn

Villager
Member
Joined
Dec 26, 2012
Messages
8
Reaction score
0
First Language
English
Primarily Uses
Should probably make a note of that in the How To Use section up there.

Ok though, splitting the Move Routes isn't too big a deal.
 

Bird Eater

Boredom is just another thing you want to avoid
Veteran
Joined
Mar 22, 2012
Messages
272
Reaction score
27
First Language
Dutch
Primarily Uses
So that means everyone who ever makes a script that uses some kind of script call (that's a lot, mind you) will have to put up a sign saying: "Hey, don't use this in a Move Route event before figuring out that just won't work!"

I don't really feel like doing that. At all.
 

Riyshn

Villager
Member
Joined
Dec 26, 2012
Messages
8
Reaction score
0
First Language
English
Primarily Uses
CTRL+C. Edit. CTRL +V. Done.

You didn't need to be rude. I was just saying that your 10 seconds of typing there could have saved me and most likely others from 20+ minutes of wondering WTF we're doing wrong. Also, kinda bad form to have a known thing that would make the script fail and not mention it.
 
Last edited by a moderator:

Bird Eater

Boredom is just another thing you want to avoid
Veteran
Joined
Mar 22, 2012
Messages
272
Reaction score
27
First Language
Dutch
Primarily Uses
I know how long it takes to add it, don't worry about that.

The problem lies not with my attitude or rudeness, at all. Rather, I believe was being fairly kind.

Also, kinda bad form to have a known thing that would make the script fail and not mention it.
It is known as in 'everybody knows it, or should be able to figure it out in a minute and use it forever in their rpg maker life'.

could have saved me and most likely others from 20+ minutes of wondering WTF we're doing wrong
I'm afraid it's just you. It literally takes 1 minute to test if something works, and then figure out it doesn't, at which point you should think "Oh, perhaps I shouldn't try this same thing for another 20 minutes because then it might miraculously work!"

This is a known thing. It doesn't Frick up your life in any way and yet we've come to this point.

Ok though, splitting the Move Routes isn't too big a deal.
Because this takes the fricking cake.

"Oh well, this plebeian is not disrupting my hard work in the worst way, I suppose I will only let him know with this post that he mayn't use such foul words with me, the great Riyshn, again!"

You're not a king. Heck, Not everyone's here to make your sole damn rpg life easier. Should I remember you that you're using my stuff, not the other way round?

Scripters in this section do not get anything for making scripts, not a single penny. I don't necessarily need you to say "thanks" (would've been appreciated though), but I absolutely don't want you to say that I somehow wasted your time by not having something said about a script you're using. A script that actually helps you.

No, sir, you are wasting my time.

I sincerely believe you're the one who's being rude here.

Please appreciate the work of others in the future, and not complain about something so trivial in such a manner. Thank you.
 
Last edited by a moderator:

Latest Threads

Latest Posts

Latest Profile Posts

The self-righteous indignation of family when you expect them to pay back money you've leant to them never ceases to amaze me.
Gamedev for relaxing? yes or no?
I've been having a rough couple of months and as such let down some friends of mine in the RPG Maker community. I still need time to get back to my normal self, but it's nice to be back, to read articles, and to design again (albeit at a slow pace). Hope to give updates on Kid Crescent soon.
Friendly reminder that you don't have to be able to do absolutely everything. It's okay to scale back features or assets if things are too much - especially if you're the only one working on the game! And you can always add things in later. <3
My new cutscene system makes it so much easier to add parallel stuff happening in the background, I can easily fill the whole screen with action.

Forum statistics

Threads
107,734
Messages
1,031,736
Members
139,868
Latest member
enterjc
Top