Quote:Code:#===============================================================================
# ■ Hero Detection
#-------------------------------------------------------------------------------
# ver 1.00 (15/11/2008) by Plugz
#-------------------------------------------------------------------------------
class Hero_Detection
def initialize(event_id)
@event_id = event_id
end
def distance(location = true)
if location
return (($game_player.x - $game_map.events[@event_id].x) ** 2 + ($game_player.y - $game_map.events[@event_id].y) ** 2).to_f ** 0.5
else
return ($game_player.x - $game_map.events[@event_id].x) ** 2 + ($game_player.y - $game_map.events[@event_id].y) ** 2
end
end
def circle(r, switch = nil)
r *= r
if distance(false) <= r
unless switch.nil?
key = [$game_map.map_id, @event_id, switch]
$game_self_switches[key] = true
$game_map.events[@event_id].refresh
end
return true
end
end
def eclipse(width, long, switch=nil)
@x_event = $game_map.events[@event_id].x
@y_event = $game_map.events[@event_id].y
@x = $game_player.x
@y = $game_player.y
width = width.to_f/2
long = long.to_f/2
distance = (width**2-long**2).to_f**0.5
@direction = $game_map.events[@event_id].direction
if @direction == 2
@x_foyer = @x_event
@y_foyer = @y_event + distance * 2
elsif @direction == 8
@x_foyer = @x_event
@y_foyer = @y_event - distance * 2
elsif @direction == 4
@x_foyer = @x_event - distance * 2
@y_foyer = @y_event
elsif @direction == 6
@x_foyer = @x_event + distance * 2
@y_foyer = @y_event
end
@equation = (((long ** 2 + distance ** 2).to_f ** 0.5) * 2).round
@distance_hero = distance(true) + ((@x_foyer-@x) ** 2 + (@y_foyer-@y) ** 2).to_f ** 0.5
@distance_hero = @distance_hero.round
if @distance_hero <= @equation
unless switch.nil?
key = [$game_map.map_id, @event_id, switch]
$game_self_switches[key] = true
$game_map.events[@event_id].refresh
end
return true
end
end
end
@d=Hero_Detection.new(@event_id)
@d.circle(x)
Quote:"เราเข้าไปคุยกะ npc แล้ว npc จะให้เราไปหาไอเทม 1 ชิ้น ถึงจะกลับมาตอบคำถามได้ "