User:Wildhorn666/Wildhorn

This is Wildhorn script for an addon. Had to store it somewhere i could access at school. Please dont delete.

wpb_version = "0.96"; wpb_MessagesToHide = 0; wpb_Temp = ""; wpb_Events = { "CHAT_MSG_GUILD", "CHAT_MSG_OFFICER", "CHAT_MSG_RAID", "CHAT_MSG_PARTY", "CHAT_MSG_SAY", "CHAT_MSG_YELL", "CHAT_MSG_WHISPER", "CHAT_MSG_WHISPER_INFORM", "CHAT_MSG_CHANNEL" }

local chat_prefix = "[WPotBot] "

function wpb_OnLoad SLASH_WPOTBOT1 = "/wpotbot"; SLASH_WPOTBOT2 = "/wpb"; SlashCmdList["WPOTBOT"] = wpb_SlashCmd; wpb_Register("VARIABLES_LOADED"); end

function wpb_VarsLoaded local index; local value; if (wpb_db == nil) then wpb_db = {}; end if (wpb_Options == nil) then wpb_Options = {}; end if (wpb_Options["enabled"] == nil) then wpb_Options["enabled"] = true; end if (wpb_Options["altoutput"] == nil) then wpb_Options["altoutput"] = false; end if (wpb_Options["MaxResults"] == nil) then wpb_Options["MaxResults"] = 20; end if (wpb_Options["HideMessages"] == nil) then wpb_Options["HideMessages"] = true; end if (wpb_Options["RegExOff"] == nil) then wpb_Options["RegExOff"] = true; end

if (wpb_Options["enabled"]) then wpb_Register; end

wpb_AddMsg("Loaded."); wpb_Unregister("VARIABLES_LOADED"); end

function wpb_OnShow getglobal("WPotBotCheckButtonEnabled"):SetChecked(wpb_Options["enabled"]); getglobal("WPotBotCheckButtonOnePerLine"):SetChecked(wpb_Options["altoutput"]); end

function wpb_SlashCmd(msg) local msg = string.lower(msg); local _, _, argument1, argument2 = string.find(msg, "(%w+) (.+)"); if (argument1 == nil) then argument1 = msg; end if (argument2 == nil) then argument2 = ""; end if (argument1 == "on") then wpb_Enable; elseif (argument1 == "off") then wpb_Disable; elseif (argument1 == "scan") then wpb_ScanPotions; else wpb_AddMsg("Help"); wpb_AddMsg("/wpotbot on|off"); wpb_AddMsg("You may use /wpb instead of /wpotbot."); WPotBot:Show; end end

function wpb_OnEvent(event) if (event == "VARIABLES_LOADED") then wpb_VarsLoaded; return; end if (wpb_Options["enabled"]) then if (string.find(event, "CHAT_MSG_[(%w)_]")) then if ((event == "CHAT_MSG_WHISPER") and (arg2 == UnitName("player"))) then return; end if (string.find(string.lower(arg1), "^!pot")) then local SearchString, linkarray, chatchannel, player; SearchString = string.lower(string.gsub(arg1, "^!pot ", "")); if ((SearchString == "") or (SearchString == nil) or ((string.gsub(SearchString, "(%s*)", "")) == "")) then local chatchannel = string.gsub(event, "CHAT_MSG_", ""); if (chatchannel == "WHISPER_INFORM") then chatchannel = "WHISPER"; end SendChatMessage("Syntax: !pot ", chatchannel, this.language, arg2); return; end if (SearchString == "help") then local chatchannel = string.gsub(event, "CHAT_MSG_", ""); if (chatchannel == "WHISPER_INFORM") then chatchannel = "WHISPER"; end SendChatMessage("Syntax: !pot ", chatchannel, this.language, arg2); return; else linkarray, chatchannel, player = wpb_Search(SearchString, event, arg2); wpb_SendResults(linkarray, chatchannel, player); end elseif (string.find(string.lower(arg1), "^!help")) then local chatchannel = string.gsub(event, "CHAT_MSG_", ""); if (chatchannel == "WHISPER_INFORM") then chatchannel = "WHISPER"; end SendChatMessage("Syntax: !pot ", chatchannel, this.language, arg2); end end end end

-- wpb_Search: Looks through db function wpb_Search(item, chatchannel, player) local chatchannel = string.gsub(chatchannel, "CHAT_MSG_", ""); if (chatchannel == "WHISPER_INFORM") then chatchannel = "WHISPER"; end local link; local iIterator = 0; local linkarray = {};

if ((item == nil) or (string.gsub(item, "(%s*)", " ") == " ")) then SendChatMessage("Syntax: !pot ", chatchannel, this.language, arg2); return; else for idx=1,#wpb_db,1 do                        local searchstr = pstrjoin(" ", {wpb_db[idx][1], wpb_db[idx][2]}); local iFound = 0; for index, value in pairs(pstrsplit(" ", item)) do                               if string.find(string.lower(searchstr), string.lower(value), 1, wpb_Options["RegExOff"]) then iFound=iFound+1; end end if (iFound == table.getn(pstrsplit(" ", item))) then

iIterator = iIterator + 1; linkarray[iIterator] = wpb_db[idx][3]; end end return linkarray, chatchannel, player; end end

function wpb_SendResults(linkarray, chatchannel, player) local iIterator = 1; --local jIterator = 0; local chatmessage; if (linkarray == nil) then return; end while (linkarray[iIterator]) and (iIterator < wpb_Options.MaxResults) do		--jIterator = jIterator + 1; chatmessage = ""; while (linkarray[iIterator]) and (string.len(chatmessage..linkarray[iIterator]) < 255) do			chatmessage = chatmessage..linkarray[iIterator]; iIterator = iIterator + 1; if (wpb_Options["altoutput"]) then break end end wpb_MessagesToHide = wpb_MessagesToHide + 2; SendChatMessage(chatmessage, "WHISPER", GetDefaultLanguage("player"), player); end end

function wpb_Enable wpb_Options["enabled"] = true; wpb_Register; wpb_AddMsg("enabled"); wpb_OnShow; end

function wpb_Disable wpb_Options["enabled"] = false; wpb_Unregister; wpb_AddMsg("disabled"); wpb_OnShow; end

function wpb_Toggle if (wpb_Options["enabled"]) then wpb_Disable; else wpb_Enable; end end

function wpb_OutputMode if (wpb_Options["altoutput"]) then wpb_Options["altoutput"] = false; wpb_AddMsg("alternate output mode disabled"); wpb_OnShow; else wpb_Options["altoutput"] = true; wpb_AddMsg("alternate output mode enabled"); wpb_OnShow; end end

function wpb_AddMsg(msg, noprefix) if (not noprefix) then DEFAULT_CHAT_FRAME:AddMessage(chat_prefix..msg, 0.0, 0.7, 0.3, 0.7); else DEFAULT_CHAT_FRAME:AddMessage(msg, 0.0, 0.7, 0.3, 0.7); end end

function wpb_Register(ev) if (ev == nil) then for _, value in pairs(wpb_Events) do                        WPotBot:RegisterEvent(value); end else WPotBot:RegisterEvent(ev); end end

function wpb_Unregister(ev) if (ev == nil) then for _, value in pairs(wpb_Events) do			WPotBot:RegisterEvent(value); end else WPotBot:UnregisterEvent(ev); end end

wpb_OriginalChatFrame_OnEvent = ChatFrame_OnEvent; function ChatFrame_OnEvent(event) if (strsub(event,1,23) == "CHAT_MSG_WHISPER_INFORM") then local msg = arg1; local player = arg2; if ((msg) and (player) and (wpb_Options["HideMessages"]) and (wpb_MessagesToHide > 0) and (string.find(msg, "Hpotion:(%d+)"))) then wpb_MessagesToHide = wpb_MessagesToHide - 1; else wpb_OriginalChatFrame_OnEvent(event); end else wpb_OriginalChatFrame_OnEvent(event); end end

-- wpb_ScanPotions: Scans potion list and puts potion name, description and link to database. function wpb_ScanPotions local numPotions, tradeskillName, wpb_TradeSkillIdx, tradeskillLink, craftDescription; local wpb_CraftData = {};

wpb_AddMsg("Scanning your potions..."); numPotions = GetNumTradeSkills; if (numPotions < 1) then wpb_AddMsg("Can't find any potions, please make sure potion window is open"); return; end wpb_db = {}; for wpb_TradeSkillIdx = 1, numPotions, 1 do			tradeskillName, _, _, _ = GetTradeSkillInfo(wpb_TradeSkillIdx); craftDescription = GetCraftDescription(wpb_TradeSkillIdx); tradeskillLink = GetTradeSkillItemLink(wpb_TradeSkillIdx);

wpb_db[wpb_TradeSkillIdx] = {tradeskillName, craftDescription, tradeskillLink};

end wpb_AddMsg("found "..numPotions.." potions."); return; end

-- Perl-like split/join functions >> http://lua-users.org/wiki/SplitJoin function pstrsplit(delimiter, text) local list = {} local pos = 1 if strfind("", delimiter, 1) then -- this would result in endless loops error("delimiter matches empty string!") end while 1 do   local first, last = strfind(text, delimiter, pos) if first then -- found? tinsert(list, strsub(text, pos, first-1)) pos = last+1 else tinsert(list, strsub(text, pos)) break end end return list end

function pstrjoin(delimiter, list) local len = getn(list) if len == 0 then return "" end local string = list[1] for i = 2, len do    string = string .. delimiter .. list[i] end return string end