Preserved forum archive. This topic stores the original first post and locally mirrored RPG Maker Web attachments when available. It is posted by the BMMPlay archive account, not by the original creator.
Original Source
- Original title: Guard Events
- Original author: Death10
- Original date: July 18, 2012
- Source thread: https://forums.rpgmakerweb.com/threads/guard-events.3319/
- Source forum path: Game Development Engines > Ruby Game System (RGSS) Scripts > RGSS3 Scripts (RMVX Ace)
Summary
Guard Events Version: 2.0 Author: Death10*Description: A view range script. -Create guards.
Archived First Post
Guard Events
Version: 2.0
Author: Death10
*Description: A view range script.Version: 2.0
Author: Death10
-Create guards.
-Can't see through wall.
-Custom range.
-Can work with Region.
*Intructions:
1. 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.
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:
-Create a event with:
*Comment: <guard ss A range x B y C>
-A: Self Switch:
-B: Range's width.
-C: Range's height.
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:
#==============================================================================
# ** Guard Events v2.0
#------------------------------------------------------------------------------
# * A view range script
#------------------------------------------------------------------------------
# * Author: Death
# * http://taotrochoi.com
#==============================================================================
class Guard_Events
def initialize
@data = []
end
def [](pos)
@data[pos] || 0
end
def []=(pos, value)
@data[pos] = 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 [108, 408].include?(cmd.code)
case cmd.parameters[0]
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 += [[x,y,y*$game_map.width+x+1]]
end
end
$game_map.events.each_value do |event|
ev = $game_map.events[event.id]
key = [$game_map.map_id, ev.id, ev.guard_switch]
next if ev.guard == false
pos = []
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[i2+ev.viewrangex/2] += [i2]
end
for i in 1...ev.viewrangey+1
for i2 in -(ev.viewrangex/2)...(ev.viewrangex/2+1)
pos[i2+ev.viewrangex/2] += [+$game_map.width*i+i2]
end
end
when 4
for i2 in -(ev.viewrangex/2)...(ev.viewrangex/2+1)
pos[i2+ev.viewrangex/2] += [$game_map.width*i2]
end
for i in 1...ev.viewrangey+1
for i2 in -(ev.viewrangex/2)...(ev.viewrangex/2+1)
pos[i2+ev.viewrangex/2] += [-$game_map.width*i2-i]
end
end
when 6
for i2 in -(ev.viewrangex/2)...(ev.viewrangex/2+1)
pos[i2+ev.viewrangex/2] += [$game_map.width*i2]
end
for i in 1...ev.viewrangey+1
for i2 in -(ev.viewrangex/2)...(ev.viewrangex/2+1)
pos[i2+ev.viewrangex/2] += [-$game_map.width*i2+i]
end
end
when 8
for i2 in -(ev.viewrangex/2)...(ev.viewrangex/2+1)
pos[i2+ev.viewrangex/2] += [i2]
end
for i in 1...ev.viewrangey+1
for i2 in -(ev.viewrangex/2)...(ev.viewrangex/2+1)
pos[i2+ev.viewrangex/2] += [-$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[r] += [[i,ev.y*$game_map.width+ev.x+1+b]]
end
end
end
for i2 in 0...list2.size
for i in 0...ev.viewrangey
i = i*(ev.viewrangey+2)
p[i2] += [list2[i2]]
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[2] != e
next if $game_map.check_passage(b[0], b[1], 0x0f)
plist[r] = b
end
end
p[r].each do |c|
next if c[1] != plist[r][2]
pcount[r] = c[0]
end
if pcount[r][0] != nil
for i in 0...pcount[r]
rpos[r] += [a]
end
else
rpos[r] = 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[key] = true
end
end
end
$game_map.events.each_value do |event|
ev = $game_map.events[event.id]
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)][0]
ev.guard_region_left = $game_system.guard_info[$game_map.guard_pos(ev.x, ev.y)][1]
ev.guard_region_right = $game_system.guard_info[$game_map.guard_pos(ev.x, ev.y)][2]
ev.guard_region_up = $game_system.guard_info[$game_map.guard_pos(ev.x, ev.y)][3]
case ev.direction
when 2
if $game_player.region_id == ev.guard_region_down
$game_self_switches[key] = true
end
when 4
if $game_player.region_id == ev.guard_region_left
$game_self_switches[key] = true
end
when 6
if $game_player.region_id == ev.guard_region_right
$game_self_switches[key] = true
end
when 8
if $game_player.region_id == ev.guard_region_up
$game_self_switches[key] = true
end
end
end
end
end
class Game_Map
def guard_pos(x, y)
return $guard_events[y*$game_map.width+x+1]
end
def guard_set(x, y, region)
$guard_events[y*$game_map.width+x+1] = region
end
end
# ** Guard Events v2.0
#------------------------------------------------------------------------------
# * A view range script
#------------------------------------------------------------------------------
# * Author: Death
# * http://taotrochoi.com
#==============================================================================
class Guard_Events
def initialize
@data = []
end
def [](pos)
@data[pos] || 0
end
def []=(pos, value)
@data[pos] = 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 [108, 408].include?(cmd.code)
case cmd.parameters[0]
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 += [[x,y,y*$game_map.width+x+1]]
end
end
$game_map.events.each_value do |event|
ev = $game_map.events[event.id]
key = [$game_map.map_id, ev.id, ev.guard_switch]
next if ev.guard == false
pos = []
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[i2+ev.viewrangex/2] += [i2]
end
for i in 1...ev.viewrangey+1
for i2 in -(ev.viewrangex/2)...(ev.viewrangex/2+1)
pos[i2+ev.viewrangex/2] += [+$game_map.width*i+i2]
end
end
when 4
for i2 in -(ev.viewrangex/2)...(ev.viewrangex/2+1)
pos[i2+ev.viewrangex/2] += [$game_map.width*i2]
end
for i in 1...ev.viewrangey+1
for i2 in -(ev.viewrangex/2)...(ev.viewrangex/2+1)
pos[i2+ev.viewrangex/2] += [-$game_map.width*i2-i]
end
end
when 6
for i2 in -(ev.viewrangex/2)...(ev.viewrangex/2+1)
pos[i2+ev.viewrangex/2] += [$game_map.width*i2]
end
for i in 1...ev.viewrangey+1
for i2 in -(ev.viewrangex/2)...(ev.viewrangex/2+1)
pos[i2+ev.viewrangex/2] += [-$game_map.width*i2+i]
end
end
when 8
for i2 in -(ev.viewrangex/2)...(ev.viewrangex/2+1)
pos[i2+ev.viewrangex/2] += [i2]
end
for i in 1...ev.viewrangey+1
for i2 in -(ev.viewrangex/2)...(ev.viewrangex/2+1)
pos[i2+ev.viewrangex/2] += [-$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[r] += [[i,ev.y*$game_map.width+ev.x+1+b]]
end
end
end
for i2 in 0...list2.size
for i in 0...ev.viewrangey
i = i*(ev.viewrangey+2)
p[i2] += [list2[i2]]
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[2] != e
next if $game_map.check_passage(b[0], b[1], 0x0f)
plist[r] = b
end
end
p[r].each do |c|
next if c[1] != plist[r][2]
pcount[r] = c[0]
end
if pcount[r][0] != nil
for i in 0...pcount[r]
rpos[r] += [a]
end
else
rpos[r] = 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[key] = true
end
end
end
$game_map.events.each_value do |event|
ev = $game_map.events[event.id]
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)][0]
ev.guard_region_left = $game_system.guard_info[$game_map.guard_pos(ev.x, ev.y)][1]
ev.guard_region_right = $game_system.guard_info[$game_map.guard_pos(ev.x, ev.y)][2]
ev.guard_region_up = $game_system.guard_info[$game_map.guard_pos(ev.x, ev.y)][3]
case ev.direction
when 2
if $game_player.region_id == ev.guard_region_down
$game_self_switches[key] = true
end
when 4
if $game_player.region_id == ev.guard_region_left
$game_self_switches[key] = true
end
when 6
if $game_player.region_id == ev.guard_region_right
$game_self_switches[key] = true
end
when 8
if $game_player.region_id == ev.guard_region_up
$game_self_switches[key] = true
end
end
end
end
end
class Game_Map
def guard_pos(x, y)
return $guard_events[y*$game_map.width+x+1]
end
def guard_set(x, y, region)
$guard_events[y*$game_map.width+x+1] = region
end
end
*Credit:
- cozziekuns (for the Pathfinding script)
Downloads / Referenced Files
Log in to download
Log in, then follow the RPG Maker Developers Group to see these download links.
Log in to downloadLicense / Terms Note
*Credit: - cozziekuns (for the Pathfinding script)
Referenced Images / Attachments
Creator Claims / Removal
If you are the original creator and want this listing reassigned, edited, or removed, join BMMPlay and contact the moderators with proof that matches the original RPG Maker Web profile, linked GitHub, itch.io page, or another public creator identity.
Replies (0)
No replies yet.
0
replies
1
view
Topic Summary
Loading summary...