;Moviendose.
; Este script ira moviendose paso a paso.
; Si alguna vez llega a una esquina de la zona, anda unos pasos al N o al S,
; da media vuelta, y sigue moviendose paso a paso hacia el sentido contrario

set %prevx #charposx
set %prevy #charposy

set %nextx %prevx + %dirx
set %nexty %prevy

move %nextx %nexty a 4s
if %prevx = #charposx
  {
   if %prevy = #charposy
     {
       if %dirx = 1
         {
          click 385 294 r
          wait 5
          click 385 294 r
          }       
       if %dirx = -1
         {
          click 259 190 r
          wait 5
          click 259 190 r
          }
     }
   }


if #charposx <= %Z1SOx
 {
   if %dirx < 0
     { 
       set %outzona 1
       set %dirx %dirx * -1
     }
 }
if #charposx >= %Z1NEx
 {
 if %dirx > 0
     { 
      set %outzona 1
      set %dirx %dirx * -1
     }
 }
if #charposy <= %Z1NEy
 {
 if %diry < 0
     { 
       if #charposy < %Z1NEy
         set %outzona 1
       set %diry %diry * -1
     }
 }
if #charposy >= %Z1SOy
 {
 if %diry > 0
     { 
      if #charposy > %Z1SOy
        set %outzona 1
      set %diry %diry * -1
     }
 }


If %outzona = 0
  exit

;Nos hemos salido de los limites
set %nextx #charposx
set %nexty #charposy + %diry

if %nextx > %Z1NEx
  set %nextx %Z1NEx
if %nextx < %Z1SOx
  set %nextx %Z1SOx
if %nexty < %Z1NEy
    set %nexty %Z1NEy
if %nexty > %Z1SOy
    set %nexty %Z1SOy

move %nextx %nexty a 7s
set %outzona 0
