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
EVENT sysmessage     GuardSys    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 C in #charstatus
;   {
; if %sacofoto = 1
;     gosub sacarfoto
;    wait 1s
;    set %vida #hits
;; An Nox
;    wait 6
;    event macro 15 10
;    target 4s
;    event macro %targetself
;    wait 4s
;   }   


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
    wait 6
    event macro 15 10
    target 4s
    event macro %targetself
    wait 4s
   event sysmessage 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
      event macro %lastobject
      target 4s
      event macro %targetself
      wait 2s
      exit
     }
 ; Curar con spell
 ; Greater Heal
    event macro Curandome con GREAT HEAL!
    event macro 15 28
    target 4s
    event macro %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
