じ☆ve冰风 发表于 2026-7-18 12:36:15

Guard Events

Guard Events
Version: 2.0
Author: Death10​
*Description: A view range script.

-Create guards.

-Can't see through wall.

-Custom range.

-Can work with Region.

*Intructions:

Spoiler1. Create guard:
-Create a event with:
*Comment: <guard ss A range x B y C>
-A: Self Switch:
-B: Range's width.

-C: Range's height.

https://lh4.googleusercontent.com/-XaNW8WVdAd0/UTDLfjJP5bI/AAAAAAAAAj8/lnMO9FSvj1o/s404/range.PNG

2. Create guard position: (Watch tower,...)
-Create events with:
*Options: Through = On (For the Pathfinding(cozziekuns) script in demo)
*Comment: <guard set D>
-D: Guard Regions (Read below for more informations)
-Create a autorun event with:
*Trigger = Autorun
*Script:

$game_system.guard_info = {
1 => [E, F, G, H]
}

-1: Guard Position (While standing).
-E: Region while guards look down.
-F: Region while guards look left.
-G: Region while guards look right.
-H: Region while guards look up.

-Set Region in Map Editor:


https://lh5.googleusercontent.com/-G8iChz1iiDc/UTDLgzLdKYI/AAAAAAAAAkE/ZvnHWpXXAWw/s646/region.PNG




*Script: Spoiler#==============================================================================

# ** Guard Events v2.0

#------------------------------------------------------------------------------

# * A view range script

#------------------------------------------------------------------------------

# * Author: Death

# * http://taotrochoi.com

#==============================================================================

class Guard_Events

def initialize

@data = []

end

def [](pos)

@data || 0

end

def []=(pos, value)

@data = value

on_change

end

def on_change

$game_map.need_refresh = true

end

end

class Scene_Title < Scene_Base

alias command_new_game_gv command_new_game

def command_new_game

$guard_events = Guard_Events.new

command_new_game_gv

end

end

class Game_System

attr_accessor :guard_info

alias initialize_gv initialize

def initialize

initialize_gv

@guard_info = {}

end

end

class Game_Event < Game_Character

attr_reader   :guard

attr_accessor :viewrangex

attr_accessor :viewrangey

attr_accessor :guard_switch

attr_accessor :guard_region_down

attr_accessor :guard_region_left

attr_accessor :guard_region_right

attr_accessor :guard_region_up

alias init_public_members_gv init_public_members

def init_public_members

init_public_members_gv

@guard = false

@viewrangex = 0

@viewrangey = 0

@guard_switch = nil

@guard_region_down = nil

@guard_region_left = nil

@guard_region_right = nil

@guard_region_up = nil

end

alias setup_page_guard setup_page

def setup_page(new_page)

setup_page_guard(new_page)

return if @page.nil?

@page.list.each { |cmd|

break unless .include?(cmd.code)

case cmd.parameters

when /<guard ss (.) range x (.) y (.)>/i

@guard = true

@guard_switch = $1

@viewrangex = $2.to_i

@viewrangey = $3.to_i

when /<guard set (.)>/i

$game_map.guard_set(@x, @y, $1.to_i)

end

}

end

end

class Scene_Map < Scene_Base

alias update_gv update

def update

update_gv

list = []

for x in 0...$game_map.width

for y in 0...$game_map.height

list += []

end

end

$game_map.events.each_value do |event|

ev = $game_map.events

key = [$game_map.map_id, ev.id, ev.guard_switch]

next if ev.guard == false

pos = []

pos = *(ev.viewrangex/2*2+1)

list2 = pos.clone

p = pos.clone

rpos = pos.clone

pcount = pos.clone

plist = pos.clone

case ev.direction

when 2

for i2 in -(ev.viewrangex/2)...(ev.viewrangex/2+1)

pos +=

end

for i in 1...ev.viewrangey+1

for i2 in -(ev.viewrangex/2)...(ev.viewrangex/2+1)

pos += [+$game_map.width*i+i2]

end

end

when 4

for i2 in -(ev.viewrangex/2)...(ev.viewrangex/2+1)

pos += [$game_map.width*i2]

end

for i in 1...ev.viewrangey+1

for i2 in -(ev.viewrangex/2)...(ev.viewrangex/2+1)

pos += [-$game_map.width*i2-i]

end

end

when 6

for i2 in -(ev.viewrangex/2)...(ev.viewrangex/2+1)

pos += [$game_map.width*i2]

end

for i in 1...ev.viewrangey+1

for i2 in -(ev.viewrangex/2)...(ev.viewrangex/2+1)

pos += [-$game_map.width*i2+i]

end

end

when 8

for i2 in -(ev.viewrangex/2)...(ev.viewrangex/2+1)

pos +=

end

for i in 1...ev.viewrangey+1

for i2 in -(ev.viewrangex/2)...(ev.viewrangex/2+1)

pos += [-$game_map.width*i+i2]

end

end

end 

pos.each do |a|

for i in 0...pos.size

if pos == a

r = i

end

end

a.each do |b|

for i in 0...a.size

list2 += []

end

end

end

for i2 in 0...list2.size

for i in 0...ev.viewrangey

i = i*(ev.viewrangey+2)

p += ]

end

end

pos.each do |a|

for i in 0...pos.size

if pos == a

r = i

end

end

for pp in a

e = ev.y*$game_map.width+ev.x+pp+1

list.each do |b|

next if b != e

next if $game_map.check_passage(b, b, 0x0f)

plist = b

end

end

p.each do |c|

next if c != plist

pcount = c

end

if pcount != nil

for i in 0...pcount

rpos += ]

end

else

rpos = a

end

end

pos = []

for i in 0...rpos.size

pos += rpos

end

for c in pos

e = ev.y*$game_map.width+ev.x+c+1

p2 = $game_player.y*$game_map.width+$game_player.x+1

if p2 == e

ev.turn_toward_player

$game_self_switches = true

end

end

end

$game_map.events.each_value do |event|

ev = $game_map.events

key = [$game_map.map_id, ev.id, ev.guard_switch]

next if ev.guard == false    

next if $game_map.guard_pos(ev.x, ev.y) < 1

ev.guard_region_down = $game_system.guard_info[$game_map.guard_pos(ev.x, ev.y)]

ev.guard_region_left = $game_system.guard_info[$game_map.guard_pos(ev.x, ev.y)]

ev.guard_region_right = $game_system.guard_info[$game_map.guard_pos(ev.x, ev.y)]

ev.guard_region_up = $game_system.guard_info[$game_map.guard_pos(ev.x, ev.y)]

case ev.direction

when 2

if $game_player.region_id == ev.guard_region_down

$game_self_switches = true

end

when 4

if $game_player.region_id == ev.guard_region_left

$game_self_switches = true

end

when 6

if $game_player.region_id == ev.guard_region_right

$game_self_switches = true

end

when 8

if $game_player.region_id == ev.guard_region_up

$game_self_switches = true

end

end

end

end

end

class Game_Map

def guard_pos(x, y)

return $guard_events

end

def guard_set(x, y, region)

$guard_events = region

end

end



*Demo:http://www.mediafire.com/?a2ppxu6gjbu2uh8
*Credit:
- cozziekuns (for the Pathfinding script)


本贴来自国际rpgmaker官方论坛作者:Death10处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/guard-events.3319/
页: [1]
查看完整版本: Guard Events