All pastes #1059855 Raw Edit

Aardwolf Spellup plugin for MUSH

public text v1 · immutable
#1059855 ·published 2008-07-01 19:13 UTC
rendered paste body
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Tuesday, July 01, 2008, 4:55 AM -->
<!-- MuClient version 4.29 -->

<!-- Plugin "Spellup" generated by Plugin Wizard -->

<muclient>
<plugin
   name="Spellup"
   author="Iyethar"
   id="63c3414ea15d1758f65e50cd"
   language="Lua"
   purpose="Aardwold spellup script"
   save_state="y"
   date_written="2008-07-01 04:53:50"
   requires="4.29"
   version="1.0"
   >

</plugin>


<!--  Get our standard constants -->

<include name="constants.lua"/>

<!--  Triggers  -->

<triggers>
  <trigger
   enabled="y"
   match=".+? lost your concentration while trying to cast (.+)\.$"
   name="spellrecast"
   regexp="y"
   script="spell_recast"
   sequence="100"
  >
  </trigger>
</triggers>

<!--  Aliases  -->

<aliases>
  <alias
   name="addspell"
   script="add_spell"
   match="^addspell\s*(?P&lt;spell&gt;.*)$"
   enabled="y"
   regexp="y"
   sequence="100"
  >
  </alias>
  <alias
   name="removespell"
   script="remove_spell"
   match="^removespell\s*(?P&lt;spell&gt;.*)$"
   enabled="y"
   regexp="y"
   sequence="100"
  >
  </alias>
  <alias
   name="insertspell"
   script="insert_spell"
   match="^insertspell\s*&quot;(?P&lt;spell&gt;.+)&quot;(?:\s*(?P&lt;sdx&gt;\d+).*$|.*$)"
   enabled="y"
   regexp="y"
   sequence="100"
  >
  </alias>
  <alias
   name="spellup"
   script="spell_up"
   match="^spellup(?:\s*(display|clear|help)\s*$|\s*$)"
   enabled="y"
   regexp="y"
   sequence="100"
  >
  </alias>
</aliases>

<!--  Script  -->


<script>
<![CDATA[
require "serialize"
require "wait"

qch = string.char (34)
fg = "forestgreen"
bg = ""

function DisplaySpellupHelp ()
  ColourNote ("lime", bg, " -- SPELLUP -- ")
  Note ("")
  ColourNote (fg, bg, "spellup                 ", "gray", bg, "  -- casts all spells in spellup list, in order")
  ColourNote (fg, bg, "spellup display         ", "gray", bg, "  -- displays defined spellup list")
  ColourNote (fg, bg, "spellup clear           ", "gray", bg, "  -- destroys spellup list.  No takebacks")
  ColourNote (fg, bg, "spellup help            ", "gray", bg, "  -- this help")
  Note ("")
  ColourNote (fg, bg, "addspell    <spell name>", "gray", bg, "  -- add <spell name> to end of spellup list")
  ColourNote (fg, bg, "removespell <spell name>", "gray", bg, "  -- delete <spell name> from spellup list")
  ColourNote (fg, bg, "insertspell " .. qch .. "<spell name>" .. qch .. " [position]", "gray", bg, " -- add <spell name> to [position] in spellup list")
  Note ("")
end -- function

function spell_up (name, line, wildcards)
  if (GetAliasInfo ("spellup",24) == 2) then
    if (string.lower (wildcards [1]) == "display") then
      if ((spellupconfig == nil) or (table.getn (spellupconfig) == 0)) then
        ColourNote (fg, bg, "No spells in spellup list.")
        Note ("")
      else
        for i, spell in ipairs (spellupconfig) do
          ColourNote (fg, bg, "Spell " .. i .. ": ", "gray", bg, spell)
        end -- for
        Note ("")
      end -- if
    elseif (string.lower (wildcards [1]) == "clear") then
      spellupconfig = {}
      ColourNote (fg, bg, "Spellup list cleared.")
      Note ("")
    elseif (string.lower (wildcards [1]) == "help") then
      DisplaySpellupHelp ()
    end -- if
  else
    if ((spellupconfig == nil) or (table.getn (spellupconfig) == 0)) then
      ColourNote (fg, bg, "No spells in spellup list.")
      ColourNote (fg, bg, "Add some with '", "white", bg, "addspell <spell name>", fg, bg, "' or '","white", bg,  "insertspell " .. qch .. "<spell name>" .. qch .. " [position]",fg, bg, "'!")
      Note ("")
    else
      wait.make (capture_ssu_cr)
    end -- if
  end -- if
end -- function spellup

function capture_ssu_cr ()
  spellstocast = {}
  SendNoEcho ("qspells spellup unaffected")
  wait.match ("Skill/Spell List - Brief Version:")
  repeat
    line, wildcards = wait.regexp("^(.*)$")
    spellstocast [#spellstocast + 1] = string.lower (Trim (line))
  until string.find (line, "End of list.")
  wait.time (1)
  for i1, spell1 in ipairs (spellupconfig) do
    for i2, spell2 in ipairs (spellstocast) do
      if (spell2 == string.lower (Trim(spell1))) then
        SendNoEcho ("cast '" .. spell2 .."'")
      end -- if
    end -- for
  end -- for
end -- function capture_ssu_cr

function insert_spell (name, line, wildcards)
  for i, spell in ipairs (spellupconfig) do
    if (string.lower (spell) == string.lower (wildcards.spell)) then
      table.remove (spellupconfig, i)
    end -- if
  end -- for
  if (GetAliasInfo ("insertspell",24) == 2) then
    spellupconfig [#spellupconfig + 1] = wildcards.spell
    ColourNote (fg, bg, qch, "white", bg, wildcards.spell, fg, bg, qch .. " added to spellup list.")
    Note ("")
  else
    ColourNote (fg, bg, qch, "white", bg, wildcards.spell, fg, bg, qch .. " added to spellup list at position ", "white", bg, wildcards.sdx, fg, bg, ".")
    Note ("")  
    table.insert (spellupconfig, tonumber (wildcards.sdx), wildcards.spell)
  end -- if
end -- function insert_spell

function add_spell (name, line, wildcards)
  for i, spell in ipairs (spellupconfig) do
    if (string.lower (spell) == string.lower (wildcards.spell)) then
      table.remove (spellupconfig, i)
    end -- if
  end -- for
  ColourNote (fg, bg, qch, "white", bg, wildcards.spell, fg, bg, qch .. " added to spellup list.")
  Note ("")
  spellupconfig [#spellupconfig + 1] = wildcards.spell
end -- function add_spell

function remove_spell (name, line, wildcards)
  local found
  found = false
  for i, spell in ipairs (spellupconfig) do
    if (string.lower (spell) == string.lower (wildcards.spell)) then
      ColourNote (fg, bg, qch, "white", bg, wildcards.spell, fg, bg, qch .. " removed from spellup list.")
      table.remove (spellupconfig, i)
      found = true
    end -- if
  end -- for
  if (found == false) then
    ColourNote (fg, bg, qch, "white", bg, wildcards.spell, fg, bg, qch .. " not found in spellup list.")
  end -- if
  Note ("")
end -- function remove_spell

function spell_recast (name, line, wildcards)
  failedspell = GetTriggerWildcard ("spellrecast", "1")
  for i, spell in ipairs (spellupconfig) do
    if (string.lower (spell) == string.lower (failedspell)) then
      SendNoEcho ("cast '" .. failedspell .. "'")
      ColourNote (fg, bg, "Casting of " .. qch, "white", bg, failedspell, fg, bg, qch .. " failed... recasting.")
    end -- if
  end -- for
end -- function spell_recast

function OnPluginInstall ()
  spellupconfig = {}
  DisplaySpellupHelp ()
  assert (loadstring (GetVariable ("spellupconfig") or "")) ()
end -- function OnPluginInstall

function OnPluginSaveState ()
  SetVariable ("spellupconfig", 
               "spellupconfig = " .. serialize.save_simple (spellupconfig))
end -- function OnPluginSaveState

]]>
</script>


</muclient>