Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print("log_base: Loading...")
- local LogBase = {}
- -- Logging functions
- local LOG_FATAL = 1
- local LOG_WARN = 2
- local LOG_INFO = 4
- local LOG_DEBUG = 8
- function LogBase.LogMessage(importance, msg) hook.Call("LogMessage", nil, "general", importance, msg) end
- function LogBase.PlayerInfo(ply)
- if ply:IsPlayer() then
- return "'"..ply:Nick().."' ("..ply:SteamID()..") ("..ply:IPAddress()..")"
- else
- return "(Non-Player)"
- end
- end
- function LogBase.Position(ent)
- if ent:IsValid() then
- local pos = ent:GetPos()
- return "("..tostring(math.floor(pos.x))..", "..tostring(math.floor(pos.y))..", "..tostring(math.floor(pos.z))..")"
- else
- return "(Invalid)"
- end
- end
- hook.Add("PlayerConnect","LogBase_PlayerConnect",function(name,address)
- LogBase.LogMessage(LOG_INFO, "Connect => '"..name.."' ("..address..").")
- end)
- hook.Add("PlayerInitialSpawn","LogBase_PlayerInitialSpawn",function(ply)
- LogBase.LogMessage(LOG_INFO, "Loaded => "..LogBase.PlayerInfo(ply)..".")
- end)
- hook.Add("PlayerDisconnected","LogBase_PlayerDisconnected",function(ply)
- LogBase.LogMessage(LOG_INFO, "Disconnect => "..LogBase.PlayerInfo(ply)..".")
- end)
- hook.Add("PlayerSay","LogBase_PlayerSay",function(ply,text,toall)
- LogBase.LogMessage(LOG_INFO, LogBase.PlayerInfo(ply).." said => '"..text.."'.")
- end)
- -- Too verbose?
- hook.Add("EntityTakeDamage","LogBase_PlayerTakeDamage",function(victim,inflictor,attacker,damage,dmginfo)
- if victim:IsPlayer() then
- if !attacker:IsValid() then
- LogBase.LogMessage(LOG_DEBUG, inflictor:GetClass().." damaged ("..damage.." health) => "..LogBase.PlayerInfo(victim).." at "..LogBase.Position(victim)..".")
- elseif !attacker:IsPlayer() then
- 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())))..").")
- else
- 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())))..").")
- end
- end
- end)
- hook.Add("PlayerDeath","LogBase_PlayerDeath",function(victim,inflictor,killer)
- if victim == killer then
- LogBase.LogMessage(LOG_INFO, LogBase.PlayerInfo(killer).." suicided at "..LogBase.Position(killer)..".")
- elseif !killer:IsValid() then
- LogBase.LogMessage(LOG_INFO, inflictor:GetClass().." killed => "..LogBase.PlayerInfo(victim).." at "..LogBase.Position(victim)..".")
- elseif !killer:IsPlayer() then
- 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())))..").")
- else
- 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())))..").")
- end
- end)
- hook.Add("PlayerSpawn","LogBase_PlayerSpawn",function(ply)
- LogBase.LogMessage(LOG_INFO, LogBase.PlayerInfo(ply).." respawned.")
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement