有做
明雷遇敵或是有
你追我跑事件的玩家應該會遇到這種現象:
明明肉眼看上去
A無法走到B那邊但就因為
兩者相鄰結果就觸發事件了,這腳本就是解決這狀況
簡單說就是讓事件觸發多了
高低差認知,至少當初目的是這樣
只是很遺憾,
這腳本有Bug,不過注意一下就能迴避掉
腳本:
#==============================================================================
# ■ Game_Player
#------------------------------------------------------------------------------
# 處理主角的類別。事件啟動的判定、以及地圖的滾動等功能。
# 本類別的實例請參考 $game_player。
#==============================================================================
class Game_Player < Game_Character
#--------------------------------------------------------------------------
# ● 常量
#--------------------------------------------------------------------------
CLIFF_TAG = 7 # 懸崖地形
#--------------------------------------------------------------------------
# ● 正面事件的啟動判定
#--------------------------------------------------------------------------
def check_event_trigger_there(triggers)
result = false
# 事件執行中的情況下
if $game_system.map_interpreter.running?
return result
end
# 計算正面座標
new_x = @x
new_y = @y
# 確認目標位置
tx = @x + (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
ty = @y + (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
# 目標所在地形
tg = $game_map.terrain_tag(tx, ty)
# 非懸崖的情況判定往前一格
if !terrain_passable?(new_x, new_y, @direction) and tg == CLIFF_TAG or terrain_tag == CLIFF_TAG
else
new_x += (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
new_y += (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
end # 全部事件的循環
for event in $game_map.events.values
# 事件座標與目標一致的情況下
if event.x == new_x and event.y == new_y and
triggers.include?(event.trigger)
# 跳躍中以外的情況下、啟動判定是正面的事件
if not event.jumping? and not event.over_trigger?
event.start
result = true
end
end
end
# 找不到符合條件的事件的情況下
if result == false
# 正面的元件是"櫃台"的情況下
if $game_map.counter?(new_x, new_y)
# 計算 1 元件裡側的座標
new_x += (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
new_y += (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
# 全事件的循環
for event in $game_map.events.values
# 事件座標與目標一致的情況下
if event.x == new_x and event.y == new_y and
triggers.include?(event.trigger)
# 跳躍中以外的情況下、啟動判定是正面的事件
if not event.jumping? and not event.over_trigger?
event.start
result = true
end
end
end
end
end
return result
end
end
#==============================================================================
# ■ Game_Character (分割定義 2)
#------------------------------------------------------------------------------
# 碰撞判定加入地形判別
#==============================================================================
class Game_Character
#--------------------------------------------------------------------------
# ● 新增方法:地型可以通行判定(強化"與事件接觸"和"決定鍵觸發")
# x : X 座標
# y : Y 座標
# d : 方向 (0,2,4,6,8) ※ 0 = 全部方向不能通行的情況判定 (跳躍用)
#--------------------------------------------------------------------------
def terrain_passable?(x, y, d)
# 求得新的座標
new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
# 座標在地圖以外的情況
unless $game_map.valid?(new_x, new_y)
# 不能通行
return false
end
# 穿透是 ON 的情況下
if @through
# 可以通行
return true
end
# 移動者的元件無法來到指定方向的情況下
unless $game_map.passable?(x, y, d, self)
# 通行不可
return false
end
# 從指定方向不能進入到移動處的元件的情況下
unless $game_map.passable?(new_x, new_y, 10 - d)
# 不能通行
return false
end
# 可以通行
return true
end
#--------------------------------------------------------------------------
# ● 向下移動 (再定義)
# turn_enabled : 本場地位置變更許可標誌
#--------------------------------------------------------------------------
def move_down(turn_enabled = true)
# 面向下
if turn_enabled
turn_down
end
# 可以通行的場合
if passable?(@x, @y, 2)
# 面向下
turn_down
# 更新座標
@y += 1
# 增加步數
increase_steps
# 不能通行的情況下
elsif !terrain_passable?(@x, @y, 2)
else # 接觸事件的啟動判定
check_event_trigger_touch(@x, @y+1)
end
end
#--------------------------------------------------------------------------
# ● 向左移動 (再定義)
# turn_enabled : 本場地位置變更許可標誌
#--------------------------------------------------------------------------
def move_left(turn_enabled = true)
# 面向左
if turn_enabled
turn_left
end
# 可以通行的情況下
if passable?(@x, @y, 4)
# 面向左
turn_left
# 更新座標
@x -= 1
# 增加步數
increase_steps
# 不能通行的情況下
elsif !terrain_passable?(@x, @y, 4)
else # 接觸事件的啟動判定
check_event_trigger_touch(@x-1, @y)
end
end
#--------------------------------------------------------------------------
# ● 向右移動 (再定義)
# turn_enabled : 本場地位置變更許可標誌
#--------------------------------------------------------------------------
def move_right(turn_enabled = true)
# 面向右
if turn_enabled
turn_right
end
# 可以通行的場合
if passable?(@x, @y, 6)
# 面向右
turn_right
# 更新座標
@x += 1
# 增加部數
increase_steps
# 不能通行的情況下
elsif !terrain_passable?(@x, @y, 6)
else # 接觸事件的啟動判定
check_event_trigger_touch(@x+1, @y)
end
end
#--------------------------------------------------------------------------
# ● 向上移動 (再定義)
# turn_enabled : 本場地位置變更許可標誌
#--------------------------------------------------------------------------
def move_up(turn_enabled = true)
# 面向上
if turn_enabled
turn_up
end
# 可以通行的情況下
if passable?(@x, @y, 8)
# 面向上
turn_up
# 更新座標
@y -= 1
# 步數增加
increase_steps
# 不能通行的情況下
elsif !terrain_passable?(@x, @y, 8)
else # 接觸事件的啟動判定
check_event_trigger_touch(@x, @y-1)
end
end
end
使用法:腳本安裝後,先確定腳本
CLIFF_TAG 的值,
之後到資料庫的地圖元件中,把你認為是懸崖地形的圖塊全部設定與
CLIFF_TAG 的數字相同
如圖,因為預設是7所以設為7
然後就大功告成
使用效果如下(以下情況皆不會觸發事件):1.(對調可)
2.打不開箱子(對調可)
BUG:角色站在懸崖地形,箱子打不開迴避法:別把事件放在角色會走到懸崖地形的位置
原理說明:接觸啟動的事件會預測下一步的座標,只是因為內建似乎沒把
能否從A點走到B點的狀況考慮進去,所以預測出的下一格如果存在事件(或玩家)就觸發了。
本來以為只要多加個通行判斷就好,但又發現得額外解決
相鄰後按下決定鍵的處理,於是...於是忘了,地圖場景類的腳本一直是我的噩夢。他很複雜、他非常複雜,我覺得戰鬥場景類可愛多了。
總之除了通行判斷外,還得額外處理「決定鍵觸發」,最後就變成得多設一個地形標誌了
衝突:頗大,改了角色上下左右移動判斷,以及面向事件時的觸發判定
很遺憾因為新增內容必須寫在條件分歧或運算過程中,無法設定alias
腳本紅字處為新增或是修改後的內容,若發生衝突得解決時,請比對原始內容,將腳本植入適當位置
改造項目:類:Game_Character、Game_Player
方法(參數省略):check_event_trigger_there、move_down、move_left、move_right、move_up
新增方法:terrain_passable?
範例:https://mega.nz/#!5RZHFZYS!7ZqK4DmYyvwI54uSlt4gpAGQ_4Z-u2vFYpVDiHObIio