#--------------------------------------------------------
# Random Transport to any passable tile on current map
#
# Be careful. You could trap the player if you have passable
# map tiles that are surrounded by impassable tiles.
#
# call with: $game_player.rand_trans
#
# set min_dist to a minimum distance away from current spot.
#
# Also avoids any event that starts with 'M' (Monster) by the
# same distance
#
# Brewmeister - 16May08 (for Saar)
#--------------------------------------------------------
class Game_Player
def rand_trans
min_dist = 5
too_close = false
width = $game_map.width
height = $game_map.height
while true
rand_x = rand(width)
rand_y = rand(height)
dist_x = rand_x - self.x
dist_y = rand_y - self.y
distance = Math.hypot(dist_x, dist_y)
if distance < min_dist
next
end
unless $game_map.passable?(rand_x, rand_y, 0)
next
end
# check distance from all enemies
for event in $game_map.events.values
if event.name[0,1] == "M" #event name starts with M
dist_x = rand_x - event.x
dist_y = rand_y - event.y
distance = Math.hypot(dist_x, dist_y)
if distance < min_dist
too_close = true
break
end
end
end
if too_close
too_close = false
next
else
break
end
end
moveto(rand_x, rand_y)
end
end
@>Switch:[0001] = ON
@>Message: Enter a distance
@>Input Number: [0001], 2 Digits
class Game_Map
def check_event(x, y)
for event in $game_map.events.values
if event.x == x and event.y == y
return event.id
else
return nil
end
end
end
end
class Game_Player
alias new_update update
def update
new_update
if $game_switches[1] == true #number of the switch that activates teleport
if Input.press?(Input::R) == true
d = $game_variables[1] #number of variable where distance is stored
current_x = $game_player.x
current_y = $game_player.y
loop do
next_x = rand($game_map.width)
next_y = rand($game_map.height)
if d * d >= (next_x - current_x) * (next_x - current_x) + (next_y - current_y) * (next_y - current_y)
if $game_map.passable?(next_x, next_y,0, nil) == true and $game_map.valid?(next_x, next_y) == true and $game_map.check_event(next_x, next_y) == nil
$game_player.moveto(next_x, next_y)
$game_switches[1] = false
break
end
end
end
end
end
end
end
def check_event(x, y)
for event in $game_map.events.values
if event.x == x and event.y == y
return event.id
end
end
return nil
end