x = $game_player.x
y = $game_player.y
a=[];for i in 1..10
a[i]=($game_map.events[i].x-x).abs+
($game_map.events[i].y-y).abs
end;for i in 1..10
next if $game_self_switches[[
$game_map.map_id,i,"D"]]==true or
$game_map.events[i].character_name == ""
if a.min == a[i]
$target = i
end;end
x = $game_player.x
y = $game_player.y
a=[];for i in 1..10
a[i]=($game_map.events[i].x-x).abs+
($game_map.events[i].y-y).abs
end;for i in 1..10
next if $game_self_switches[[
$game_map.map_id,i,"D"]]==true or
$game_map.events[i].character_name == ""
if a.min == a[i]
$target = i
end;end