Adding Traitor Kills to Scoreboard TTT

Hey guys,

I’m developing a TTT server, and I’d like to make it so that the traitor’s kills show up on the scoreboard during round to other traitors, and that they show up to everyone else after the round ends.

I saw something that did this on ScriptFodder, but the person who made it no longer has an active subscription, and I wouldn’t imagine it would be too difficult (although I’m pretty terrible at Lua).

Thanks in advance.

https://scriptfodder.com/scripts/view/376 for clarification.

First of all, you need to store the traitor kills.
the easiest way would be to hook into PlayerDeath an check if attacker IsActiveTraitor and victim isnt.
Maybe even with an NWInt.

Also you need to set it to 0 at the beginning. Depens on what you want to store. Only round? then try TTTBeginRound. For an Map or alltime? Then use PlayerConnect.
Also if alltime, try to use PData. It isn’t so much hastle then, except you want to display this information on an webpage, then try to read up on tmysql4 or mysqloo.

So after this information gathering, you need to display the information on your scoreboard. an easy way would be to use the TTTScoreboardColumns hook and return the NWint.

Voíla, you got your traitor counter.

edit://
just thought about something. That way it could be used for ghosting.
The easiest solution to this would be NOT to use the NWInt in the TTTScoreboardColumns, but instead make an second NWint (i call them private and public)
While you update the private one every kill, you display the public one, which you then set to the private one every time TTTEndRound is called.
so in there something like:
[lua]for k,v in pairs(player.GetAll()) do
v:SetNWInt(“PublicTraitorKills”, v:GetNWInt(“PrivateTraitorKills”)
end[/lua]

Would be a good idea, Just update the public one to the private one using the round end/start hook and the private ones through a kill hook.

Hey guys,

Thanks a bunch for your help.

Unfortunately, I’m completely hopeless with Lua, and doubt I would be able to even begin to figure out how to do this.

Sorry to be a bother, do you think anybody could walk me through this?

Thanks

[lua]if SERVER then – since this stuff is serversided, so it won’t run and error on the client.

hook.Add("PlayerDeath", "TraitorKills_Private", function(victim, inflictor, attacker)
	if not IsValid(attacker) then return end -- Check if the Attacker is valid. If it's not, the script won't run.
	if attacker:IsPlayer() and attacker:IsActiveTraitor() then -- Then check if it's an Traitor and an Player (not trigger or simmilar)
		if victim:IsActiveTraitor() then return end -- If he kills his own teamate, then it stop running.
		attacker:SetNWInt("TraitorKills_Private", attacker:GetNWInt("TraitorKills_Private") + 1) -- Setting the NWInt to current value + 1
	end
end)

hook.Add("TTTBeginRound", "TraitorKills_Private2Public", function()
	for k, v in pairs(player.GetAll()) do  -- Get all Players
		v:SetNWInt("TraitorKills_Public", v:GetNWInt("TraitorKills_Private")) -- Setting the Public NWInt to the value of the private.
	end
end)

hook.Add("PlayerInitialSpawn", "TraitorKills_Init", function(ply) 
	ply:SetNWInt("TraitorKills_Private", 0) -- Setting it to 0 on first Spawn, so it won't error.
	ply:SetNWInt("TraitorKills_Public", 0) -- same here.
end)

else – and here the Client side stuff.

hook.Add("TTTScoreboardColumns", "TraitorKills_Public_Display", function(pnl)
	pnl:AddColumn("Traitor Kills", function(ply) return ply:GetNWInt("TraitorKills_Public") end) --Adding the Column
end)	

end[/lua]
something along this lines. btw it’s untested.