I have seen a lot of Youtube videos and demos that make it look like enemies are chasing on you the map. i just can't perfect it to where they actually have to touch you in order to engage in
combat. They will approach from two squares and then they'll still tag me somehow, and if two enemies are nearby on the screen even after a battle the game locks up.
here is the code I used as :
Proximity Detection Script v1.5
module Proxy
#Default radius of detection:
PROXYRANGE = 4
#Region for transparent obstacles
REGION = 20
#Switch to be turned on to pause Proximity
PAUSE_SWITCH = 100
#----#
def self.inprox?(id, distance = PROXYRANGE, los = true, second_id = nil)
return if $game_switches[PAUSE_SWITCH]
x = $game_map.events[id].x
y = $game_map.events[id].y
if !second_id
x2 = $game_player.x; y2 = $game_player.y
else
x2 = $game_map.events[second_id].x;y2 = $game_map.events[second_id].y
end
x_d = x - x2; y_d = y - y2
x_d *= -1 if x_d < 0; y_d *= -1 if y_d < 0
t_d = x_d + y_d
return false if t_d > distance
return false if !line_of_sight($game_player.x,$game_player.y,x,y) and los
return true
end
def self.inprox_d?(id, distance = PROXYRANGE, los = true)
if self.inprox?(id, distance, los) then else return false end
x1 = $game_player.x; x2 = $game_map.events[id].x
y1 = $game_player.y; y2 = $game_map.events[id].y
x1 > x2 ? xx = x1 - x2 : xx = x2 - x1
y1 > y2 ? yy = y1 - y2 : yy = y2 - y1
case $game_map.events[id].direction
when 2
if $game_player.y > $game_map.events[id].y then
if yy >= xx then return true end end
when 4
if $game_player.x < $game_map.events[id].x then
if xx >= yy then return true end end
when 6
if $game_player.x > $game_map.events[id].x then
if xx >= yy then return true end end
when 8
if $game_player.y < $game_map.events[id].y then
if yy >= xx then return true end end
end
return false
end
def self.inprox_r?(id, width, height)
return if $game_switches[PAUSE_SWITCH]
width % 2 == 0 ? hwidth = width / 2 : hwidth = (width - 1) / 2
height % 2 == 0 ? hheight = height / 2 : hheight = (height - 1) / 2
x = $game_map.events[id].x - hwidth
y = $game_map.events[id].y - hheight
if $game_player.x >= x and $game_player.x < (x + width)
if $game_player.y >= y and $game_player.y < (y + height)
return true
end
end
return false
end
def self.line_of_sight(x,y,x2,y2)
tile_array = []
x_d = x - x2; y_d = y - y2
x_d *= -1 if x_d < 0
y_d *= -1 if y_d < 0
t_d = x_d + y_d
t_d.times do |i|
x_distance = x - x2
y_distance = y - y2
x_distance *= -1 if x_distance < 0
y_distance *= -1 if y_distance < 0
if x_distance > y_distance or y_distance == 0
x < x2 ? x += 1 : x -= 1
elsif
y < y2 ? y += 1 : y -= 1 or x_distance == 0
end
tile_array.push([x,y])
end
tile_array.each do |cord|
next if $game_map.region_id(cord[0],cord[1]) == REGION
return false if !$game_map.check_passage(cord[0], cord[1], 0x002)
end
return true
end
end
I am not knowledge in ruby as of yet, I got this from a youtube channel actually. But if there is a better way to fix this or a better method to make enemies have to touch the player directly in order for
combat to engage. I also need help with a behavior for zombies to be attracted to players from a distance.
thanks in advance as always.
combat. They will approach from two squares and then they'll still tag me somehow, and if two enemies are nearby on the screen even after a battle the game locks up.
here is the code I used as :
Proximity Detection Script v1.5
module Proxy
#Default radius of detection:
PROXYRANGE = 4
#Region for transparent obstacles
REGION = 20
#Switch to be turned on to pause Proximity
PAUSE_SWITCH = 100
#----#
def self.inprox?(id, distance = PROXYRANGE, los = true, second_id = nil)
return if $game_switches[PAUSE_SWITCH]
x = $game_map.events[id].x
y = $game_map.events[id].y
if !second_id
x2 = $game_player.x; y2 = $game_player.y
else
x2 = $game_map.events[second_id].x;y2 = $game_map.events[second_id].y
end
x_d = x - x2; y_d = y - y2
x_d *= -1 if x_d < 0; y_d *= -1 if y_d < 0
t_d = x_d + y_d
return false if t_d > distance
return false if !line_of_sight($game_player.x,$game_player.y,x,y) and los
return true
end
def self.inprox_d?(id, distance = PROXYRANGE, los = true)
if self.inprox?(id, distance, los) then else return false end
x1 = $game_player.x; x2 = $game_map.events[id].x
y1 = $game_player.y; y2 = $game_map.events[id].y
x1 > x2 ? xx = x1 - x2 : xx = x2 - x1
y1 > y2 ? yy = y1 - y2 : yy = y2 - y1
case $game_map.events[id].direction
when 2
if $game_player.y > $game_map.events[id].y then
if yy >= xx then return true end end
when 4
if $game_player.x < $game_map.events[id].x then
if xx >= yy then return true end end
when 6
if $game_player.x > $game_map.events[id].x then
if xx >= yy then return true end end
when 8
if $game_player.y < $game_map.events[id].y then
if yy >= xx then return true end end
end
return false
end
def self.inprox_r?(id, width, height)
return if $game_switches[PAUSE_SWITCH]
width % 2 == 0 ? hwidth = width / 2 : hwidth = (width - 1) / 2
height % 2 == 0 ? hheight = height / 2 : hheight = (height - 1) / 2
x = $game_map.events[id].x - hwidth
y = $game_map.events[id].y - hheight
if $game_player.x >= x and $game_player.x < (x + width)
if $game_player.y >= y and $game_player.y < (y + height)
return true
end
end
return false
end
def self.line_of_sight(x,y,x2,y2)
tile_array = []
x_d = x - x2; y_d = y - y2
x_d *= -1 if x_d < 0
y_d *= -1 if y_d < 0
t_d = x_d + y_d
t_d.times do |i|
x_distance = x - x2
y_distance = y - y2
x_distance *= -1 if x_distance < 0
y_distance *= -1 if y_distance < 0
if x_distance > y_distance or y_distance == 0
x < x2 ? x += 1 : x -= 1
elsif
y < y2 ? y += 1 : y -= 1 or x_distance == 0
end
tile_array.push([x,y])
end
tile_array.each do |cord|
next if $game_map.region_id(cord[0],cord[1]) == REGION
return false if !$game_map.check_passage(cord[0], cord[1], 0x002)
end
return true
end
end
I am not knowledge in ruby as of yet, I got this from a youtube channel actually. But if there is a better way to fix this or a better method to make enemies have to touch the player directly in order for
combat to engage. I also need help with a behavior for zombies to be attracted to players from a distance.
thanks in advance as always.