If %InitOK = 1
  goto guardstart

; ***********************************************
;   SISTEMA DE DEFENSA PERSONAL  v0.1   Por Ishan
; ***********************************************

; El proposito de este script es el de evitar que
;los malos malosos te hagan cosas malitas mientras
;no estas delante del ordenador


; Funcionalidades
;  +Si te hacen dao intentara curarse mediante
;    vendas o con hechizo
;  +Si te envenenan intentara curarse con hechizo
;  +Llama a los guardias 
;  +Esquiva balas como el de Matrix (bueno esto aun no)

; **************** PROGRAMA PRINCIPAL *****************
; Ya no necesitas tocar nada mas
wait 9
msg $/ GUARDAESPALDAS activo$

set %vida 0

guardstart:
 set %minlife #str * %MinimoDeVida 
 set %minlife %minlife / 100


if %vida > #str
   set %vida = #str

if #hits < %Minlife
   {
     if %guardmusic = 1
      {
        if %Musica = 0
           {
             playcd
             set %Musica 1
           }
       }
    }

if #hits = 0
   {
    ; paramos la macro principal. Poco podemos hace :D
     set *55 1
   
     if %vida <> -1
      {
        if %sacofoto = 1
          gosub sacarfoto
        if %guardmusic = 1
        if %Musica = 0
           {
             playcd
             set %Musica 1
           }
      }
     set %vida -1
     pause
     if *55 = 1
       set *55 0

     return
   }

if %vida < #hits
  set %vida #hits

if %vida > 100
   set %vida = 100

 if P in #charstatus
   {
   if %sacofoto = 1
     gosub sacarfoto
    wait 1s
; An Nox
    set #LSPELL 10
    key %lastspell
   }   


for %tm 1 5
 {
  scanjournal %tm
  if  detectvenom in #journal
     goto noscanvenom
 if %msg_poisoned in #journal
   {
 if %sacofoto = 1
     gosub sacarfoto
    wait 1s
    set %vida #hits
; An Nox
    set #LSPELL 10
    wait 6
    key %lastspell
    target 4s
    key %targetself
    wait 4s
   msg $/ detectvenom $
   }   
 }
noscanvenom:

if %vida > #hits
  {
   if %sacofoto = 1
     gosub sacarfoto
   gosub guardia
   wait 1s
   set %vida #hits
   if %tipoheal = VENDAS
     {
      ; Curar con vendas
      gosub apuntar ZLF
      key %lastobject
      target 4s
      key %targetself
      wait 2s
      exit
     }
 ; Curar con spell
 ; Greater Heal
msg $ curandome con GREAT HEAL!$
    set #LSPELL 28
    key %lastspell
    target 4s
    key %targetself
  }

exit

sub guardia
 msg $ Guards ! Es un criminal! Socorro!$
return

sub sacarfoto
  set %rnd #random
  if %rnd > 500
     msg $PATATA!$
  if %rnd <= 500
     msg $PATATUELAS!$

;Aki iria el execute snapshot
return


sub apuntar
usarinit:
 finditem %1

 if #findkind = -1
     {
      set %1 -1
      goto usarfin
     }

 if #findkind > 0
    {
     ignoreitem #findid
     goto usarinit
    }

 set #lobjecttype #findtype
 set #lobjectid #findid
usarfin:
return
