Untitled
unknown
lua
2 years ago
7.1 kB
13
Indexable
local frame = CreateFrame("Frame")
local flareItemIDs = {
23769, -- red-smoke-flare
23768, -- white-smoke-flare
25886, -- purple-smoke-flare
23770, -- blue-smoke-flare
23771, -- green-smoke-flare
}
local prizePot = 0
local payoutSet = false
local raceInProgress = false
local raceStartTime = 0
local elapsedTime = 0
local raceName = "Race Event"
local timerUpdateInterval = 20 * 60
local countdownInProgress = false
local countdownSeconds = 10
local totalDeaths = 0
local totalRacers = 0
local totalGoldDistributed = 0
local playerGUID = UnitGUID("player")
local function UpdateTimer()
if raceInProgress then
local currentTime = GetServerTime()
elapsedTime = math.max(currentTime - raceStartTime, 60) -- Ensure at least 1 minute is displayed
local minutesElapsed = math.floor(elapsedTime / 60)
local secondsElapsed = elapsedTime % 60
SendChatMessage("Elapsed Time: " .. minutesElapsed .. " minutes " .. secondsElapsed .. " seconds", "RAID")
end
end
local function EndRace()
if raceInProgress then
SendChatMessage("Thank you for coming to \"" .. raceName .. "\". This is the race's final stats:", "RAID")
SendChatMessage("Deaths: " .. totalDeaths, "RAID")
SendChatMessage("Total Elapsed Time: " .. elapsedTime .. " seconds", "RAID")
SendChatMessage("Total Racers: " .. totalRacers, "RAID")
SendChatMessage("Total Gold Distributed: " .. prizePot .. " gold", "RAID")
raceInProgress = false
raceStartTime = 0
elapsedTime = 0
totalDeaths = 0
totalRacers = 0
totalGoldDistributed = 0
else
print("No race in progress.")
end
end
function frame:OnEvent(event, ...)
if event == "UNIT_SPELLCAST_SUCCEEDED" then
local unit, _, _, _, spellID = ...
if unit == "player" then
local spellName = GetSpellInfo(spellID)
for _, flareItemID in ipairs(flareItemIDs) do
local itemName = GetItemInfo(flareItemID)
if itemName and spellName and itemName == spellName then
local playerName = UnitName("player")
SendChatMessage(playerName .. " used a " .. itemName .. "!", "RAID")
SendChatMessage(playerName .. " used a " .. itemName .. "!", "RAID_WARNING")
return
end
end
end
elseif event == "UNIT_AURA" then
local unit = ...
if UnitIsPlayer(unit) and UnitInRaid(unit) then
local isAssistant = false
local isLeader = false
for i = 1, GetNumGroupMembers() do
local _, _, subgroup, _, _, _, _, _, _, _, _, isAssistant, isLeader = GetRaidRosterInfo(i)
if isAssistant or isLeader then
-- Ignore assistants and raid leaders
return
end
end
totalRacers = totalRacers + 1 -- Increment totalRacers
local buffs = {}
for i = 1, 40 do
local _, _, _, _, _, _, _, _, _, spellId = UnitAura(unit, i, "HELPFUL")
if spellId then
local spellName = GetSpellInfo(spellId)
table.insert(buffs, spellName)
else
break
end
end
local debuffs = {}
for i = 1, 40 do
local _, _, _, _, _, _, _, _, _, spellId = UnitAura(unit, i, "HARMFUL")
if spellId then
local spellName = GetSpellInfo(spellId)
table.insert(debuffs, spellName)
else
break
end
end
local playerName = UnitName(unit)
if #buffs > 0 then
SendChatMessage(playerName .. " gained buffs: " .. table.concat(buffs, ", "), "RAID")
end
if #debuffs > 0 then
SendChatMessage(playerName .. " gained debuffs: " .. table.concat(debuffs, ", "), "RAID")
end
end
elseif event == "COMBAT_LOG_EVENT_UNFILTERED" then
local timestamp, eventType, _, sourceGUID, sourceName, _, _, destGUID, destName, _, _, spellID, spellName = ...
if raceInProgress and eventType == "UNIT_DIED" then
local playerName = UnitName("player")
if destName == playerName then
totalDeaths = totalDeaths + 1
end
end
end
end
frame:SetScript("OnEvent", frame.OnEvent)
SLASH_START_RACE1 = "/race"
SlashCmdList["START_RACE"] = function(msg)
if msg == "" then
if not IsInRaid() then
print("You are not in a raid. You must be in a raid to use /race.")
return
end
if not payoutSet or raceName == "Race Event" then
print("Payout or Race Name not set. Use /payout and /racename to set the prize pot and race name.")
return
end
if not raceInProgress then
print("Starting the race!")
raceInProgress = true
raceStartTime = GetServerTime()
countdownInProgress = true
C_Timer.NewTicker(1, function()
if countdownInProgress then
countdownSeconds = countdownSeconds - 1
if countdownSeconds > 0 then
SendChatMessage("Race starting in " .. countdownSeconds .. " seconds!", "RAID_WARNING")
else
SendChatMessage("GO GO GO! The race has started for \"" .. raceName .. "\"!", "RAID_WARNING")
countdownInProgress = false
countdownSeconds = 10
end
end
end)
else
print("Race is already in progress.")
end
else
print("Invalid command. Usage: /race")
end
end
SLASH_SET_PAYOUT1 = "/payout"
SlashCmdList["SET_PAYOUT"] = function(msg)
local amount = tonumber(string.match(msg:lower(), "%d+"))
if amount and amount > 0 then
prizePot = amount
payoutSet = true
print("Prize pot set to " .. amount .. " gold. You can now use /race.")
SendChatMessage("The prize pot for the race has been set to " .. amount .. " gold!", "RAID_WARNING")
else
print("Invalid command. Usage: /payout gold amount")
end
end
SLASH_SET_RACENAME1 = "/racename"
SlashCmdList["SET_RACENAME"] = function(msg)
if msg ~= "" then
raceName = msg
SendChatMessage("Welcome to " .. raceName .. "! The race will start shortly.", "RAID_WARNING")
print("Race name set to: " .. raceName)
else
print("Invalid command. Usage: /racename <message>")
end
end
SLASH_END_RACE1 = "/endrace"
SlashCmdList["END_RACE"] = function()
EndRace()
end
Editor is loading...
Leave a Comment