rebf-gaiden/Scripts/_.16.rb
2025-04-26 17:06:34 -05:00

131 lines
5.1 KiB
Ruby
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

=begin
RGSS3
★ 距離によるセルフスイッチ自動切り替え ★
イベントのセルフスイッチをプレイヤーとの距離によって
自動的に切り替えます。
● 使い方 ●========================================================
イベントの名前に以下の記述を行ってください。
SDS:<A,B,C,D>
A,B,C,Dにはそれぞれのセルフスイッチが切り替わるプレイヤーとの距離を
数値で設定します。
距離によるセルフスイッチ切り替えを行わないスイッチには
0 を設定してください。
--------------------------------------------------------------------
各セルフスイッチの距離設定に2種類のオプションを付加することが可能です。
必要な場合は距離を示す数値の直後に以下のキーワードを付加してください。
-r => スイッチの切り替わり判定が逆になります。
設定距離より離れたらON, 近づいたらOFF。
-o => プレイヤーとの距離によりONには自動で切り替わりますが、
   OFFには自動で切り替わらなくなります。
--------------------------------------------------------------------
例) SDS:<0,3-o,6,8-o-r>
セルフスイッチAに対しては何も行わない。
プレイヤーとの距離が3マス以内の場合、セルフスイッチBをON。
プレイヤーとの距離が3マスより大きい場合は何もしない。
プレイヤーとの距離が6マス以内の場合、セルフスイッチCをON。
プレイヤーとの距離が6マスより大きい場合、セルフスイッチCをOFF。
プレイヤーとの距離が8マス以内の場合は何もしない。
プレイヤーとの距離が8マスより大きい場合、セルフスイッチDをON。
====================================================================
ver1.00
Last Update : 2012/06/16
06/16 : 新規
ろかん   http://kaisou-ryouiki.sakura.ne.jp/
=end
$rsi ||= {}
$rsi["距離によるセルフスイッチ自動切り替え"] = true
class RPG::Event
def get_distance_switches_conf
match = @name.scan(/SDS:<(.*)>/)
result = []
if match.first
match.first.first.split(",").each{|split_data|
result << get_distance_switch_data(split_data)
}
end
result
end
def get_distance_switch_data(split_data)
option = 0
if split_data.include?('-r')
option += 1
split_data.delete!('-r')
end
if split_data.include?('-o')
option += 2
split_data.delete!('-o')
end
[split_data.to_i, option]
end
end
class Game_Event < Game_Character
SELF_KEY = ['A','B','C','D']
#--------------------------------------------------------------------------
# ● リフレッシュ
#--------------------------------------------------------------------------
alias _refresh_distance_switch refresh
def refresh
set_distance_switch unless @switch_distances
_refresh_distance_switch
end
#--------------------------------------------------------------------------
# ● 距離によるスイッチ切り替え情報の初期化
#--------------------------------------------------------------------------
def set_distance_switch
@switch_distances = @event.get_distance_switches_conf
end
#--------------------------------------------------------------------------
# ● プレイヤーからの距離を取得
#--------------------------------------------------------------------------
def distance_from_player
distance_x_from($game_player.x).abs + distance_y_from($game_player.y).abs
end
#--------------------------------------------------------------------------
# ● フレーム更新
#--------------------------------------------------------------------------
alias _update_distance_switch update
def update
update_switch unless @switch_distances.empty?
_update_distance_switch
end
#--------------------------------------------------------------------------
# ● 距離によるスイッチ切り替え更新
#--------------------------------------------------------------------------
def update_switch
distance = distance_from_player
@switch_distances.each_with_index{|conf_data, index|
unless conf_data[0].zero?
case conf_data[1]
when 0
result = distance <= conf_data[0]
when 1
result = distance > conf_data[0]
when 2
result = distance <= conf_data[0]
next unless result
when 3
result = distance > conf_data[0]
next unless result
end
if $game_player.stealth? == true#紅茶走加工
else #紅茶走加工
$game_self_switches[[@map_id, @event.id, SELF_KEY[index]]] = result#紅茶走加工
end#紅茶走加工
end
}
end
end