- 累计送礼:
- 0 个
- 累计收礼:
- 1 个
TA的每日心情 | 开心 2026-7-12 04:10 |
|---|
签到天数: 209 天 连续签到: 2 天 [LV.7]常住居民III

管理员
  
- VIP
- 7
- 卡币
- 58883
- OK点
- 16
- 推广点
- 0
- 同能卷
- 50
- 积分
- 68848


|
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
Spoiler 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.
本贴来自国际rpgmaker官方论坛作者:Bird Eater处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址: https://forums.rpgmakerweb.com/threads/activate-or-flip-self-switches-of-surrounding-events-or-events-with-known-coordinates.2647/ |
|