Guest User

Untitled

a guest
Jul 28th, 2020
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.09 KB | None | 0 0
  1. local tracked_players = {}
  2.  
  3. local function start_tracking(ent)
  4.    if not ent or not ent:IsValid() or not ent:IsPlayer() then return end
  5.    table.insert(tracked_players, ent)
  6. end
  7.  
  8. local function stop_tracking(ent)
  9.    if not ent or not ent:IsValid() or not ent:IsPlayer() then return end
  10.    table.RemoveByValue(tracked_players, ent) -- this doesn't error if player is not found: https://wiki.facepunch.com/gmod/table.RemoveByValue
  11. end
  12.  
  13.  
  14. -- feed this into your callback
  15. local function track(attacker, path, dmginfo)
  16.    local ent = path.Entity
  17.    if not ent or not ent:IsValid() or not ent:IsPlayer() then return end
  18.    
  19.    timer.Simple(3, function()
  20.       start_tracking(ent)
  21.    end)
  22. end
  23.  
  24.  
  25. hook.Add("PreDrawHalos", "MySWEP.StartHaloTracking", function()
  26.    if #tracked_players < 1 then return end
  27.    halo.Add(tracked_players, Color(255,0,0,255), 1, 1, 2, true, true)
  28. end)
  29.  
  30. hook.Add("PlayerDeath", "MySWEP.StopHaloTracking", stop_tracking)
  31.  
  32. hook.Add("TTTEndRound", "MySWEP.StopHaloTracking", function()
  33.    for _, ply in ipairs(player.GetAll()) do
  34.       stop_tracking(ply)
  35.    end
  36. end)
Advertisement
Add Comment
Please, Sign In to add comment