POINTSHOP 2: Points per kill?

Before anyone gets the idea of complaining about how many times this has been asked, that was concerning pointshop ONE not pointshop TWO and yeah i honestly have looked everywhere for the answer but nooe, i cannot find anything.

As simple as the title is, ive managed to grab some code about kills into pointshop and changed the varibles a bit but still i get errors about this code not working:

hook.Add( "DoPlayerDeath", "Give Points", function( vict, att, dmginfo )

	if not (IsValid(att) and att:IsPlayer() and att:Team() != vict:Team()) then return end

	ply:PS2_AddStandardPoints ( 5, "Nice job!" )


I am not new to lua as i know my stuff but this just goes over my head so could someone put me on the right track? And yeah i think those who are experianced in lua are probably laughing at me now.


Litteraly all you need (Unless you’ve never seen Lua before)

When you are on TTT then it is already built in. If you are on antorher gamemode, then just use the script , JasonMan34 referred you to. Remember to replace killer:PS_GivePoints(num) to killer:PS2_AddStandardPoints(num) etc.

Ive test the code whilst modifing the parts so this is what i have atm:

hook.Add("Initialize", "Points.Initialize", function()
	if !ROLE_INNOCENT then return end
	local RolePoints = {
			[ROLE_DETECTIVE] = -30,
			[ROLE_INNOCENT] = -10,
			[ROLE_TRAITOR] = 200
			[ROLE_DETECTIVE] = -50,
			[ROLE_INNOCENT] = -20,
			[ROLE_TRAITOR] = 50
			[ROLE_DETECTIVE] = 200,
			[ROLE_INNOCENT] = 25,
			[ROLE_TRAITOR] = -30

	local function NotifyPlayer(ply, killer)
		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()..".")
			killer:PrintMessage(HUD_PRINTTALK, "[TTT] Shop: You were awarded "..num.." points for killing "..ply:Nick()..", they were a(n) "..ply:GetRoleString()..".")

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

And im getting the error code of:

^sorry for putting it in a image since the CMD window doesn’t allow me to copy shi*t

local num = RolePoints[killer:GetRole()][ply:GetRole()]

You don’t have the table anymore, that’s why it is not working I think.

Ah yes sorry i realised i pasted the wrong code and the one now in the post before is the correct code

In which line does the error appear?
(copy the line pls)

And if you meant what line of code, im not sure what is causing this error to appear

Also if it helps, this code is in a lua file in the pointshops server autorun folder

Post your sv_pointshopkills.lua here.

Okay, no offense, if you want to get anywhere in lua, you’re going to have to start thinking and putting in effort, not just copypasting parts you see.

You’ve used vict, att, dmginfo in the function arguments but you’re trying to give points to ply, which is not a thing by default in gmod - it’s just what a lot of people refer to the player as. So you want to use att, because they are the attacker/killer in this instance - I’m curious, what did you think ply was referring to in this instance of a hook?

I’d also recommend using PlayerDeath rather than DoPlayerDeath, but that’s just a me thing

I’d recommend using PlayerDeath or PostPlayerDeath as the timing might be a bit weird.

Thanks for the insight but i have been trying hard myself not to go and copy and paste since i get nowhere with and i have tried again to code this myself by visiting the lua wiki often but im getting not very far with that but i assumed ply was a short index for player. So should i replace ply with something that the game would recognise?

As far as I can see: You should repace ply with att

Hmm still nothing, players dont earn points when they kill other :confused:

The game doesn’t recognize anything in terms of stuff like this, it’s up to you to define ply/whatever, usually done in the hooks passed arguments. However in situations like this where you have multiple players (victim and attacker) you will obviously need multiple different ‘names’ for them, so just ply won’t work.

All you have to do is look at the arguments of the function, then look at the hook on the Wiki to see which number argument is what. Then use whatever it is named in the parentheses of your script. In this case, it’s ‘att’ (the attacker)

Ahh yes okay that makes sence, thanks