Problem with getting deaths per life

Hello, I am making a Killstreaks addon.
I have some code for tracking killstreaks but it’s inaccurate.

Problems:

  • One shot/headshots do not get counted
  • If player health is less than 10, it starts to count up

Code:



LocalPlayer().killstreak = 0

local delay = CurTime()

hook.Add("PlayerTraceAttack", "killstreaks", function(ply, data)
	if delay < CurTime() then
		if data:GetDamage() >= ply:Health() then
			LocalPlayer().killstreak = LocalPlayer().killstreak + 1
			delay = CurTime()+0.1
		end
	end
end)

hook.Add("Think","ks_death",function()
	if not LocalPlayer():Alive() then LocalPlayer().killstreak = 0 end
end)

hook.Add("HUDPaint","killstreaks",function()
	draw.DrawText("Killstreak: "..LocalPlayer().killstreak,"NameTags",ScrW()-400,0,color_white)
	draw.DrawText("Kills: "..LocalPlayer():Frags(),"NameTags",ScrW()-400,48,color_white)
	draw.DrawText("Deaths: "..LocalPlayer():Deaths(),"NameTags",ScrW()-400,96,color_white)
end)

timer.Create("ks_sounds",5,0,function()
	if LocalPlayer().killstreak == 2 then LocalPlayer():EmitSound("chatsounds/autoadd/instagib/doublekill.ogg") end
	if LocalPlayer().killstreak == 3 then LocalPlayer():EmitSound("chatsounds/autoadd/nonhuman/oh baby a triple.OGG") end
	if LocalPlayer().killstreak == 10 then LocalPlayer():EmitSound("chatsounds/autoadd/instagib/monsterkill.ogg") end
	if LocalPlayer().killstreak == 25 then LocalPlayer():EmitSound("chatsounds/autoadd/instagib/holyshit.ogg") end
	if LocalPlayer().killstreak == 50 then LocalPlayer():EmitSound("chatsounds/autoadd/morsh/airhorn.ogg") end
	if LocalPlayer().killstreak == 75 then LocalPlayer():EmitSound("chatsounds/autoadd/nonhuman/mom get the camera mommy mommy mommy oh my god.OGG") end
	if LocalPlayer().killstreak == 100 then LocalPlayer():EmitSound("chatsounds/autoadd/nonhuman/wombocombo.OGG") chat.AddText(Color(math.Rand(0,255),math.Rand(0,255),math.Rand(0,255)),"[Killstreaks] ",color_white,"Either you're really good, are a dev, are a hacker or found how to change the value") end
	if not LocalPlayer():Alive() then LocalPlayer():EmitSound("chatsounds/autoadd/windows/winxp shutdown.ogg") end
end)

chat.AddText(Color(math.Rand(0,255),math.Rand(0,255),math.Rand(0,255)),"[Killstreaks] ",Color(128,255,0),"KILLSTREAKS ACTIVE (warning, buggy)")


Thanks,
Flex

[editline]21st August 2014[/editline]

Pointless bump just because people don’t feel like helping apperently.

-snip- (this is clientside, my bad. I’m not quite sure how to grab a player death clientside)

Don’t use Think either, might as well make your own pseudo think timer with a 1 second delay.

You really should delete everything (Except sound list) and use the PlayerDeath with net messages, and not…PlayerTraceAttack

Could you give me an example of how I would do this, I’m not really good with net messages yet so I kinda need pointers of what to do

Net Library Usage