Advertisement
Guest User

Untitled

a guest
May 25th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.41 KB | None | 0 0
  1. print("log_base: Loading...")
  2.  
  3. local LogBase = {}
  4.  
  5. -- Logging functions
  6. local LOG_FATAL = 1
  7. local LOG_WARN = 2
  8. local LOG_INFO = 4
  9. local LOG_DEBUG = 8
  10. function LogBase.LogMessage(importance, msg) hook.Call("LogMessage", nil, "general", importance, msg) end
  11.  
  12. function LogBase.PlayerInfo(ply)
  13.   if ply:IsPlayer() then
  14.     return "'"..ply:Nick().."' ("..ply:SteamID()..") ("..ply:IPAddress()..")"
  15.   else
  16.     return "(Non-Player)"
  17.   end
  18. end
  19.  
  20. function LogBase.Position(ent)
  21.   if ent:IsValid() then
  22.     local pos = ent:GetPos()
  23.     return "("..tostring(math.floor(pos.x))..", "..tostring(math.floor(pos.y))..", "..tostring(math.floor(pos.z))..")"
  24.   else
  25.     return "(Invalid)"
  26.   end
  27. end
  28.  
  29. hook.Add("PlayerConnect","LogBase_PlayerConnect",function(name,address)
  30.   LogBase.LogMessage(LOG_INFO, "Connect => '"..name.."' ("..address..").")
  31. end)
  32.  
  33. hook.Add("PlayerInitialSpawn","LogBase_PlayerInitialSpawn",function(ply)
  34.   LogBase.LogMessage(LOG_INFO, "Loaded => "..LogBase.PlayerInfo(ply)..".")
  35. end)
  36.  
  37. hook.Add("PlayerDisconnected","LogBase_PlayerDisconnected",function(ply)
  38.   LogBase.LogMessage(LOG_INFO, "Disconnect => "..LogBase.PlayerInfo(ply)..".")
  39. end)
  40.  
  41. hook.Add("PlayerSay","LogBase_PlayerSay",function(ply,text,toall)
  42.   LogBase.LogMessage(LOG_INFO, LogBase.PlayerInfo(ply).." said => '"..text.."'.")
  43. end)
  44.  
  45. -- Too verbose?
  46. hook.Add("EntityTakeDamage","LogBase_PlayerTakeDamage",function(victim,inflictor,attacker,damage,dmginfo)
  47.   if victim:IsPlayer() then
  48.     if !attacker:IsValid() then
  49.       LogBase.LogMessage(LOG_DEBUG, inflictor:GetClass().." damaged ("..damage.." health) => "..LogBase.PlayerInfo(victim).." at "..LogBase.Position(victim)..".")
  50.     elseif !attacker:IsPlayer() then
  51.       LogBase.LogMessage(LOG_DEBUG, inflictor:GetClass().." at "..LogBase.Position(attacker).." damaged ("..damage.." health) => "..LogBase.PlayerInfo(victim).." at "..LogBase.Position(victim).." (Distance: "..tostring(math.floor(attacker:GetPos():Distance(victim:GetPos())))..").")
  52.     else
  53.       LogBase.LogMessage(LOG_DEBUG, LogBase.PlayerInfo(attacker).." at "..LogBase.Position(attacker).." damaged ("..inflictor:GetClass()..", "..damage.." health) => "..LogBase.PlayerInfo(victim).." at "..LogBase.Position(victim).." (Distance: "..tostring(math.floor(attacker:GetPos():Distance(victim:GetPos())))..").")
  54.     end
  55.   end
  56. end)
  57.  
  58. hook.Add("PlayerDeath","LogBase_PlayerDeath",function(victim,inflictor,killer)
  59.   if victim == killer then
  60.     LogBase.LogMessage(LOG_INFO, LogBase.PlayerInfo(killer).." suicided at "..LogBase.Position(killer)..".")
  61.   elseif !killer:IsValid() then
  62.     LogBase.LogMessage(LOG_INFO, inflictor:GetClass().." killed => "..LogBase.PlayerInfo(victim).." at "..LogBase.Position(victim)..".")
  63.   elseif !killer:IsPlayer() then
  64.     LogBase.LogMessage(LOG_WARN, inflictor:GetClass().." at "..LogBase.Position(killer).." killed => "..LogBase.PlayerInfo(victim).." at "..LogBase.Position(victim).." (Distance: "..tostring(math.floor(killer:GetPos():Distance(victim:GetPos())))..").")
  65.   else
  66.     LogBase.LogMessage(LOG_WARN, LogBase.PlayerInfo(killer).." at "..LogBase.Position(killer).." killed ("..inflictor:GetClass()..") => "..LogBase.PlayerInfo(victim).." at "..LogBase.Position(victim).." (Distance: "..tostring(math.floor(killer:GetPos():Distance(victim:GetPos())))..").")
  67.   end
  68. end)
  69.  
  70. hook.Add("PlayerSpawn","LogBase_PlayerSpawn",function(ply)
  71.   LogBase.LogMessage(LOG_INFO, LogBase.PlayerInfo(ply).." respawned.")
  72. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement