<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Tuesday, May 09, 2006, 12:26 AM -->
<!-- MuClient version 3.30 -->

<!-- Plugin "Aardwolf_WeaponSwitchLUA" generated by Plugin Wizard -->

<muclient>
<plugin
   name="Aardwolf_WeaponSwitchLUA"
   author="Onoitsu2"
   id="3df99b9e98da7ed9257b6598"
   language="Lua"
   purpose="Switches Weapons from inside or outside a bag"
   save_state="y"
   date_written="2006-05-09 00:26:00"
   requires="3.23"
   version="1.1"
   >
<description trim="n">
<![CDATA[

Weapon_SwitchLUA Helpfile
Usage
----- (Spaces between the '=' and parameterrs are OPTIONAL!)
w1 = weapon   (set weapon 1, also w1=weapon)
w2 = weapon   (set weapon 2, also w2=weapon)
w3 = weapon   (set weapon 3, also w3=weapon)  ... and so on up to 9 ...

w1            (choose weapon 1)
w2            (choose weapon 2)
w3            (choose weapon 3) ... and so on up to 9 ...
w0            (REMOVES Weapon!)

w clear       (clears the weapons list)
wbag = bag    (sets the bag to get and put weapons to and from, also wbag=bag)
wl            (lists the weapons that are set)
w list        (lists the weapons that are set)
w help        (display this message)

Examples
-----
wbag=black portable hole  (bag set to 'An endless hole', using item's "Keywords")
w1=dagger vampire     (weapon 1 is dagger)
w2=mace of warding    (weapon 2 is 'mace of warding')

w1                    (choose 'dagger vampire')
w2                    (choose 'mace of warding')
w1                    (choose dagger again)
w2                    (choose 'mace of warding' again)
w0                    (REMOVES Weapon!)
]]>
</description>

</plugin>
<include name="constants.lua"/>
<!--  Triggers  -->

<triggers>
  <trigger
   custom_colour="4"
   enabled="y"
   group="Battle"
   match="^(.*?) DISARMS you and sends your (.*?) flying\!$"
   name="Disarm_Rewear"
   regexp="y"
   script="disarmed"
   sequence="40"
  >
  </trigger>
</triggers>

<!--  Aliases  -->

<aliases>
  <alias
   script="SetBag"
   match="^wbag\s*\=\s*(.+)$"
   enabled="y"
   regexp="y"
  >
  </alias>
  <alias
   script="SetWeapon"
   match="^w([1-9])\s*\=\s*(.+)$"
   enabled="y"
   regexp="y"
  >
  </alias>
  <alias
   script="ChooseWeapon"
   match="(^w([1-9])$|^w0$)"
   enabled="y"
   regexp="y"
  >
  </alias>
  <alias
   script="WeaponClear"
   match="^w clear$"
   enabled="y"
   regexp="y"
   send_to="12"
  >
  </alias>
  <alias
   script="WeaponLister"
   match="(^w list$|^wl$)"
   enabled="y"
   regexp="y"
   send_to="12"
  >
  </alias>

</aliases>
<!--  Script  -->


<script>
<![CDATA[
function OnPluginInstall()
--local i
OnHelp()
--for i = 1, 9 do
--world.SetVariable("weapons" .. i,"")
--end
--world.SetVariable("weaponsbag","")
--world.SetVariable("weapon","")
end

function OnPluginConnect()

end

function disarmed()
Note("DISARMED - Attempting to ReArm!")
local cweap = world.GetVariable("weapon")
if cweap == nil then
	Send("get all")
	Send("wield all")
else
	Send("get " .. cweap)
	Send("wield " .. cweap)
end
end


function SetBag(sName, sLine, wildcards)
local which
local to_whom
  which = wildcards[1]
  SetVariable("weaponsbag", "'" .. which .. "'")
  ColourNote("moccasin", "darkgreen", "Weapons Bag is now '" .. which .. "'")
  SaveState()
end

function SetWeapon(sName, sLine, wildcards)
local which
local to_whom
which = wildcards[1]
to_what = wildcards[2]
world.SetVariable("weapons" .. which, "'" .. to_what .. "'")
ColourNote("moccasin", "darkgreen", "Weapon " .. which .. " now '" .. to_what .. "'")
SaveState()
Note("")
end

function ChooseWeapon(sName, sLine, wildcards)
world.Note(wildcards[0])
local cweap = world.GetVariable("weapon")
local cbag = world.GetVariable("weaponsbag")
local weapnum
if wildcards[0] == "w0" then
else
weapnum = world.GetVariable("weapons" .. wildcards[2])
end

if cweap == nil then
cweap = ""
end
if weapnum == nil then
weapnum = ""
end
if cbag == nil then
cbag = ""
end

if wildcards[0] == "w0" then
	if cweap == "" then
		Note("No Weapon To Remove!!")
		return
	else
		Note("Removing Weapons")
		Send("remove " .. cweap)
		if cbag == "" then
		else
			Send("put " .. cweap .. " " .. cbag)
		end
		SetVariable("weapon","")
		SaveState()
		return
	end
end

if weapnum == "" then
Note("No Weapon Set For #" .. wildcards[2] .. "!")
return
end
--Note(cweap .. " " .. cbag .. " " .. weapnnum)
if cweap == weapnum and not weapnum == "" then
	return
else
    if cweap == "" then
	else
	Send("remove " .. cweap)
	if cbag == "" then
	else
		Send("put " .. cweap .. " " .. cbag)
	end
	end
	SetVariable("weapon", weapnum)
	cweap = weapnum
	ColourNote("moccasin", "darkgreen", "Weapon now '" .. cweap .. "'")
	if cbag == "" then
	else
		Send("get " .. cweap .. " " .. cbag)
	end
	Send("wear " .. cweap)
end
SaveState()
end

function WeaponClear(sName, sLine, wildcards)
local i
for i = 1 , 9 do
	SetVariable("weapons" .. i,"")
end
SetVariable("weaponsbag","")
SetVariable("weapon","")
ColourNote("white","blue","All weapons cleared from weapons list. AND Weapons Bag")
SaveState()
Note("")
end

function WeaponLister()
local weapon
local i
local var
var = world.GetVariable("weapon")
if var == nil then
var = ""
end
	if var == "" then
		Note("Current Weapon = (nothing)")
	else
		Note("Current Weapon = " .. var)
	end
for i = 1 , 9 do
	var = world.GetVariable("weapons" .. i)
	if var == nil then
	var = ""
	end
	if var == "" then
		Note("Weapon " .. i .. " = (nothing)")
	else
		Note("Weapon " .. i .. " = " .. var)
	end
end
var = GetVariable("weaponsbag")
if var == nil then
var = ""
end
if var == "" then
	Note("Weapons Bag set to: (nothing)")
else
	Note("Weapons Bag set to: " .. var)
end
Note("")
end


]]>
</script>

<!--  Plugin help  -->

<aliases>
  <alias
   script="OnHelp"
   match="w help"
   enabled="y"
  >
  </alias>
</aliases>

<script>
<![CDATA[
function OnHelp()
  world.Note(GetPluginInfo (GetPluginID(), 3))
end
]]>
</script> 

</muclient>
