set %fallo 0
set %llevamucho 0
set %transcurrido 0


if #targcurs = 0
  {
    if  #LObjectId <> %mihacha
        set #LObjectId %mihacha
    Event Macro %LastObject
  }
target 3s
if #targcurs = 0
  exit

click %1 %2
for %i 1 6
 { 
                call keepalive
  if #targcurs = 0
     goto amosacortar
  wait 1
  }
set %1 %msg_noarbol
exit

amosacortar:

set %1 0
goto PasaDeApuntar


apicar:

if %TiraLogs <> SI
  {
    if %maxpeso <= #weight
     goto Journal_End
  }

 DeleteJournal
reintento:
  if %fallo > 3
     goto Journal_End
  if  #LObjectId <> %mihacha
     set #LObjectId %mihacha
  Event Macro %LastObject 0
  target 4s
  Event Macro %LastTarget 0
 PasaDeApuntar:
  set %initpicar #SCNT

; Nos sale el letrero de atacar a un azul
 if #contkind = STJC
    {
     click 376 312
     wait 2s
     click 376 312
     wait 2s
     goto Journal_End
    }

  goto clickok

clickok:
                   call keepalive
wait 10

set %tmp #scnt
set %transcurrido %tmp - %initpicar

  if %transcurrido > 7
     {
     set %fallo %fallo + 2
     wait 2s
      goto apicar
     }

set %i 0
JournalLoop:
 scanjournal %i
wait 1
if N/A in #journal
     goto clickok

if %msg_targeterror in #journal
    goto Journal_End
if %msg_nologs in #journal
    goto Journal_End
if %msg_reach in #journal
    goto Journal_End
if %msg_enhojas in #journal
    goto Journal_End
if %msg_lejos in #journal
    goto Journal_End
if %msg_noarbol in #journal
    goto Journal_End
if %msg_attackanimal in #journal
    goto Journal_End

if %msg_fail in #journal
  {
     set %llevamucho %llevamucho + 1
     if %llevamucho > 8
               goto Journal_End
     if %transcurrido < 3
          wait 6s
     goto apicar
   }

if %msg_saveworld in #journal 
 {
  DeleteJournal
  wait 20s
  goto clickok
 }

if %msg_getlog in #journal
   {
    goto apicar
   }
 
 set %i %i + 1
 if %i > 12
     {  
       DeleteJournal
       goto clickok
     }
goto JournalLoop

Journal_End: 
DeleteJournal

