-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathboss_kill_announcer.lua
More file actions
43 lines (35 loc) · 1.83 KB
/
boss_kill_announcer.lua
File metadata and controls
43 lines (35 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
local T = {}
local function KilledCreature(event, player, enemy)
if(not enemy:IsWorldBoss()) then return end -- not world boss, skip
local pguid, cguid = player:GetGUIDLow(), enemy:GetGUIDLow() -- get guids
local ktime = 0 -- get time (default to 0)
if(T[pguid] and T[pguid][cguid]) then
ktime = os.time() - T[pguid][cguid] -- (now - start) = passed time (seconds)
T[pguid][cguid] = nil -- erase record
end
local participants
if(player:IsInGroup()) then
participants = "with his friends (Total: "..player:GetGroup():GetMembersCount().." guys, "
else
participants = "Alone! ("
end
SendWorldMessage("[PVE] |Hplayer:"..player:GetName().."|h["..player:GetName().."]|h killed ["..enemy:GetName().."] "..participants.."Use: "..ktime.." seconds)")
end
local function EnterCombat(event, player, enemy)
if(not enemy:IsWorldBoss()) then return end -- not world boss, skip saving time etc
local pguid, cguid = player:GetGUIDLow(), enemy:GetGUIDLow() -- get guids
if(not T[pguid]) then -- if the player doesnt have a table
T[pguid] = {} -- create a new table for him
elseif(T[pguid][cguid]) then -- check that we are not already in combat with the creature (already saved a time)
return -- we are, already a time saved. Stop before saving
end
T[pguid][cguid] = os.time() -- save combat start time
end
local function LeaveCombat(event, player)
if(T[player:GetGUIDLow()]) then
T[player:GetGUIDLow()] = nil -- erase combat time records
end
end
RegisterPlayerEvent(7, KilledCreature) -- executes when a player kills a creature
RegisterPlayerEvent(33, EnterCombat) -- executes on each player attack attempt (spammy)
RegisterPlayerEvent(34, LeaveCombat) -- executes when a player leaves combat