Skip to content

Commit

Permalink
Merge pull request #9 from FinalAsgard/feature/TrackDeathsPerDay
Browse files Browse the repository at this point in the history
Feature/track deaths per day
  • Loading branch information
jonzenor authored Dec 11, 2022
2 parents 3496e27 + e4de315 commit d53a28b
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion Core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ SLASH_DEATHCOUNTER2 = "/dcr"

local defaults = {
deaths = 0,
deathsToday = 0,
lastDeath = time(),
lastDayDied = date("%d"),
guildAnnounce = false,
usePopupAlert = false,
}
Expand All @@ -22,7 +24,10 @@ function f:OnEvent(event, addOnName)
deathTimeString = self:CalculateTimesinceDeath(FADeathCounterDB.lastDeath, currentTime)

self:RecordDeathTime(currentTime)

self:CountDeath()
self:CountDeathsToday()

self:PrintDeaths(deathTimeString)
self:AnnounceToGuild(deathTimeString)
end
Expand Down Expand Up @@ -60,8 +65,20 @@ function f:CountDeath()
FADeathCounterDB.deaths = FADeathCounterDB.deaths + 1
end

function f:CountDeathsToday()
today = date("%d")

if (today ~= FADeathCounterDB.lastDayDied) then
FADeathCounterDB.lastDayDied = today
FADeathCounterDB.deathsToday = 0
end

FADeathCounterDB.deathsToday = FADeathCounterDB.deathsToday + 1
end

function f:PrintDeaths(deathTimeString)
print("You have died " .. FADeathCounterDB.deaths .. " times!")
print("You died " .. FADeathCounterDB.deathsToday .. " times today.")

if (FADeathCounterDB.deaths == 1) then
useText = "Started Tracking "
Expand Down Expand Up @@ -128,7 +145,7 @@ end
function f:AnnounceToGuild(deathTimeString)
if (f:ShouldAnnounceToGuild() == true) then
playerName = f:GetPlayerName()
SendChatMessage(playerName .. " just died! They died " .. FADeathCounterDB.deaths .. " times. " .. playerName .. "'s last death was " .. deathTimeString .. "ago.", "GUILD")
SendChatMessage(playerName .. " just died! They died " .. FADeathCounterDB.deathsToday .. " times today. " .. playerName .. "'s last death was " .. deathTimeString .. "ago.", "GUILD")
end
end

Expand Down Expand Up @@ -158,6 +175,7 @@ SlashCmdList.DEATHCOUNTER = function(msg)

if msg == "" or msg == nil then
print("You have died " .. FADeathCounterDB.deaths .. " times.")
print("You died " .. FADeathCounterDB.deathsToday .. " times today.")

if (FADeathCounterDB.deaths > 0) then
print("Last died " .. f:CalculateTimesinceDeath(FADeathCounterDB.lastDeath, time()))
Expand Down

0 comments on commit d53a28b

Please sign in to comment.