<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE muclient>

<muclient>
<plugin
   name="Who_group"
   author="Abelinc"
   id="dc7ff8e568167f9b95c1e2e5"
   language="Lua"
   purpose="Creates a 'whogroup' command to automatically use level-15 level+15"
   date_written="2011-05-07"
   requires="4.40"
   version="1.0"
   save_state="y"
   >
<description trim="y">
<![CDATA[
Install this plugin to give yourself commands for level-based "swho" output for
finding groups and PK targets. Its syntax is:

whogroup            - Sends "who <level-15> <level+15>"
whogroup good       - Sends "who <level-15> <level+15> good"
whogroup evil       - Sends "who <level-15> <level+15> evil"
whogroup help       - Displays this text

whopk               - Sends "swho <pk_swho_number> <level-10> <level+10> <clanlist>"
whoapk              - Sends "swho <pk_swho_number> <level-10> <level+10> <clanlist> area"

swhogroup <1-13>    - Sets the variable for which swho to use for groups
swhopk <1-13>       - Sets the variable for which swho to use for PK

pkclans <clanlist>  - Sets the variable for clans to include in PK options
]]>
</description>

</plugin>

<aliases>

  <alias
   name="whogroup"
   script="whogroup_func"
   match="^whogroup ?(align|good|evil|help)?$"
   enabled="y"
   regexp="y"
   ignore_case="y"
   sequence="100"
  >
  </alias>

  <alias
   name="whopk"
   script="whopk_func"
   match="whopk"
   enabled="y"
   regexp="n"
   ignore_case="y"
   sequence="100"
  >
  </alias>

  <alias
   name="whoapk"
   script="whoapk_func"
   match="whoapk"
   enabled="y"
   regexp="n"
   ignore_case="y"
   sequence="100"
  >
  </alias>

  <alias
   name="swhogroup"
   script="swhogroup_func"
   match="^swhogroup ([1]?[0-9])$"
   enabled="y"
   regexp="y"
   ignore_case="y"
   sequence="100"
  >
  </alias>

  <alias
   name="swhopk"
   script="swhopk_func"
   match="^swhopk ([1]?[0-9])$"
   enabled="y"
   regexp="y"
   ignore_case="y"
   sequence="100"
  >
  </alias>

  <alias
   name="pkclans"
   script="pkclans_func"
   match="^pkclans ([a-z ]+)$"
   enabled="y"
   regexp="y"
   ignore_case="y"
   sequence="100"
  >
  </alias>

</aliases>


<triggers>
</triggers>

<script>
<![CDATA[

require "serialize"
require "commas"
require "gmcphelper"

function OnPluginBroadcast (msg, id, name, text)
   -- Look for GMCP handler.
   if (id == '3e7dedbe37e44942dd46d264') then
      if (text == "char.status") then
         res, gmcparg = CallPlugin("3e7dedbe37e44942dd46d264","gmcpval","char")

         luastmt = "gmcpdata = " .. gmcparg
         assert (loadstring (luastmt or "")) ()
      end
   end
end


function whogroup_func (name, line, wildcards)
	if wildcards [1] == "" then
		Send ("swho " .. group_swho_number .. " " .. (tonumber(gmcpval("status.level")) - 15) .. " " .. (tonumber(gmcpval("status.level")) + 15) )
	elseif wildcards [1] == "good" then
		Send ("swho " .. group_swho_number .. " " .. (tonumber(gmcpval("status.level")) - 15) .. " " .. (tonumber(gmcpval("status.level")) + 15) .. " " .. "good")
	elseif wildcards [1] == "evil" then
		Send ("swho " .. group_swho_number .. " " .. (tonumber(gmcpval("status.level")) - 15) .. " " .. (tonumber(gmcpval("status.level")) + 15) .. " " .. "evil")
	elseif wildcards [1] == "help" then
		whogroup_help ()
	else whogroup_help ()
	end
end

function whopk_func (name, line, wildcards)
	Send ("swho " .. pk_swho_number .. " " .. (tonumber(gmcpval("status.level")) - 10) .. " " .. (tonumber(gmcpval("status.level")) + 10) .. " " .. whopk_clans)
end

function whoapk_func (name, line, wildcards)
		Send ("swho " .. pk_swho_number .. " " .. (tonumber(gmcpval("status.level")) - 10) .. " " .. (tonumber(gmcpval("status.level")) + 10) .. " " .. whopk_clans .. " " .. "area")
end

function swhogroup_func (name, line, wildcards)
	group_swho_number = wildcards [1]
	ColourNote ("yellow", "", "whogroup will now use swho " .. group_swho_number)
end

function swhopk_func (name, line, wildcards)
	pk_swho_number = wildcards [1]
	ColourNote ("yellow", "", "whopk and whoapk will now use swho " .. pk_swho_number)
end

function pkclans_func (name, line, wildcards)
	whopk_clans = wildcards [1]
	ColourNote ("yellow", "", "whopk and whoapk will now use the clans " .. whopk_clans)
end


function OnPluginInstall ()
  if GetVariable ("enabled") == "false" then
    ColourNote ("yellow", "", "Warning: Plugin " .. GetPluginName ().. " is currently disabled.")
    check (EnablePlugin(GetPluginID (), false))
    return
  end -- they didn't enable us last time

  OnPluginEnable ()  -- do initialization stuff

end -- OnPluginInstall

function OnPluginEnable ()

	if GetVariable ("pk_swho_number") == nil then 
		SetVariable ("pk_swho_number", "12")
	end
	pk_swho_number = GetVariable ("pk_swho_number")

	if GetVariable ("group_swho_number") == nil then 
		SetVariable ("group_swho_number", "12")
	end
	group_swho_number = GetVariable ("group_swho_number")

	if GetVariable ("whopk_clans") == nil then 
		SetVariable ("whopk_clans", " ")
	end
	whopk_clans = GetVariable ("whopk_clans")

	Send_GMCP_Packet("request char")

end -- OnPluginEnable

function OnPluginSaveState ()
  SetVariable ("enabled", tostring (GetPluginInfo (GetPluginID (), 17)))
  SetVariable ("pk_swho_number", pk_swho_number)
  SetVariable ("group_swho_number", group_swho_number)
  SetVariable ("whopk_clans", whopk_clans)
end -- OnPluginSaveState

function whogroup_help (name, line, wildcards)
  ColourNote ("teal", "", world.GetPluginInfo (world.GetPluginID (), 3))
  return true -- done  
end -- whogroup_help



]]>
</script>

</muclient>
