<?xml version="1.0" encoding="UTF-8" ?> 
<!DOCTYPE muclient > 

<muclient> 
   <plugin name="AutoHealer" author="Keldar" language="vbscript" purpose="Automatic healing" 
     save_state="y" date_written="2003-10-05" date_modified="2003-10-26" requires="3.32" version="1.4" 
     id="ebbb2e6c8db0bfb433d76dbf"> 
  
    <description trim="y"> 

        <![CDATA[ 
This plugin will automatically replenish your health level. Use 
the following commands to configure the plugin and control it: 

ah on|off                    -    turns the plugin on and off 

moss on|off               -   turns moss eating on and off 

AutoHealer:maxMana <value>     -    sets a new value for your maximum 
                                     mana level (default is 2500) 

AutoHealer:maxHealth <value>   -    sets a new value for your maximum 
                                     health level (default is 2500) 

AutoHealer:help                -    displays this help text 

Default floors for health and mana (when to sip) are set at 85%, see 
comments in the script. 
Default floor for health (when to eat moss) is set at 65%, see comments 
in the script. 
Default balance intervals for elixir and moss are set to 5 secs, see 
comments in the script. 

The plugin takes a different approach to managing elixir and moss balance 
- it uses scripted time checks between calls of the prompt trigger (with 
an optional external timer) to figure out whether the balance time has 
elapsed and you can heal again. This approach makes sure the plugin isn't 
susceptible to lag or situations which will render 'regular' - trigger 
based - auto healers temporarily unfunctional. Enjoy, and feel free to 
adjust whatever you want in the plugin. 

        ]]> 

    </description> 

</plugin> 
 <include name="constants.vbs" /> 

<timers> 
 <timer name="TickTimer" enabled="n" second="1" script="TickTimer"> 
  <send></send> 
  </timer> 
</timers> 


<triggers> 
  <trigger 
   enabled="y" 
   keep_evaluating="y" 
   match="^(\d+)h, (\d+)m (\D{0,7})\-.*$" 
   name="prompt_trigger" 
   regexp="y" 
   script="DecipherPromptInfo" 
   sequence="1" 
   other_text_colour="black" 
   other_back_colour="black" 
  > 
  </trigger> 
  <trigger 
   enabled="n" 
   name="HealthBalanceRecovered" 
   match="*You may drink another health or mana elixir." 
   script="HealthRecovery" 
   sequence="100" 
  > 
  </trigger> 
  <trigger 
   enabled="y" 
   name="ElixirWasted" 
   match="*The elixir flows down your throat without effect." 
   script="AttemptResult" 
   keep_evaluating="y" 
   sequence="10" 
  > 
  </trigger> 
  <trigger 
   enabled="y" 
   name="MossWasted" 
   match="*The moss slides down without effect." 
   script="AttemptResult" 
   sequence="100" 
  > 
  </trigger> 
  <trigger 
   enabled="n" 
   name="MossBalanceRecovered" 
   match="*You may eat another bit of irid moss." 
   script="HealthRecovery" 
   keep_evaluating="y" 
   sequence="10" 
  > 
  </trigger> 
</triggers> 

<aliases> 
  <alias 
    name="SwitchHealing" 
    script="SetHealingMode" 
    enabled="y" 
    regexp="y" 
    match="^ah (on|off)$" 
    sequence="100" 
  /> 
  <alias 
    name="max_mana" 
    script="SetMaxValues" 
    enabled="y" 
    regexp="y" 
    match="^AutoHealer:maxMana (\d+)$" 
    sequence="100" 
   /> 
  <alias 
    name="max_health" 
    script="SetMaxValues" 
    enabled="y" 
    regexp="y" 
    match="^AutoHealer:maxHealth (\d+)$" 
    sequence="100" 
   /> 
  <alias 
    name="autohealer_help" 
    script="DisplayHelp" 
    enabled="y" 
    match="AutoHealer:help" 
    sequence="100" 
   /> 
  <alias 
    name="autohealer_moss" 
    script="SetMoss" 
    enabled="y" 
    match="moss (on|off)" 
    regexp="y" 
   /> 
  <alias 
   name="autohealer_health" 
   script="Manual" 
   enabled="n" 
   match="dh" 
  /> 
  <alias 
   name="autohealer_mana" 
   script="Manual" 
   enabled="n" 
   match="dm" 
   sequence="100" 
  /> 
  <alias 
   name="autohealer_mosseat" 
   script="Manual" 
   enabled="n" 
   match="em" 
   sequence="100" 
  /> 
</aliases> 

<variables> 
 <variable name="MaxMana">2500</variable> 
 <variable name="MaxHealth">2500</variable> 
 <variable name="HealthFloor">85</variable> 
 <variable name="ManaFloor">85</variable> 
 <variable name="MossFloor">65</variable> 
</variables> 


<script> 
<![CDATA[ 
dim maxHealth, maxMana 
maxHealth = world.GetVariable("MaxHealth") 
maxMana = world.GetVariable("MaxMana") 

dim Health, Mana, accumulatedDamage 
Health = maxHealth 
Mana = maxMana 


dim Heal, Moss, auto 
Heal = vbFalse 
Moss = vbFalse 


sub AttemptResult(name, output, wildcs) 
 select case name 
  case "ElixirWasted" 
   world.EnableTrigger "HealthBalanceRecovered", 1 
  case "MossWasted" 
   world.EnableTrigger "MossBalanceRecovered", 1 
 end select 
end sub 

sub HealthRecovery(name, output, wildcs) 
 select case name 
  case "HealthBalanceRecovered" 
   world.EnableTrigger "HealthBalanceRecovered", 0 
   HealthBalance = vbTrue 
   AutoHeal "health" 
  case "MossBalanceRecovered" 
   world.EnableTrigger "MossBalanceRecovered", 0 
   MossBalance = vbTrue 
   AutoHeal "moss" 
 end select 
end sub 


dim HealthBalance, MossBalance 
HealthBalance = vbTrue 
MossBalance = vbTrue 

dim healthoffTimer, mossoffTimer 

sub SetMoss(name, output, wildcs) 
 select case wildcs(1) 
  case "on" 
   Moss = vbTrue 
  case "off" 
   Moss = vbFalse 
 end select 
end sub 

sub SetMaxValues(name, output, wildcs) 
 select case name 
  case "max_mana" 
   world.SetVariable "MaxMana", wildcs(1) 
   maxMana = world.GetVariable("MaxMana") 
   world.Note "AutoHealer plugin: you've set your max mana to " + wildcs(1) 
  case "max_health" 
   world.SetVariable "MaxHealth", wildcs(1) 
   maxHealth = world.GetVariable("MaxHealth") 
   world.Note "AutoHealer plugin: you've set your max health to " + wildcs(1) 
 end select 
end sub 

sub SetHealingMode(name, output, wildcs) 
 select case wildcs(1) 
  case "on" 
   Heal = vbTrue 
   world.EnableTimer "TickTimer", 1 
   world.note "Automatic healing is ON" 
  case "off" 
   Heal = vbFalse 
   world.EnableTimer "TickTimer", 0 
   world.note "Automatic healing is OFF" 
  
 end select 
end sub 

sub DecipherPromptInfo (name, output, wildcs) 
 Health = cint(wildcs(1)) 
 Mana = cint(wildcs(2)) 
 CheckTiming 
end sub 

sub CheckTiming 
 if HealthBalance then 
   AutoHeal "health" 
 else 
   if TimingExpired("health") then 
    AutoHeal "health" 
   end if 
 end if 
 if  MossBalance then 
   AutoHeal "moss" 
 else 
   if TimingExpired("moss") then 
    AutoHeal "moss" 
   end if 
 end if 
end sub 

dim healthFloor, manaFloor, mossFloor 
healthFloor = cint(world.GetVariable("HealthFloor"))/100 
manaFloor = cint(world.GetVariable("ManaFloor"))/100 
mossFloor = cint(world.GetVariable("MossFloor"))/100 

sub AutoHeal (name)                     'Feel free to change these or suggest changes to the overall
if Heal then                            'algorithm of deciding what and when to drink and eat 
 select case name 
  case "health" 
   if (Health <= maxHealth*healthFloor) then   'drink health elix if health falls below 85% of max 
      worldsend "drink health" 
      HealthBalance = vbFalse 
      SetTimeNow "health" 
   elseif (Mana <= maxMana*manaFloor) then   'drink mana elix if mana falls below 85% of max and health is over 85% 
      worldsend "drink mana" 
      HealthBalance = vbFalse 
      SetTimeNow "health" 
   end if 
  case "moss" 
   if Moss then 
    if (Health <= maxHealth*mossFloor) then   'eat moss if health falls below 65% of max 
      worldsend "outr moss" 
      worldsend "eat moss" 
      MossBalance = vbFalse 
      SetTimeNow "moss" 
    end if 
   end if 
 end select 
end if 
end sub 

sub SetTimeNow (task) 
 select case task 
  case "health" 
    healthoffTimer = Timer 
  case "moss" 
    mossoffTimer = Timer 
 end select 
end sub 

function TimingExpired (task) 
   dim timerNow, timerDiff  
   timerNow = Timer 
select case task 
   case "health" 
     if (timerDiff < 0) then 
      timerDiff = timerNow + (86400 - healthoffTimer) 
     else 
      timerDiff = timerNow - healthoffTimer 
     end if 
     if (timerDiff < 5) then                  'Health elix balance interval is set at 5 secs 
      TimingExpired = vbFalse 
     elseif (timerDiff >= 5) then 
      TimingExpired = vbTrue 
     end if 
   case "moss" 
     if (timerDiff < 0) then 
      timerDiff = timerNow + (86400 - mossoffTimer) 
     else 
      timerDiff = timerNow - mossoffTimer 
     end if 
     if (timerDiff < 5) then                  'Moss balance interval is set at 5 secs 
      TimingExpired = vbFalse 
     elseif (timerDiff >= 5) then 
      TimingExpired = vbTrue 
     end if 
end select 
end function 

sub DisplayHelp(name, output, wildcs) 
   World.Note World.GetPluginInfo (World.GetPluginID, 3) 
end sub 

sub TickTimer(name) 
 if Heal then 
  CheckTiming 
 end if 
end sub 


' 
'Below are all the callbacks for this plugin. 
'Read comments for each sub to see what it does and how 
'to use it. 
' 
sub SetMaxManaEx(val) 
'This sets the max mana level 
'Usage example: world.callplugin "ebbb2e6c8db0bfb433d76dbf", "SetMaxManaEx", 2670 
' 
world.SetVariable "MaxMana", val 
maxMana = cint(world.GetVariable("MaxMana")) 
end sub 

sub SetMaxHealthEx(val) 
'This sets the max health level 
'Usage example: world.callplugin "ebbb2e6c8db0bfb433d76dbf", "SetMaxHealthEx", 2670 
' 
world.SetVariable "MaxHealth", val 
maxHealth = cint(world.GetVariable("MaxHealth")) 
end sub 

sub SetHealthFloorEx(val) 
'This sets the relative level of health (%) at which to drink elixir 
'Usage example: world.callplugin "ebbb2e6c8db0bfb433d76dbf", "SetHealthFloorEx", 70 
' 
world.SetVariable "HealthFloor", val 
healthFloor = cint(world.GetVariable("HealthFloor"))/100 
end sub 

sub SetManaFloorEx(val) 
'This sets the relative level of mana (%) at which to drink elixir 
'Usage example: world.callplugin "ebbb2e6c8db0bfb433d76dbf", "SetManaFloorEx", 75 
' 
world.SetVariable "ManaFloor", val 
manaFloor = cint(world.GetVariable("ManaFloor"))/100 
end sub 

sub SetMossFloorEx(val) 
'This sets the relative level of health (%) at which to eat moss 
'Usage example: world.callplugin "ebbb2e6c8db0bfb433d76dbf", "SetMossFloorEx", 50 
' 
world.SetVariable "MossFloor", val 
mossFloor = cint(world.GetVariable("MossFloor"))/100 
end sub 

sub SetMossModeEx(val) 
'This sets whether you will eat moss or not. Usefull for combat vs bashing modes 
'Moss is off by default when plugin starts, so you have to turn it on either 
'manually or using this callback. 
'Usage example: world.callplugin "ebbb2e6c8db0bfb433d76dbf", "SetMossModeEx", "on" 
' 
 select case val 
  case "on" 
   Moss = vbTrue 
  case "off" 
   Moss = vbFalse 
 end select 
end sub 

sub SetHealingModeEx(val) 
'This turns the plugin on and off. 
'Usage example: world.callplugin "ebbb2e6c8db0bfb433d76dbf", "SetHealingModeEx", "on" 
' 
 select case val 
  case "on" 
   Heal = vbTrue 
   world.EnableTimer "TickTimer", 1 
   world.note "Automatic healing is ON" 
  case "off" 
   Heal = vbFalse 
   world.EnableTimer "TickTimer", 0 
   world.note "Automatic healing is OFF" 
 end select 
end sub 


sub ManualEx(name) 
'This manually sips or eats. 
'Usage example: world.callplugin "ebbb2e6c8db0bfb433d76dbf", "ManualEx", "health" 
' 

select case name 
 case "health" 
   worldsend "drink health" 
   HealthBalance = vbFalse 
   SetTimeNow "health" 
 case "mana" 
   worldsend "drink mana" 
   HealthBalance = vbFalse 
   SetTimeNow "health" 
 case "moss" 
   worldsend "outr moss" 
   worldsend "eat moss" 
   MossBalance = vbFalse 
   SetTimeNow "moss" 
end select 
end sub 

sub GagAll(val) 
'This gags all output, meaning that the plugin will be muted completely 
'if you turn this on 
'Example of usage: world.callplugin "ebbb2e6c8db0bfb433d76dbf", "GagAll", "on" 
' 
 select case val 
  case "on" 
   gagInput = vbTrue 
  case "off" 
   gagInput = vbFalse 
 end select 
end sub 

'-------->End of callbacks<-------- 

sub Manual(name, output, wildcs) 
select case name 
 case "autohealer_health" 
   worldsend "drink health" 
   HealthBalance = vbFalse 
   SetTimeNow "health" 
 case "autohealer_mana" 
   worldsend "drink mana" 
   HealthBalance = vbFalse 
   SetTimeNow "health" 
 case "autohealer_mosseat" 
   worldsend "outr moss" 
   worldsend "eat moss" 
   MossBalance = vbFalse 
   SetTimeNow "moss" 
end select 
end sub 

dim gagInput 
gagInput = vbFalse 

sub WorldSend (txt) 
 if gagInput then 
   exit sub 
 else 
   world.send txt 
 end if 
end sub 

]]>        
</script> 

</muclient> 