As the title suggests, I'd like to know if there's perhaps a /script or /run command line that will log me out if my character is dead.
The following works, now if only someone could compress it into macro form I would be a happy camper:
Code:
--[[
BGRelease - because having to click the Release button is annoying.
]]
-- Create an addon object using the Ace3 libraries
BGR = LibStub("AceAddon-3.0"):NewAddon("BGR", "AceEvent-3.0")
-- Define the battlegrounds here
local BGs = {
["Winterspring"] = true,
["Tanaris"] = true,
["Stranglethorn Vale"] = true,
}
function BGR:OnInitialize()
-- Default is to enable the addon for a new profile
self.defaults = {
profile = {
enabled = true,
},
}
self.db = LibStub:GetLibrary("AceDB-3.0"):New("BGReleaseDB", self.defaults)
end
function BGR:OnEnable()
-- Watch for the omgidied event
self:RegisterEvent("PLAYER_DEAD")
end
function BGR:OnDisable()
-- Is it polite or necessary to unregister events
-- when using AceEvent? I guess I'll do it just to
-- be safe.
self:UnregisterEvent("PLAYER_DEAD")
end
function BGR:Print(str)
DEFAULT_CHAT_FRAME:AddMessage(str)
end
function BGR:PLAYER_DEAD()
-- If BGR is enabled,
-- and you're in a defined battleground,
-- and you don't have a Soulstone on,
-- then release when killed.
if (self.db.profile.enabled and BGs[GetRealZoneText()] and not HasSoulstone()) then
Logout()
end
end
-- Register slash commands /bgr and /bgrelease.
-- Note: should probably do this with Ace3 stuff, but
-- this is the way I already knew how to do it. Should
-- rewrite later.
SLASH_BGR1 = "/bgr"
SLASH_BGR2 = "/bgrelease"
SlashCmdList["BGR"] = function(input)
local self = BGR
local cmd = string.lower(string.trim(input) or "")
local status = ""
local showSyntax = false
if (cmd == "on") then
-- Enable the addon functionality
self.db.profile.enabled = true
status = "|cFF00FF00Enabled|r"
elseif (cmd == "off") then
-- Disable the addon functionality
self.db.profile.enabled = false
status = "|cFFFF0000Disabled|r"
else
-- Get the current status
if (self.db.profile.enabled) then
status = "|cFF00FF00Enabled|r"
else
status = "|cFFFF0000Disabled|r"
end
showSyntax = true
end
-- Display the current status
self:Print("BGRelease: " .. status)
-- If no valid arguments were passed to the slash command,
-- display the syntax message
if (showSyntax) then
self:Print("BGRelease: '/bgr on' to enable")
self:Print("BGRelease: '/bgr off' to disable")
end
end