;-----------------------------------------------------------
; Script Name: TrailMyx's Active Meditation Subs
; Author: TrailMyx
; Version: 1.1
; Client Tested with: 6.0.1.6
; EUO version tested with: 1.5 118
; Shard: OSI, FS
; Revision Date:  6/15/2007
; Public Release: ...
; Global Variables Used: None
; Purpose/Features:
;   Automatic active meditation
; Usage:
;   gosub Meditate #TRUE 10 ; call block until mana reaches #INT - 10
;   gosub Meditate #FALSE 10 ; just startes active meditation, then returns.
;
;    http://www.scriptuo.com/
;----------------------------------------------------------
; %1 #TRUE = wait until you've reached your threshold
; %2 = target full threshold (number subtracted from #INT)
sub Meditate
  namespace push
  namespace local MED
  set !wait %1
  set !thresh %2
  gosub TM_SyncTextScan
  set !mana_target #INT - !thresh
  set !success #FALSE
  med_loop1:
    if #MANA > !mana_target
      goto Meditate_skip
    if !success = #FALSE
    {
      gosub TM_SyncTextScan
      event macro 13 46
      wait 20
    }
    gosub TM_FindValidTextNoAdvance you_enter_a_meditative_trance
    if #RESULT = #TRUE
    {
      gosub TM_SyncTextScan
      if !wait <> #TRUE
        goto Meditate_skip
      set !success #TRUE
    }
    gosub TM_FindValidTextNoAdvance you_stop_meditating
    if #RESULT = #TRUE
    {
      gosub TM_SyncTextScan
      set !success #FALSE
    }
    goto med_loop1
Meditate_skip:
  namespace pop
return
;-------------------------------------------------------------------------------
; Brings !_jindex up to the most recent #journal entry
sub TM_SyncTextScan
  namespace push
  namespace local text
  set !_jindex #jindex + 1
  namespace pop
return
;-------------------------------------------------------------------------------
; %2, %3, %4, etc strings to match
; returns #TRUE for match, #FALSE for no match
;  Will not advance !_jindex pointer to allow for scanning journal history for more than one search.
;  Also searches for : , #SPC in journal entry to be sure someone isn't spamming the text
sub TM_FindValidTextNoAdvance
  namespace push
  namespace local text
  set !temp_lpc #LPC
  set #LPC 1000
  set !num_args %0
  set !first_arg 1
  if !_jindex = N/A
    set !_jindex #jindex
  set !index !first_arg
  repeat
    set !temp_jindex !_jindex
    set !text % . !index
    while !temp_jindex <= #jindex
    {
      scanjournal !temp_jindex
      if !text in #journal && :_ , !text notin #journal
      {
        set !temp_jindex !temp_jindex + 1
        set #LPC !temp_lpc
        namespace pop
        return #TRUE
      }
      set !temp_jindex !temp_jindex + 1
    }
    set !index !index + 1
  until ( ( !index - !first_arg ) > ( !num_args - 1 ) )
  set #LPC !temp_lpc
  namespace pop
return #FALSE