AutoAcceptRes

AutoAcceptRes

1.5k Downloads

code to add a simple enable/disable switch

anzz1 opened this issue ยท 1 comments

commented

Great little addon, but I'd like to be able to turn the functionality on and off without disabling the whole addon which means reloading the UI. I took the liberty to add it for ya, but I'm too lazy to fork and make a proper pull request so here is the code:

You also need to change ARC_ACCEPT_IN_COMBAT in the .toc file to ARC_CONFIG

AutoResClassic.toc
## SavedVariablesPerCharacter: ARC_CONFIG

AutoResClassic.lua

SLASH_ARC1 = "/arc"

local loaded = false

-- Handle slash commands
SlashCmdList["ARC"] = function(msg)
	
	if not loaded then return end
	
	if msg == "" then
		print("* AutoResClassic")
		print("* /arc enable - To enable auto-resurrection")
		print("* /arc disable - To disable auto-resurrection")
		print("* /arc combat 0 - To not auto-accept resses while resurrector is in combat")
		print("* /arc combat 1 - To auto-accept resses while resurrector is in combat.")
	end
	
	if msg == "combat 0" then
		ARC_CONFIG.ACCEPT_IN_COMBAT = 0
		print("You won't auto-accept resses while the resurrector is in combat.")
	end
	
	if msg == "combat 1" then
		ARC_CONFIG.ACCEPT_IN_COMBAT = 1
		print("You will auto-accept resses even if the resurrector is in combat.")
	end
	
	if msg == "enable" then
		ARC_CONFIG.ENABLE = 1
		print("Auto-resurrect enabled.")
	end
	
	if msg == "disable" then
		ARC_CONFIG.ENABLE = 0
		print("Auto-resurrect disabled.")
	end
	
	if msg == "status" then
		print("Auto-resurrect " .. (ARC_CONFIG.ENABLE==1 and "enabled." or "disabled."))
	end
	
	if msg == "combat" then
		print("Auto-resurrect when resser in combat: " .. ARC_CONFIG.ACCEPT_IN_COMBAT)
	end

end

-- Set up our frame
local frame = CreateFrame("Frame", "AutoResClassicFrame")
frame:RegisterEvent("ADDON_LOADED")
frame:RegisterEvent("RESURRECT_REQUEST")
frame:RegisterEvent("PLAYER_UNGHOST")
frame:RegisterEvent("PLAYER_ALIVE")

-- Handle events
frame:SetScript("OnEvent", function(self, event, ...)
			
	if event == "ADDON_LOADED" then
		local arg1 = ...
		
		if arg1 == "AutoResClassic" then
		
			if ARC_CONFIG == nil then
				ARC_CONFIG = {
					ACCEPT_IN_COMBAT = 0,
					ENABLE = 1
				}
			end
			
			loaded = true
		end
		
	end
		
	if event == "RESURRECT_REQUEST" then
		playerName = ...
		
		if ARC_CONFIG.ENABLE == 0 then
			return
		end
		
		if ARC_CONFIG.ACCEPT_IN_COMBAT == 1 then
			AcceptResurrect()
			
		elseif UnitInParty(playerName) or UnitInRaid(playerName) ~= nil then
		
			if UnitAffectingCombat(playerName) == false then
				AcceptResurrect()
			else
				print("Did not auto-accept res because the resurrector is in combat.")
			end
		
		else
			print("Did not auto-accept res because the resurrector is not in your party. Type '/arc combat 1' to auto-accept resses from anyone.")
		end
		
	end
	
	if event == "PLAYER_UNGHOST" or event == "PLAYER_ALIVE" then
	
		if StaticPopup_Visible("RESURRECT") then
			StaticPopup_Hide("RESURRECT")
		end
		
		if StaticPopup_Visible("RESURRECT_NO_TIMER") then
			StaticPopup_Hide("RESURRECT_NO_TIMER")
		end
		
		if StaticPopup_Visible("RESURRECT_NO_SICKNESS") then
			StaticPopup_Hide("RESURRECT_NO_SICKNESS")
		end
		
	end
	
end)
commented

Hello and thanks for your suggestion, I think it's really cool that you've looked through my code and actually worked on it, in fact you're my first third party contribution on any of my projects. I actually didn't know that you could treat saved variables as tables, so that's really useful info actually.

I'll be updating most of my existing addons (new print formatting, etc) and uploading new ones pretty soon, I'll make sure to take your suggestions into consideration and maybe I'll use tables for saved variables somewhere too. I'll definitely add a on/off switch to ARC.

I'll add your name to the readme for your contribution.