Disallowing specific player from picking up weapons (any)

Hello, I’m creating my first add-on for TTT and it’s basically !redie, I thought it’d be fun and help me learn.

So far I’ve been messing with this and I’ve come into a problem

[lua]if SERVER then

function redie( ply, text, public )
if (string.sub(text) == “!redie”) then
if ply:IsValid() and !ply:Alive() then
ply:Spawn()
ply:StripWeapons()
end
end
hook.Add( “PlayerSay”, “redie”, redie );
end
end[/lua]

I know GM:PlayerCanPickupWeapon() exists, but I am slightly confused as to how to use it so said player cannot pickup any weapons at all.

Any help?

Use hook.Add and compare the player in the callback to the one that shouldn’t pickup weapons, return false if it should pickup weapons.

Add players to a table that you don’t want to pick up weapons.
On PlayerCanPickupWeapons, check if the player is in that table.

Also, don’t use ply:IsValid(), it can be unreliable; use IsValid(ply)

[lua]if SERVER then

pGhost = {}

function redie( ply, text, public )
if (string.sub(text) == “!redie”) then
if ply:IsValid() and !ply:Alive() then
table.Insert(pGhost, ply)
ply:Spawn()
ply:StripWeapons()
ply:SetTeam(1002)
end
end
hook.Add( “PlayerSay”, “redie”, redie )
end

GM:PlayerCanPickupWeapon(ply)
if pGhost[ply] then
return false end

[/lua]

Correct usage would be like this, correct?

Close, you’re adding ply as a value and then trying to index it by key.

pGhost[ply] = true

This allows you to do:
if pGhost[ply] then-- return nil if they don’t exist, true if they do

That’s what my friend said

[12:38:30 AM] person: instead of insert
[12:38:35 AM] person: table[player] = true
[12:38:37 AM] person: then
[12:38:46 AM] person: if (table[player]) then he’s in the fucking table

so it’d be

[lua]
GM:PlayerCanPickupWeapon(ply)
pGhost[ply] = true
if pGhost[ply] then
return false end[/lua]

You do not want to override TTT’s weapon pickup hook.

If the value of your table is a boolean you can just do:

I can see you’re using “table.Insert” aswell and this won’t work the way you want it to.

It doesn’t seem like you’re researching at all because you’re using lots of functions the wrong way, like “string.sub”.