All pastes #95639 Raw Edit

Something

public text v1 · immutable
#95639 ·published 2006-07-22 05:35 UTC
rendered paste body


--	Lets you set timers with labels, especially useful for MC mob respawn timing
--	5/10/05
--	I ripped my code from RaidMeter and IBRezTimer. Please don't hurt me.


----------------------------------------------------------------------------------------------------------------------
--- ON LOAD
----------------------------------------------------------------------------------------------------------------------

local ProTimers_out;
local ProTimers_elapsed = 0;
local ProTimers_CORE_HOUNDS_COLLAPSED = 0;
local ProTimers_CORE_HOUNDS_COLLAPSED_TIME = 0;


function ProTimers_initialize()
	SlashCmdList["PTIM"] = ProTimers_SlashHandler; 
	SLASH_PTIM1 = "/pt"; 
	SLASH_PTIM2 = "/protimers";
	
	
	
	
	this:RegisterEvent("ON_UPDATE");
	this:RegisterEvent("VARIABLES_LOADED");
	this:RegisterEvent("CHAT_MSG_COMBAT_HOSTILE_DEATH");
	this:RegisterEvent("CHAT_MSG_MONSTER_EMOTE");

	-- 5 minute moving average by default
	ProTimers_window = 300;
	ProTimersFrame:Show();
end


-----------------------------------------------------------------------------------------------------------------------
--- CHAT FUNCTIONS
-----------------------------------------------------------------------------------------------------------------------

function ProTimers_SlashHandler(word)
	local msg = word;
	local _, _, command, args = string.find(msg, "(%w*)%s*(.*)");
	command = string.lower(command);
	--DEFAULT_CHAT_FRAME:AddMessage("command: " .. command .. " args: " .. args);
	
	if((command == "set") or (command == "time")) then
		local _, _, arg1, arg2, arg3 = string.find(args, "(%d*):?(%d*)%s*(.*)");
		if((arg2 == "") or (arg2 == nil))then
			arg2 = "0";
		end
		if((arg1 == "") or (arg1 == nil)) then
			DEFAULT_CHAT_FRAME:AddMessage("|cff00ff00ProTimers: |cffffffffInvalid argument")
		else
			local time = tonumber(arg1)*60 + tonumber(arg2);
			ProTimers_AddTimer(arg3, time, 0);
		end
	elseif((command == "bg") or (command == "background")) then
		ProTimers_BG(args);
	elseif(command == "clear") then
		ProTimers_clear(args);
	elseif(command == "print") then
		ProTimers_print(args);
	elseif(command == "alert") then
		ProTimers_alert(args);
	elseif(command == "announce") then
		ProTimers_announce(args);
	elseif(command == "preannounce") then
		ProTimers_preannounce(args);
	elseif(command == "mob") then
		ProTimers_mob(args);
	elseif(command == "hook") then
		ProTimers_hook(args);
	elseif(command == "repeat") then
		local _, _, arg1, arg2, arg3 = string.find(args, "(%d*):?(%d*)%s*(.*)");
		if((arg2 == "") or (arg2 == nil))then
			arg2 = "0";
		end
		if((arg1 == "") or (arg1 == nil)) then
			DEFAULT_CHAT_FRAME:AddMessage("|cff00ff00ProTimers: |cffffffffInvalid argument")
		else
			local time = tonumber(arg1)*60 + tonumber(arg2);
			ProTimers_AddTimer(arg3, time, time);
		end
	else
		DEFAULT_CHAT_FRAME:AddMessage("|cff00ff00ProTimers Commands:");
		DEFAULT_CHAT_FRAME:AddMessage("  |cffffffffset ................ |cff00ff00sets a timer");
		DEFAULT_CHAT_FRAME:AddMessage("  |cffffffffset ................ |cff00ff00sets a repeating timer");
		DEFAULT_CHAT_FRAME:AddMessage("  |cffffffffmob .............. |cff00ff00sets a timer based on mobname");
		DEFAULT_CHAT_FRAME:AddMessage("  |cffffffffbg ................. |cff00ff00toggles the frame background");
		DEFAULT_CHAT_FRAME:AddMessage("  |cffffffffalert .............. |cff00ff00toggles expired timers announced to you");
		DEFAULT_CHAT_FRAME:AddMessage("  |cffffffffannounce ...... |cff00ff00toggles nearly expired timers announced to raid");
		DEFAULT_CHAT_FRAME:AddMessage("  |cffffffffpreannounce .... |cff00ff00toggles expired timers announced to raid");
		DEFAULT_CHAT_FRAME:AddMessage("  |cffffffffhook ............. |cff00ff00allows you to hook mobdeaths to start timers");
		DEFAULT_CHAT_FRAME:AddMessage("  |cffffffffprint .............. |cff00ff00prints your timers");
		
	end
end
	

function ProTimers_clear(args)

	args = string.lower(args);
	if((args == "") or (args =="all")) then

		ProTimers_names = {"nil", "nil", "nil", "nil", "nil", "nil", "nil", "nil", "nil"};
		ProTimers_times = {-50, -50, -50, -50, -50, -50, -50, -50, -50, -50};
		ProTimers_bank = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
		ProTimers_repeat = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
	else
		local slot = tonumber(args);
		ProTimers_bank[slot] = -1;
	end
	
end

function ProTimers_print(args)
	local r;

	if (GetNumRaidMembers()>0) then 
		r = "raid"; 
	elseif(GetNumPartyMembers()>0) then 
		r = "party"; 
	else 
		r = "yell";
	end
	

	args = string.lower(args);
	if((args == "") or (args =="all")) then
		for i=1, 10, 1 do
			if ProTimers_bank[i] ~= -1 then
				SendChatMessage("ProTimers: " .. ProTimers_names[i] .. " - " .. date("%M:%S", ProTimers_times[i]) .. " remaining", r);
			end
		end
				
	else
		local num = tonumber(args);
		if ProTimers_bank[num] ~= -1 then
			SendChatMessage("ProTimers: " .. ProTimers_names[num] .. " - " .. date("%M:%S", ProTimers_times[num]) .. " remaining", r);
		end
					
	end
	
end

function ProTimers_BG(args)
	if((args == "on") or (args == "show")) then
		ProTimersFrame:SetBackdropColor(0, 0, 0, 1);
		ProTimersFrame:SetBackdropBorderColor(1, 1, 1, 1);
		ProTimers_CONFIG.bgvis = 1;
		ProTimersFrame:EnableMouse(1);
	elseif((args == "off") or (args == "hide")) then 
		ProTimersFrame:SetBackdropColor(0, 0, 0, 0);
		ProTimersFrame:SetBackdropBorderColor(0, 0, 0, .0);
		ProTimers_CONFIG.bgvis = 0;
		ProTimersFrame:EnableMouse(nil);
	else
		if(ProTimers_CONFIG.bgvis == 0) then
			ProTimersFrame:SetBackdropColor(0, 0, 0, 1);
			ProTimersFrame:SetBackdropBorderColor(1, 1, 1, 1);
			ProTimers_CONFIG.bgvis = 1;
			ProTimersFrame:EnableMouse(1);
		else
			ProTimersFrame:SetBackdropColor(0, 0, 0, 0);
			ProTimersFrame:SetBackdropBorderColor(0, 0, 0, .0);
			ProTimers_CONFIG.bgvis = 0;
			ProTimersFrame:EnableMouse(nil);
		end
	end
	DEFAULT_CHAT_FRAME:AddMessage("|cff00ff00ProTimers: |cffffffffBackground status set to " .. ProTimers_CONFIG.bgvis)
end

function ProTimers_alert(args)
	if((args == "on") or (args == "show")) then
		ProTimers_CONFIG.alert = 1;
	elseif((args == "off") or (args == "hide")) then 
		ProTimers_CONFIG.alert = 0;
	else
		if(ProTimers_CONFIG.alert == 0) then
			ProTimers_CONFIG.alert = 1;
		else
			ProTimers_CONFIG.alert = 0;
		end
	end
	DEFAULT_CHAT_FRAME:AddMessage("|cff00ff00ProTimers: |cffffffffAlert status set to " .. ProTimers_CONFIG.alert);
end

function ProTimers_announce(args)
	if((args == "on") or (args == "show")) then
			ProTimers_CONFIG.announce = 1;
		elseif((args == "off") or (args == "hide")) then 
			ProTimers_CONFIG.announce = 0;
		else
			if(ProTimers_CONFIG.announce == 0) then
				ProTimers_CONFIG.announce = 1;
			else
				ProTimers_CONFIG.announce = 0;
			end
	end
	DEFAULT_CHAT_FRAME:AddMessage("|cff00ff00ProTimers: |cffffffffAnnounce status set to " .. ProTimers_CONFIG.announce);
end

function ProTimers_preannounce(args)
	if((args == "on") or (args == "show")) then
			ProTimers_CONFIG.preannounce = 1;
		elseif((args == "off") or (args == "hide")) then 
			ProTimers_CONFIG.preannounce = 0;
		else
			if(ProTimers_CONFIG.preannounce == 0) then
				ProTimers_CONFIG.preannounce = 1;
			else
				ProTimers_CONFIG.preannounce = 0;
			end
	end
	DEFAULT_CHAT_FRAME:AddMessage("|cff00ff00ProTimers: |cffffffffPre-announce status set to " .. ProTimers_CONFIG.announce);
end

function ProTimers_mob(args)
	if(not (args)) then
		args = "";
	end
	
	args = string.lower(args);
	
	if((args == "ach") or (args == "ancient core hound")) then
		ProTimers_AddTimer("Ancient Core Hound", 18*60, 0);
	elseif (args == "firelord") then
		ProTimers_AddTimer("Firelord", 120*60, 0);
	elseif (args == "lava annihilator") then
		ProTimers_AddTimer("Lava Annihilator", 120*60, 0);
	elseif (args == "lava surger") then
		ProTimers_AddTimer("Lava Surger", 28*60, 0);
	elseif (args == "imps") then
		ProTimers_AddTimer("Imp Pack", 7*60, 0);
	elseif ((args == "chp") or (args == "core hound pack")) then
		ProTimers_AddTimer("Core Hound Pack", 60*60, 0);
	elseif ((args == "lp") or (args == "lava pack")) then
		ProTimers_AddTimer("Lava Pack", 120*60, 0);
	end
end

function ProTimers_hook(args)
	local _, _, arg1, arg2 = string.find(args, "(%w*)%s*(.*)");
	
	local switch = 0;
	
	if string.lower(arg1) == "on" then
		switch = 1;
	elseif string.lower(arg1) == "off" then
		switch = -1;
	else
		if arg2 ~= nil and arg2 ~= "" then
			arg2 = arg1 .. " " .. arg2;
		else
			arg2 = arg1;
		end
	end
	
	arg2 = string.lower(arg2);
	
	if((arg2 == "ach") or (arg2 == "ancient core hound")) then
		if switch == 1 then
			ProTimers_CONFIG.hooks["Ancient Core Hound"] = 1;
		elseif switch == -1 then
			ProTimers_CONFIG.hooks["Ancient Core Hound"] = 0;
		else
			if ProTimers_CONFIG.hooks["Ancient Core Hound"] == 0 then
				ProTimers_CONFIG.hooks["Ancient Core Hound"] = 1;
			else
				ProTimers_CONFIG.hooks["Ancient Core Hound"] = 0;
			end
		end
		DEFAULT_CHAT_FRAME:AddMessage("|cff00ff00ProTimers: |cffffffffHooks - Ancient Core Hound set to " .. ProTimers_CONFIG.hooks["Ancient Core Hound"]);
	elseif (arg2 == "lava surger") then
		if switch == 1 then
			ProTimers_CONFIG.hooks["Lava Surger"] = 1;
		elseif switch == -1 then
			ProTimers_CONFIG.hooks["Lava Surger"] = 0;
		else
			if ProTimers_CONFIG.hooks["Lava Surger"] == 0 then
				ProTimers_CONFIG.hooks["Lava Surger"] = 1;
			else
				ProTimers_CONFIG.hooks["Lava Surger"] = 0;
			end
		end
		DEFAULT_CHAT_FRAME:AddMessage("|cff00ff00ProTimers: |cffffffffHooks - Lava Surger set to " .. ProTimers_CONFIG.hooks["Lava Surger"]);
	elseif ((arg2 == "chp") or (arg2 == "core hound pack")) then
		if switch == 1 then
			ProTimers_CONFIG.hooks["Core Hound Pack"] = 1;
		elseif switch == -1 then
			ProTimers_CONFIG.hooks["Core Hound Pack"] = 0;
		else
			if ProTimers_CONFIG.hooks["Core Hound Pack"] == 0 then
				ProTimers_CONFIG.hooks["Core Hound Pack"] = 1;
			else
				ProTimers_CONFIG.hooks["Core Hound Pack"] = 0;
			end
		end
		DEFAULT_CHAT_FRAME:AddMessage("|cff00ff00ProTimers: |cffffffffHooks - Core Hound Pack set to " .. ProTimers_CONFIG.hooks["Core Hound Pack"]);
	end
end



-----------------------------------------------------------------------------------------------------------------------
--- HELPERS
-----------------------------------------------------------------------------------------------------------------------



function ProTimers_AddTimer(name, time, rep)
	local found = 0;
	for i=1, 10, 1 do
		if (ProTimers_bank[i] == -1) then
			found = i;
			break;
		end
	end
	
	if (found == 0) then
		DEFAULT_CHAT_FRAME:AddMessage("|cff00ff00ProTimers: |cffffffffToo many timers");
	else
		ProTimers_times[found] = time;
		ProTimers_names[found] = name;
		ProTimers_bank[found] = 1;
		ProTimers_repeat[found] = rep;
	end
end

function ProTimers_onalert(num)
	if(ProTimers_CONFIG.alert == 1) then
		UIErrorsFrame:AddMessage("ProTimers: " .. ProTimers_names[num] .. " expired", 1.0, .82, 0, 1.0, UIERRORS_HOLD_TIME);
	end
end

function ProTimers_onprealert(num)
	if(ProTimers_CONFIG.alert == 1) then
		UIErrorsFrame:AddMessage("ProTimers: " .. ProTimers_names[num] .. " - 2:00 remaining", 1.0, .82, 0, 1.0, UIERRORS_HOLD_TIME);
	end
end
	
function ProTimers_onannounce(num)
	if(ProTimers_CONFIG.announce == 1) then
		local r;
		if (GetNumRaidMembers()>0) then 
			r = "raid"; 
		elseif(GetNumPartyMembers()>0) then 
			r = "party"; 
		else 
			r = "yell";
		end
		SendChatMessage("ProTimers: " .. ProTimers_names[num] .. " expired", r);
	end
end

function ProTimers_onpreannounce(num)
	if(ProTimers_CONFIG.preannounce == 1) then
		local r;
		if (GetNumRaidMembers()>0) then 
			r = "raid"; 
		elseif(GetNumPartyMembers()>0) then 
			r = "party"; 
		else 
			r = "yell";
		end
		SendChatMessage("ProTimers: " .. ProTimers_names[num] .. " - 2:00 remaining", r);
	end
end
		
----------------------------------------------------------------------------------------------------------------------
--- ON EVENT
----------------------------------------------------------------------------------------------------------------------

function ProTimers_OnEvent(event)
	if(event == "VARIABLES_LOADED") then
		if(not (ProTimers_CONFIG)) then
			ProTimers_CONFIG = {};
		end
		
		if(not (ProTimers_CONFIG.announce)) then
					ProTimers_CONFIG.announce = 0;
		end
		if(not (ProTimers_CONFIG.preannounce)) then
					ProTimers_CONFIG.preannounce = 0;
		end
		
		if(not (ProTimers_CONFIG.alert)) then
					ProTimers_CONFIG.alert = 0;
		end
		
		if(not (ProTimers_CONFIG.bgvis)) then
					ProTimers_CONFIG.bgvis = 1;
		end
		
		if (not (ProTimers_CONFIG.hooks)) then
					ProTimers_CONFIG.hooks = {["Ancient Core Hound"] = 0, ["Lava Surger"] = 0, ["Core Hound Pack"] = 0};
		
		end
		
		
		
		if (not (ProTimers_names)) then
			ProTimers_names = {"nil", "nil", "nil", "nil", "nil", "nil", "nil", "nil", "nil"};
		end
		
		if (not (ProTimers_times)) then
			ProTimers_times = {-50, -50, -50, -50, -50, -50, -50, -50, -50, -50};
		end
		
		if (not (ProTimers_bank)) then
			ProTimers_bank = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
		end
		
		if (not (ProTimers_repeat)) then
			ProTimers_repeat = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
		end
		
		
		
		
		
		
		
		DEFAULT_CHAT_FRAME:AddMessage("|cff00ff00ProTimers loaded");
		if(ProTimers_CONFIG.bgvis == 1) then
			ProTimersFrame:SetBackdropColor(0, 0, 0, 1);
			ProTimersFrame:SetBackdropBorderColor(1, 1, 1, 1);
		else
			ProTimersFrame:SetBackdropColor(0, 0, 0, 0);
			ProTimersFrame:SetBackdropBorderColor(0, 0, 0, .0);
		end
	elseif (event == "CHAT_MSG_COMBAT_HOSTILE_DEATH") then
		if string.find(arg1, "Ancient Core Hound") ~= nil and ProTimers_CONFIG.hooks["Ancient Core Hound"] == 1 then
			ProTimers_AddTimer("Ancient Core Hound", 18*60, 0);
		
		--elseif string.find(arg1, "Core Hound") ~= nil and ProTimers_CONFIG.hooks["Core Hound Pack"] == 1 then
		--	local toshow = 1;
		--	for i=1, 10, 1 do
		--		if ProTimers_bank[i] ~= -1 and ProTimers_names[i] == "Core Hound Pack" and ProTimers_times[i] > 59*60 then
		--			toshow = 0;
		--		end
		--	end
		--	if toshow == 1 then
		--		ProTimers_AddTimer("Core Hound Pack", 60*60, 0);
		--	end
		
		elseif string.find(arg1, "Lava Surger") ~= nil and ProTimers_CONFIG.hooks["Lava Surger"] == 1 then
			ProTimers_AddTimer("Lava Surger", 28*60, 0);
		elseif string.find(arg1, "Magmadar") ~= nil then
			ProTimers_CONFIG.hooks["Ancient Core Hound"] = 0;
			DEFAULT_CHAT_FRAME:AddMessage("|cff00ff00ProTimers: |cffffffffHooks - Ancient Core Hound set to 0");
		elseif string.find(arg1, "Garr") ~= nil then
			ProTimers_CONFIG.hooks["Lava Surger"] = 0;
			DEFAULT_CHAT_FRAME:AddMessage("|cff00ff00ProTimers: |cffffffffHooks - Lava Surger set to 0");
		end
		
	elseif (event == "CHAT_MSG_MONSTER_EMOTE") then
		--DEFAULT_CHAT_FRAME:AddMessage(arg1 .. arg2);
		if string.find(arg1, "collapse") ~= nil and string.find(arg1, "smolder") ~= nil and ProTimers_CONFIG.hooks["Core Hound Pack"] == 1 then
			
			if ProTimers_CORE_HOUNDS_COLLAPSED == 0 then
				ProTimers_CORE_HOUNDS_COLLAPSED = 1;
				ProTimers_CORE_HOUNDS_COLLAPSED_TIME = 0;
			elseif ProTimers_CORE_HOUNDS_COLLAPSED == 4 and ProTimers_CORE_HOUNDS_COLLAPSED_TIME <= 10 then
				ProTimers_CORE_HOUNDS_COLLAPSED = 0;
				ProTimers_AddTimer("Core Hound Pack", 60*60, 0);
			else
				ProTimers_CORE_HOUNDS_COLLAPSED = ProTimers_CORE_HOUNDS_COLLAPSED + 1;
			end
			--DEFAULT_CHAT_FRAME:AddMessage(ProTimers_CORE_HOUNDS_COLLAPSED .. " down in " .. ProTimers_CORE_HOUNDS_COLLAPSED_TIME);
		end
		
	end
end



function ProTimers_OnUpdate(elapsed)
	ProTimers_elapsed = ProTimers_elapsed + elapsed;
	ProTimers_CORE_HOUNDS_COLLAPSED_TIME = ProTimers_CORE_HOUNDS_COLLAPSED_TIME + elapsed;
	if ProTimers_CORE_HOUNDS_COLLAPSED_TIME > 12 then
		ProTimers_CORE_HOUNDS_COLLAPSED = 0;
	end
	
	--DEFAULT_CHAT_FRAME:AddMessage(ProTimers_elapsed);
	if ProTimers_elapsed > 1 then
		for i = 1, 10, 1 do
			if (ProTimers_bank[i] ~= -1) then
				ProTimers_times[i] = ProTimers_times[i] - 1;
			end

			if (ProTimers_times[i] ~= nil) then
				if (ProTimers_times[i] < -15) then
					ProTimers_bank[i] = -1;
				end
			end
		end

		for j=1, 10, 1 do
			local found = 0;
			local done = 0;
			for i=1, 10, 1 do
				if (ProTimers_bank[i] == -1 and found == 0) then
					found = i;
				end
				if (ProTimers_bank[i] ~= -1 and found ~= 0 and done == 0) then
					ProTimers_bank[i] = -1;
					ProTimers_bank[found] = 1;
					ProTimers_names[found] = ProTimers_names[i];
					ProTimers_times[found] = ProTimers_times[i];
					ProTimers_repeat[found] = ProTimers_repeat[i];
					done = 1;
				end
			end
		end

		local found;
		for i=1, 10, 1 do
			if (ProTimers_bank[i] == -1) then
				found = i;
				break;
			end
		end

		for i = 1, 10, 1 do
			local row = getglobal("ProTimersItem"..i);
			local where = getglobal("ProTimersItem"..i.."Name");
			local rate = getglobal("ProTimersItem"..i.."Rate");
			if (i > found-1) then
				row:Hide();
			else
				row:Show();
				where:Show();
				rate:Show();
				where:SetText(ProTimers_names[i]);
				if (ProTimers_times[i] > 3600) then
					rate:SetText(math.floor(ProTimers_times[i]/3600) .. ":" .. date("%M:%S", ProTimers_times[i]));
				else
					rate:SetText(date("%M:%S", ProTimers_times[i]));
				end
				if (ProTimers_times[i] ~= nil) then
					if (ProTimers_times[i] < 15) then
						local tester = math.ceil(ProTimers_times[i]);
						if ((tester == -1) or (tester == -3) or (tester == -5) or (tester == -7) or (tester == -9) or (tester == -11) or (tester == -13) or (tester == -15) or (tester == 1) or (tester == 3) or (tester == 5) or (tester == 7) or (tester == 9) or (tester == 11) or (tester == 13) or (tester == 15)) then
							where:SetTextColor(1,0,0);
							rate:SetTextColor(1,0,0);
						else
							where:SetTextColor(1.0, 0.82, 0.0);
							rate:SetTextColor(1.0, 0.82, 0.0);

						end


					else
						where:SetTextColor(1.0, 0.82, 0.0);
						rate:SetTextColor(1, 1, 1);
					end

					if (ProTimers_times[i] < 0) then
						rate:SetText(date("%M:%S", 0));
					end


					
					if ((math.ceil(ProTimers_times[i]) == 0)) then
						ProTimers_times[i] = -1;
						ProTimers_onalert(i);
						ProTimers_onannounce(i);
						if ProTimers_repeat[i] > 0 then
							ProTimers_AddTimer(ProTimers_names[i], ProTimers_repeat[i], ProTimers_repeat[i]);
					
						end
					end
					
					if ((math.ceil(ProTimers_times[i]) == 120)) then
						ProTimers_onprealert(i);
						ProTimers_onpreannounce(i);
					end

				end
			end
		end
		ProTimers_elapsed = ProTimers_elapsed - 1;
	end
end