Skip to content

Instantly share code, notes, and snippets.

@NanoAi
Last active August 10, 2017 17:01
Show Gist options
  • Save NanoAi/b4af3cebfd728a4e27d09ec0a3a0481c to your computer and use it in GitHub Desktop.
Save NanoAi/b4af3cebfd728a4e27d09ec0a3a0481c to your computer and use it in GitHub Desktop.
Custom Death Notices for Garry's Mod
-- Not Finished
-- Change Notes: Added `domination` logic. [UNTESTED]
local tag = "DeathNotice+"
local physpick = false
local function IsPlayer(ent)
return IsValid(ent) and ent:GetClass() == "player" or false
end
hook.Add("PhysgunPickup", tag, function(ply, ent)
if IsValid(ply) and IsValid(ent) and not physpick then
physpick = true
local can_touch = hook.Run('PhysgunPickup', ply, ent)
if can_touch then
ent.droppedby = false -- Indicate that this entity was picked up, and that this variable is ready to be filled.
end
physpick = false
end
end)
hook.Add("PhysgunDrop", tag, function(ply, ent)
if IsValid(ply) and IsValid(ent) and ent.droppedby == false then
ent.droppedby = {ply = ply, when = CurTime()}
end
end)
local function OnPlayerTakeDamage(ply, dmginfo)
local inflictor = dmginfo:GetInflictor()
local attacker = dmginfo:GetAttacker()
local actor = attacker or inflictor
local picker = actor.droppedby
if picker and IsPlayer(picker.ply) and not IsPlayer(actor) then
if (picker.when + 7) > CurTime() then
dmginfo:SetAttacker(picker.ply)
actor = picker.ply -- Update `actor` variable.
end
end
ply.lastHurtBy = {ply = actor, when = CurTime()}
end
do
if CLIENT then
local dn = {} -- DeathNotices
local color = {
high = Color(255,0,0,255),
front = Color(255,255,255,255),
back = Color(0,0,0,255),
}
net.Receive(tag .. "Domination", function(len, ply)
local id = net.ReadString()
local streak = net.ReadInt(3)
ply.domination = ply.domination or {}
local key = ply.domination[id]
key.streak = streak
key.dominating = tobool(streak > 5)
end)
local function IsDominating(attacker, victim)
if IsPlayer(victim) and IsPlayer(attacker) then
local data = victim.domination
local id = actor:UserID()
if data and data[id] then
return data[id].dominating or false
else
return false
end
else
return false
end
end
hook.Add("AddDeathNotice", tag, function(attacker, ateam, inflictor, victim, vteam)
color.high = SKIN and SKIN.text_highlight or color.high
color.front = SKIN and SKIN.text_normal or color.front
color.back = SKIN and SKIN.bg_color_dark or color.back
local attacker = {ent = attacker, dominating = IsDominating(attacker, victim), avatar = avatar and avatar.avatars[attacker] or nil}
local victim = {ent = victim, avatar = avatar and avatar.avatars[victim] or nil}
dn[#dn + 1] = function(x, y)
-- Add Draw Stuff Here
end
end)
hook.Add("DrawDeathNotice", tag, function(x, y)
-- Call Draw Stuff Here
end)
end
end
if SERVER then
util.AddNetworkString(tag .. "Domination")
hook.Add("EntityTakeDamage", tag, function(ply, dmginfo)
if IsPlayer(ply) then
OnPlayerTakeDamage(ply, dmginfo)
end
end)
hook.Add("DoPlayerDeath", tag, function(ply, dmginfo)
local killer = dmginfo:GetAttacker() or dmginfo:GetInflictor()
if IsValid(ply) then
if ply.lastHurtBy and ( (ply.lastHurtBy.when + 5) > CurTime() ) then
killer = ply.lastHurtBy.ply
dmginfo:SetAttacker(killer)
end
if IsPlayer(killer) then
local kid = tostring(killer:UserID())
ply.domination = ply.domination or {}
for k,v in next, ply.domination do
if k ~= kid and v.streak > 0 then
v.streak = v.streak - 1
if v.streak <= 0 then
ply.domination[k] = nil
end
end
end
local key = ply.domination[kid]
key.streak = key.streak and key.streak + 1 or 1
key.dominating = tobool(key.streak > 5)
net.Start(tag .. "Domination")
net.WriteString(kid)
net.WriteInt(key.streak, 3)
net.Send(ply)
end
end
end)
end
@NanoAi
Copy link
Author

NanoAi commented Jul 21, 2017

Concept

Standard
deathnotification-concept
Dominating
deathnotification-concept-dominating
Layout
deathnotification-concept-explained

Information

The shadow is an offset faded square behind the players avatar and name, it has no functions it's just there for looks. I've forgotten what the initial colour of the shadow was and at what opacity I had it set so just play around with it until it looks good.

The fading lines on the left are the same colour as the initial background however they are at different opacities. The opacities from left to right are as follows... %5, %10, %33, %66. I think it would create a cool effect especially if the notification was to fade in from the left.

The victims name (right), should be at a preset width away from the border, however their avatar should be placed on the first letter of their name.

The killers name (left), should follow the same rules.

When a user is leading in kills or is ahead in points they should get a little crown on their avatar to show that they are #1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment