Quantcast

* Added a Corpse arrow that can be configured on the general options screen. When enabled, a non-persistent waypoint arrow will be set directing you towards your corpse. It will be removed when you resurrect.

James Whitehead II [12-21-08 - 21:41]
* Added a Corpse arrow that can be configured on the general options screen.  When enabled, a non-persistent waypoint arrow will be set directing you towards your corpse.  It will be removed when you resurrect.
Filename
TomTom.lua
TomTom.toc
TomTom_Config.lua
TomTom_Corpse.lua
diff --git a/TomTom.lua b/TomTom.lua
index bb42551..ab6c2e2 100755
--- a/TomTom.lua
+++ b/TomTom.lua
@@ -54,6 +54,7 @@ function TomTom:ADDON_LOADED(event, addon)
 				general = {
 					confirmremoveall = true,
 					announce = false,
+					corpse_arrow = true,
 				},
 				block = {
 					enable = true,
diff --git a/TomTom.toc b/TomTom.toc
index d52fa40..d242023 100755
--- a/TomTom.toc
+++ b/TomTom.toc
@@ -28,5 +28,6 @@ Localization.ruRU.lua
 TomTom.lua
 TomTom_Waypoints.lua
 TomTom_CrazyArrow.lua
+TomTom_Corpse.lua

 TomTom_Config.lua
diff --git a/TomTom_Config.lua b/TomTom_Config.lua
index 801c54d..13d16d0 100644
--- a/TomTom_Config.lua
+++ b/TomTom_Config.lua
@@ -600,6 +600,14 @@ local function createconfig()
 				min = 0, max = 150, step = 1,
 				arg = "persistence.cleardistance",
 			},
+			corpse_arrow = {
+				type = "toggle",
+				order = 5,
+				name = L["Automatically set a waypoint when I die"],
+				desc = L["TomTom can automatically set a waypoint when you die, guiding you back to your corpse"],
+				width = "double",
+				arg = "general.corpse_arrow",
+			},
 		},
 	}

diff --git a/TomTom_Corpse.lua b/TomTom_Corpse.lua
new file mode 100644
index 0000000..87d5743
--- /dev/null
+++ b/TomTom_Corpse.lua
@@ -0,0 +1,118 @@
+--[[-------------------------------------------------------------------------
+--  Simple module for TomTom that creates a waypoint for your corse
+--  if you happen to die.  No humor, no frills, just straightforward
+--  corpse arrow.  Based on code written and adapted by Yssarill.
+-------------------------------------------------------------------------]]--
+
+local L = TomTomLocals
+local eventFrame = CreateFrame("Frame")
+eventFrame:RegisterEvent("ADDON_LOADED")
+eventFrame:RegisterEvent("PLAYER_ALIVE")
+eventFrame:RegisterEvent("PLAYER_DEAD")
+eventFrame:RegisterEvent("PLAYER_UNGHOST")
+eventFrame:Hide()
+
+local c,z,x,y,uid
+local function GetCorpseLocation()
+	-- Cache the result so we don't scan the maps multiple times
+	if c and z and x and y then
+		return c, z, x, y
+	end
+
+	local oc,oz = GetCurrentMapContinent(), GetCurrentMapZone()
+
+	for i=1,select("#", GetMapContinents()) do
+		SetMapZoom(i)
+		local cx, cy = GetCorpseMapPosition()
+		if cx ~= 0 and cy ~= 0 then
+			c = i
+			break
+		end
+	end
+
+	-- If we found the corpse on a continent, find out which zone it is in
+	if c and c ~= -1 then
+		for i=1,select("#", GetMapZones(c)) do
+			SetMapZoom(c, i)
+			local cx,cy = GetCorpseMapPosition()
+			if cx > 0 and cy > 0 then
+				x = cx
+				y = cy
+				z = i
+				break
+			end
+		end
+	end
+
+	-- Restore the map to its previous zoom level
+	SetMapZoom(oc, oz)
+
+	if c and z and x and y then
+		return c,z,x,y
+	end
+end
+
+local function SetCorpseArrow()
+	if c and z and x and y then
+		uid = TomTom:AddZWaypoint(c, z, x*100, y*100, L["My Corpse"], false, true, true, nil, true, true)
+		return uid
+	end
+end
+
+local function ClearCorpseArrow()
+	if uid then
+		TomTom:RemoveWaypoint(uid)
+		c,z,x,y,uid = nil, nil, nil, nil, nil
+	end
+end
+
+local counter, throttle = 0, 0.5
+eventFrame:SetScript("OnUpdate", function(self, elapsed)
+	counter = counter + elapsed
+	if counter < throttle then
+		return
+	else
+		counter = 0
+		if TomTom.profile.general.corpse_arrow then
+			if GetCorpseLocation() then
+				if SetCorpseArrow() then
+					self:Hide()
+				end
+			end
+		else
+			self:Hide()
+		end
+	end
+end)
+
+eventFrame:SetScript("OnEvent", function(self, event, arg1, ...)
+	if event == "ADDON_LOADED" and arg1 == "TomTom" then
+		self:UnregisterEvent("ADDON_LOADED")
+		if UnitIsDeadOrGhost("player") then
+			self:Show()
+		end
+	end
+
+	if event == "PLAYER_ALIVE" then
+		if UnitIsDeadOrGhost("player") then
+			self:Show()
+		else
+			ClearCorpseArrow()
+		end
+	elseif event == "PLAYER_DEAD" then
+		-- Cheat a bit and avoid the map flipping
+		SetMapToCurrentZone()
+		c = GetCurrentMapContinent()
+		z = GetCurrentMapZone()
+		if not IsInInstance() then
+			x,y = GetPlayerMapPosition("player")
+		end
+		self:Show()
+	elseif event == "PLAYER_UNGHOST" then
+		ClearCorpseArrow()
+	end
+end)
+
+if IsLoggedIn() then
+	eventFrame:GetScript("OnEvent")(eventFrame, "ADDON_LOADED", "TomTom")
+end