设为首页收藏本站同能贴吧 切换语言 繁体中文
开启辅助访问 切换到窄版
扫描二维码关注官方公众号
返回列表
+ 发新帖
查看: 145|回复: 0

[转载发布] Activate or flip self switches of surrounding events or events with known coordi

[复制链接]
累计送礼:
0 个
累计收礼:
1 个
  • TA的每日心情
    开心
    2026-7-12 04:10
  • 签到天数: 209 天

    连续签到: 2 天

    [LV.7]常住居民III

    9071

    主题

    864

    回帖

    6万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

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

    灌水之王

    发表于 2026-7-14 17:22:28 | 显示全部楼层 |阅读模式
    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:       
    1. ##############################################################################
    2. # A small script that lets you activate surrounding events and flip their
    3. # self switches.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
    4. # Version 1.0.0.0.0.3                                                                                                                                                                                            
    5. #                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
    6. # Use "activate(dir)" to activate a surrounding event.                                                                                                               
    7. # 'dir' can be either up, left, down, right or an array of coordinates [x,y]
    8. #                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
    9. # Use "self_switch_dir(switch, state, dir)" to flip the self switch of a                       
    10. # surrounding event.                                                                                                                                                                                                                                                                                                                                                                                                                               
    11. # 'switch' can be 'A', 'B', 'C', 'D' or others if you have a script that                       
    12. # allows you to have more self switches (don't forget the quotation marks! )
    13. # 'state' can be either true or false                                                                                                                                                                                                                                                       
    14. # 'dir' can be either up, left, down, right or an array of coordinates [x,y]
    15. #                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
    16. # Use "check_self_switch(switch, dir)" to check the state of a self switch
    17. # of an event.                                                                                                                                                                                                                                                                                                                                                                                                                                               
    18. # 'switch' can be 'A', 'B', 'C', 'D' or others if you have a script that                       
    19. # allows you to have more self switches (don't forget the quotation marks!)
    20. # 'dir' can be either up, left, down, right or an array of coordinates [x,y]
    21. # To use this in a conditional branch, insert this in the small script box:
    22. # check_self_switch(switch, dir) == state                                                                                                                                                                                                                                               
    23. # 'state' can be either true or false                                                                                                                                                                                                                                                       
    24. #                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
    25. #                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
    26. # Knock yourself out!                                                                                                                                                                                                                                                                                                                                                                                       
    27. #                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
    28. # Credits and stuff:                                                                                                                                                                                                                                                                                                                                                                                                                               
    29. # gloot for requesting me to extract this from a big pile of dump                                               
    30. # Bird Eater for making it                                                                                                                                                                                                                                                                                                                                                                       
    31. #############################################################################
    32. class Game_Interpreter
    33. # This is the script call to activate the event next to the running event.
    34. # "activate(down)" would activate the event directly south.
    35. def activate(dir)
    36.          ev = gevat(dir)
    37.          if ev != nil
    38.                  getev(ev).start
    39.          end
    40. end
    41. # This is the script call to activate the event which starting coordinates
    42. # are in the array 'dir', for example activate2([9,7]) would activate the event
    43. # which had the coordinates of x=9 and y=7 when it started.
    44. # Directions also work!
    45. # "activate2(down)" would activate the event which had the coordinates of the
    46. # tile directly south.
    47. def activate2(dir)
    48.          for i in 1...500
    49.                  if getev(i) != nil
    50.                          if getev(i).old_x == dir[0] && getev(i).old_y == dir[1]
    51.                                  getev(i).start
    52.                          end
    53.                  end
    54.          end
    55. end
    56. # Returns the ID of the event at x, y.
    57. def evat(x,y)
    58.          w = [x,y]
    59.          ev = gevat(w)
    60.          if ev != nil
    61.                  return $game_map.events_xy(x,y)[0].id
    62.          end
    63. end
    64. # Checks if there's actually an event and then returns the event.
    65. def gevat(w)
    66.          events = $game_map.events_xy(w[0],w[1])
    67.          return nil if events.empty?
    68.          events.each{ |e|
    69.                                  return e.id if e.priority_type > 0
    70.          }
    71.          return events[0].id
    72. end
    73. # Checks for the event next to it and returns coords.
    74. # This also supports longer distances; z defines the distance.
    75. def pick(e,z,dir)
    76.          ev = getev(e)
    77.          v = [ev.x,ev.y]
    78.          case dir
    79.                                  when 2; v[1] += z
    80.                                  when 4; v[0] -= z
    81.                                  when 6; v[0] += z
    82.                                  when 8; v[1] -= z
    83.          end
    84.          return v
    85. end
    86. # Defines if it's an event or the player and return accordingly.
    87. def getev(i) i > 0 ? $game_map.events[i] : $game_player
    88. end
    89. # Define the commands 'down', 'left', 'right' and 'up'.
    90. def down(e=@event_id)
    91.          return pick(e,1,2)
    92. end
    93. def left(e=@event_id)
    94.          return pick(e,1,4)
    95. end
    96. def right(e=@event_id)
    97.          return pick(e,1,6)
    98. end
    99. def up(e=@event_id)
    100.          return pick(e,1,8)
    101. end
    102. # Flips a self switch 'switch' to 'state' (true or false) of the event with
    103. # id 'evid'.
    104. def self_switch(switch, state, evid=@event_id)
    105.          if @event_id > 0
    106.                                  key = [$game_map.map_id, evid, switch]
    107.                                  $game_self_switches[key] = state
    108.          end
    109.          $game_map.need_refresh = true
    110. end
    111. # Checks the state of the self switch 'switch' of event with id 'evid'.
    112. def self_switch_state(switch, evid=@event_id)
    113.          key = [$game_map.map_id, evid, switch]
    114.          return $game_self_switches[key]
    115. end
    116. # Checks the state of the self switch 'switch' of the event in direction 'dir'.
    117. def check_self_switch(switch, dir)
    118.          evid = gevat(dir)
    119.          return self_switch_state(switch, evid)
    120. end
    121. # Checks the state of the self switch 'switch' of the event starting in
    122. # direction 'dir'.
    123. def check_self_switch2(switch, dir)
    124.          for i in 1...500
    125.                  if getev(i) != nil
    126.                          if getev(i).old_x == dir[0] && getev(i).old_y == dir[1]
    127.                                  return self_switch_state(switch, i)
    128.                          end
    129.                  end
    130.          end
    131. end
    132. # Flips a self switch 'switch' to 'state' (true or false) of the event in
    133. # direction 'dir'.
    134. def self_switch_dir(switch, state, dir)
    135.          evid = gevat(dir)
    136.          return self_switch(switch, state, evid)
    137. end
    138. # Flips a self switch 'switch' to 'state' (true or false) of the event which
    139. # starting coordinates are in the array 'dir'. Directions also work for 'dir'
    140. # See 'def activate2'...
    141. def self_switch_dir2(switch, state, dir)
    142.          for i in 1...500
    143.                  if getev(i) != nil
    144.                          if getev(i).old_x == dir[0] && getev(i).old_y == dir[1]
    145.                                  return self_switch(switch, state, i)
    146.                          end
    147.                  end
    148.          end
    149. end
    150. end
    151. class Game_Event < Game_Character
    152. # Get old coordinates
    153. def old_x
    154.          @old_x = @event.x
    155. end
    156. def old_y
    157.          @old_y = @event.y
    158. end
    159. 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/
    天天去同能,天天有童年!
    回复 送礼论坛版权

    使用道具 举报

    文明发言,和谐互动
    文明发言,和谐互动
    高级模式
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    简体中文
    繁體中文
    English(英语)
    日本語(日语)
    Deutsch(德语)
    Русский язык(俄语)
    بالعربية(阿拉伯语)
    Türkçe(土耳其语)
    Português(葡萄牙语)
    ภาษาไทย(泰国语)
    한어(朝鲜语/韩语)
    Français(法语)
    关闭

    幸运抽奖

    社区每日抽奖来袭,快来试试你是欧皇还是非酋~

    立即查看

    聊天机器人
    Loading...

    QQ|Archiver|手机版|小黑屋|同能RPG制作大师 ( 沪ICP备12027754号-3 )

    GMT+8, 2026-8-17 13:06 , Processed in 0.134935 second(s), 52 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

    快速回复 返回顶部 返回列表