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
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