Help: TTT points

Hi, I’m wondering if its possible for someone to create a working script that gives a innocent player points for pointshop when he kills a Traitor, Gives traitor points when he kills an innocent or detective. Detective points when he kills a traitor. some points are removed for innocents killing innocents / detectives and same for when a detective kills a innocent or detective.

Regards,
Dave

Add me on steam

I made a script for this a week ago:
[lua]
–To be placed in lua/autorun/server/
local RolePoints = {
[ROLE_DETECTIVE] = {[ROLE_DETECTIVE] = -30,–Killed Detective as Detective
[ROLE_INNOCENT] = -10,–Killed Innocent as Detective
[ROLE_TRAITOR] = 20
},
[ROLE_INNOCENT] = {[ROLE_DETECTIVE] = -50,
[ROLE_INNOCENT] = -20,
[ROLE_TRAITOR] = 20
},
[ROLE_TRAITOR] = {[ROLE_DETECTIVE] = 50,
[ROLE_INNOCENT] = 25,
[ROLE_TRAITOR] = -30
}
}

function NotifyPlayer(ply, killer)
local num = RolePoints[killer:GetRole()][ply:GetRole()]
local bool = string.find(num, “-”)
ply:PrintMessage(HUD_PRINTTALK, “[TTT] Shop: You were killed by “…killer:Nick()…” they were “…killer:GetRoleString()…”.”)
if bool then
killer:PrintMessage(HUD_PRINTTALK, “[TTT] Shop: You had “…num…” points taken away for killing “…ply:Nick()…”, they were a(n) “…ply:GetRoleString()…”.”)
else
killer:PrintMessage(HUD_PRINTTALK, “[TTT] Shop: You were awarded “…num…” points for killing “…ply:Nick()…”, they were a(n) “…ply:GetRoleString()…”.”)
end
killer:PS_GivePoints(num)
end

function PointShopDeathHook(ply, killer, dmginfo)
if !IsValid(killer) and !killer:IsPlayer() and !IsValid(ply) and !ply:IsPlayer() then return end
if GetRoundState() == ROUND_ACTIVE then
NotifyPlayer(ply, killer)
end
end
hook.Add(“DoPlayerDeath”, “PointShopDeathHook”, PointShopDeathHook)
[/lua]

I’ve tried this within my server placed in autorun/server and while in-game Nothing happens, I dont even get an error.

In fact its still in my server files I believe.

You’re doing something wrong because it works 100%.

I put the code in scite, Saved the file as tpoints.lua and placed in autorun/server then restarted the server.

I figured out the issue. Since it’s in autorun it runs before the gamemode is loaded so the enums wern’t created.
[lua]
–To be placed in lua/autorun/server/
– ROLE_INNOCENT = 0
– ROLE_TRAITOR = 1
– ROLE_DETECTIVE = 2
– ROLE_NONE = ROLE_INNOCENT
local RolePoints = {
[2] = {[2] = -30,–Killed Detective as Detective
[0] = -10,–Killed Innocent as Detective
[1] = 20–Killed Traitor as Detective
},
[0] = {[2] = -50,–Killed Detective as Innocent
[0] = -20,–Killed Innocent as Innocent
[1] = 20–Killed Traitor as Innocent
},
[1] = {[2] = 50,–Killed Detective as Traitor
[0] = 25,–Killed Innocent as Traitor
[1] = -30–Killed Traitor as Traitor
}
}

function NotifyPlayer(ply, killer)
local num = RolePoints[killer:GetRole()][ply:GetRole()]
local bool = string.find(num, “-”)
ply:PrintMessage(HUD_PRINTTALK, “[TTT] Shop: You were killed by “…killer:Nick()…” they were “…killer:GetRoleString()…”.”)
if bool then
killer:PrintMessage(HUD_PRINTTALK, “[TTT] Shop: You had “…num…” points taken away for killing “…ply:Nick()…”, they were a(n) “…ply:GetRoleString()…”.”)
else
killer:PrintMessage(HUD_PRINTTALK, “[TTT] Shop: You were awarded “…num…” points for killing “…ply:Nick()…”, they were a(n) “…ply:GetRoleString()…”.”)
end
killer:PS_GivePoints(num)
end

function PointShopDeathHook(ply, killer, dmginfo)
if !IsValid(killer) and !killer:IsPlayer() and !IsValid(ply) and !ply:IsPlayer() then return end
if GetRoundState() == ROUND_ACTIVE then
NotifyPlayer(ply, killer)
end
end
hook.Add(“DoPlayerDeath”, “PointShopDeathHook”, PointShopDeathHook)
[/lua]
I’ve filled it with comments, it shouldn’t be hard to figure out.

Okay thanks for the help there, I’ll give it a quick test and let you know how it turns out.

–Edit—
Just done a test run on the server and its working like a charm now, Thanks again for the help some good work there :slight_smile:

could you add in a bit so that when you commit suicide it doesn’t count?

Now you’re just reaching man. It couldn’t take you more than 2 minutes to look up how to do a simple if statement checking for this.



if ply == killer then return end


Another quick question, is there a way to make the text [ttt] the color BLUE, points the color GREEN and the victim RED? Then the rest white? I’m not sure how to do it with ‘PrintMessage(HUD_PRINTTALK’

When i use this script whenever a T kills someone everyone CTD’s saying something about too many buffer errors.

Hey!

I am experiencing one problem with this code I’m not sure if it is an issue on my end but when someone dies from world damage such as dying from fall damage the body is removed from the world and you are put straight into spectator mode.

Thanks in advance.

What means this

[ERROR] lua/autorun/server/points.lua:22: attempt to call method ‘GetRole’ (a nil value)

  1. NotifyPlayer - lua/autorun/server/points.lua:22
  2. fn - lua/autorun/server/points.lua:36
    3. unknown - lua/ulib/shared/hook.lua:183

[ERROR] lua/autorun/server/points.lua:22: attempt to call method ‘GetRole’ (a nil value)

  1. NotifyPlayer - lua/autorun/server/points.lua:22
  2. fn - lua/autorun/server/points.lua:36
    3. unknown - lua/ulib/shared/hook.lua:183
    4. TakeDamageInfo - [C]:-1
    5. unknown - gamemodes/terrortown/gamemode/player.lua:848

-snip-

dumb bump, please die.

So it works in autorun now? This is really useful if so Brandonj4, thanks for this.

This is the updated code I posted a while ago.

[lua]
//lua/autorun/server

hook.Add(“Initialize”, “Points.Initialize”, function()
if !ROLE_INNOCENT then return end

local RolePoints = {
	[ROLE_DETECTIVE] = {
		[ROLE_DETECTIVE] = -30,
		[ROLE_INNOCENT] = -10,
		[ROLE_TRAITOR] = 200
	},
	[ROLE_INNOCENT] = {
		[ROLE_DETECTIVE] = -50,
		[ROLE_INNOCENT] = -20,
		[ROLE_TRAITOR] = 50
	},
	[ROLE_TRAITOR] = {
		[ROLE_DETECTIVE] = 200,
		[ROLE_INNOCENT] = 25,
		[ROLE_TRAITOR] = -30
	}
}

local function NotifyPlayer(ply, killer)
	local num = RolePoints[killer:GetRole()][ply:GetRole()]
	local bool = string.find(num, "-")
	if bool then
		killer:PrintMessage(HUD_PRINTTALK, "[TTT] Shop: You had "..num.." points taken away for killing "..ply:Nick()..", they were a(n) "..ply:GetRoleString()..".")
	else
		killer:PrintMessage(HUD_PRINTTALK, "[TTT] Shop: You were awarded "..num.." points for killing "..ply:Nick()..", they were a(n) "..ply:GetRoleString()..".")
	end
	
	 killer:PS_GivePoints(num)
end

hook.Add("DoPlayerDeath", "PS.GivePointsOnDeath", function(ply, killer, dmginfo)
	if !IsValid(killer) or !killer:IsPlayer() or !IsValid(ply) or !ply:IsPlayer() or (ply == killer) then return end
	if GetRoundState() == ROUND_ACTIVE then
		NotifyPlayer(ply, killer)
	end
end)

end)
[/lua]

Can you help out on my question about a headcrab launcher? it hasn’t gotten any replies.

http://forum.facepunch.com/showthread.php?t=1351276