Advertisement
Rochet2

Untitled

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