Advertisement
Guest User

Kill Announce

a guest
Jan 9th, 2015
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.87 KB | None | 0 0
  1. local T = {}
  2.  
  3. local function KilledCreature(event, player, enemy)
  4.     if(not enemy:IsWorldBoss()) then return end -- not world boss, skip
  5.     local pguid, cguid = player:GetGUIDLow(), enemy:GetGUIDLow() -- get guids
  6.    
  7.     local ktime = 0 -- get time (default to 0)
  8.     if(T[pguid] and T[pguid][cguid]) then
  9.         ktime = os.time() - T[pguid][cguid] -- (now - start) = passed time (seconds)
  10.         T[pguid][cguid] = nil -- erase record
  11.     end
  12.        
  13.     local participants
  14.         if(player:IsInGroup()) then
  15.                 participants = "with his friends (Total: "..player:GetGroup():GetMembersCount().." guys, "
  16.         else
  17.                 participants = "Alone! ("
  18.         end
  19.    
  20.     SendWorldMessage("[PVE] |Hplayer:"..player:GetName().."|h["..player:GetName().."]|h killed ["..enemy:GetName().."] "..participants.."Use: "..ktime.." seconds)")
  21. end
  22.  
  23. local function EnterCombat(event, player, enemy)
  24.     if(not enemy:IsWorldBoss()) then return end -- not world boss, skip saving time etc
  25.     local pguid, cguid = player:GetGUIDLow(), enemy:GetGUIDLow() -- get guids
  26.    
  27.     if(not T[pguid]) then -- if the player doesnt have a table
  28.         T[pguid] = {} -- create a new table for him
  29.     elseif(T[pguid][cguid]) then -- check that we are not already in combat with the creature (already saved a time)
  30.         return -- we are, already a time saved. Stop before saving
  31.     end
  32.     T[pguid][cguid] = os.time() -- save combat start time
  33. end
  34.  
  35. local function LeaveCombat(event, player)
  36.         if(T[player:GetGUIDLow()]) then
  37.                 T[player:GetGUIDLow()] = nil -- erase combat time records
  38.         end
  39. end
  40.  
  41. RegisterPlayerEvent(7, KilledCreature) -- executes when a player kills a creature
  42. RegisterPlayerEvent(33, EnterCombat) -- executes on each player attack attempt (spammy)
  43. RegisterPlayerEvent(34, LeaveCombat) -- executes when a player leaves combat
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement