Skip to content

Commit

Permalink
Update TFTB.lua
Browse files Browse the repository at this point in the history
  • Loading branch information
Gogo1951 authored Dec 4, 2024
1 parent 6d389c7 commit bba71fc
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions TFTB.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@ TFTB.config = {
"WHOA",
"WINK",
"YES"
},
thankYouMessages = {
-- Define thank-you messages
"Thanks, you're the best! (="
}
}
TFTB.cooldowns = {}

-- Function to clear expired cooldowns
local function clearExpiredCooldowns(now)
for key, expiry in pairs(TFTB.cooldowns) do
if expiry < now then
Expand All @@ -32,19 +37,31 @@ local function clearExpiredCooldowns(now)
end
end

-- Function to check if a unit is in the party, raid, or battleground
local function isInPartyRaidOrBG(sourceGUID)
for i = 1, GetNumGroupMembers() do
local unitID = UnitInBattleground("player") and "raid" .. i or IsInRaid() and "raid" .. i or "party" .. i
local unitID = IsInRaid() and "raid" .. i or "party" .. i
if UnitGUID(unitID) == sourceGUID then
return true
end
end
return false
end

-- Function to check if a unit is a valid player on the same faction
local function isValidSameFactionPlayer(unit)
if not UnitExists(unit) or not UnitIsPlayer(unit) then
return false
end

local playerFaction = UnitFactionGroup("player")
local targetFaction = UnitFactionGroup(unit)
return playerFaction == targetFaction
end

-- Function to determine if the event should be processed
function TFTB:shouldProcessEvent()
return not self.state.hasLoggedIn and not self.state.inCombat
return self.state.hasLoggedIn == false and self.state.inCombat == false
end

-- Combat Log Event Processing
Expand Down Expand Up @@ -73,6 +90,12 @@ function TFTB:OnCombatEvent(...)
return
end

-- Check faction alignment
local sourceUnitID = "target"
if UnitGUID(sourceUnitID) == sourceGUID and not isValidSameFactionPlayer(sourceUnitID) then
return
end

-- Avoid sending multiple thanks during the cooldown
if destGUID == UnitGUID("player") and not TFTB.cooldowns[sourceGUID] then
TFTB.cooldowns[sourceGUID] = now + TFTB.config.cooldownDuration
Expand Down Expand Up @@ -126,10 +149,16 @@ local function cheerAndThankTarget()
-- Get the current target's name
local targetName = GetUnitName("target", true)

-- Check if the target is valid and on the same faction
if not isValidSameFactionPlayer("target") then
print("|cff00C853TFTB|r : Invalid target. Please select a valid player on the same faction.")
return
end

if targetName then
-- Select a random emote from the list
local emote = TFTB.config.randomEmotes[math.random(#TFTB.config.randomEmotes)]
local message = thankYouMessages[math.random(#thankYouMessages)]
local message = TFTB.config.thankYouMessages[math.random(#TFTB.config.thankYouMessages)]

-- Perform the emote targeted at the player
DoEmote(emote, targetName)
Expand Down

0 comments on commit bba71fc

Please sign in to comment.