function PlayerPickedUpProp( ply, ent )
if table.HasValue((immunity5), ply:GetUserGroup()) and ent:GetOwner(table.HasValue((immunity5), ply:GetNWString("usergroup"))) then pickup = true
if table.HasValue((immunity5), ply:GetUserGroup()) and ent:GetOwner(table.HasValue((immunity2), ply:GetNWString("usergroup"))) then pickup = false
if table.HasValue((immunity2), ply:GetUserGroup()) and ent:GetOwner(table.HasValue((immunity2), ply:GetNWString("usergroup"))) then pickup = true
if pickup == true then return true end
if pickup == false then return false end
end
end
end
end
hook.Add( "PhysgunPickup", "PlayerPickedUpProp", PlayerPickedUpProp )
Trying some new things, nothing works, I'll keep trying.
I'm not sure if it makes a different, but
Entity:GetOwner doesn't take any arguments. If you're trying to see if the owner of the prop has one of the ranks in immunity5, for example, you need to do the following:
local owner = ent:GetOwner()
if table.HasValue(immunity5, ply:GetUserGroup()) and table.HasValue(immunity5, owner:GetUserGroup()) then pickup = true end
(To those more experienced with Lua: does Lua support function chaining? I've been working a lot with JavaScript lately so I originally wrote this example with
ent:GetOwner():GetUserGroup(), but I'm not 100% stuff like that works in Lua.)
Another thing is that your code will only return something if it gets through all three if statements, which will never happen (assuming immunity5 and immunity2 have the same value as they did in your first post). You could see this pretty easily if you indented your code, like so:
function PlayerPickedUpProp( ply, ent )
if table.HasValue((immunity5), ply:GetUserGroup()) and ent:GetOwner(table.HasValue((immunity5), ply:GetNWString("usergroup"))) then pickup = true
if table.HasValue((immunity5), ply:GetUserGroup()) and ent:GetOwner(table.HasValue((immunity2), ply:GetNWString("usergroup"))) then pickup = false
if table.HasValue((immunity2), ply:GetUserGroup()) and ent:GetOwner(table.HasValue((immunity2), ply:GetNWString("usergroup"))) then pickup = true
if pickup == true then return true end
if pickup == false then return false end
end
end
end
end
hook.Add( "PhysgunPickup", "PlayerPickedUpProp", PlayerPickedUpProp )
I use two spaces to indent, but you can use whatever works for you. 4 spaces, tabs, etc.
To make sure the final if statements are reached, move them outside of the other if statements like so:
function PlayerPickedUpProp( ply, ent )
if table.HasValue((immunity5), ply:GetUserGroup()) and ent:GetOwner(table.HasValue((immunity5), ply:GetNWString("usergroup"))) then pickup = true
if table.HasValue((immunity5), ply:GetUserGroup()) and ent:GetOwner(table.HasValue((immunity2), ply:GetNWString("usergroup"))) then pickup = false
if table.HasValue((immunity2), ply:GetUserGroup()) and ent:GetOwner(table.HasValue((immunity2), ply:GetNWString("usergroup"))) then pickup = true end
end
end
if pickup == true then return true end
if pickup == false then return false end
end
hook.Add( "PhysgunPickup", "PlayerPickedUpProp", PlayerPickedUpProp )
Taking this a step further, you can simplify those if statements to a simple return call. Because
pickup is either true or false, you don't need to check it's value and return the Boolean literal; you can just return
pickup:
function PlayerPickedUpProp( ply, ent )
if table.HasValue((immunity5), ply:GetUserGroup()) and ent:GetOwner(table.HasValue((immunity5), ply:GetNWString("usergroup"))) then pickup = true
if table.HasValue((immunity5), ply:GetUserGroup()) and ent:GetOwner(table.HasValue((immunity2), ply:GetNWString("usergroup"))) then pickup = false
if table.HasValue((immunity2), ply:GetUserGroup()) and ent:GetOwner(table.HasValue((immunity2), ply:GetNWString("usergroup"))) then pickup = true end
end
end
return pickup
end
hook.Add( "PhysgunPickup", "PlayerPickedUpProp", PlayerPickedUpProp )
This doesn't fix the fact that the inner if statements are useless. If you just want it to block the pickup up of props belonging to players who outrank you, the following code should accomplish the same thing with less code (not that less code is always good):
function PlayerPickedUpProp( ply, ent )
if table.HasValue((immunity5), ply:GetUserGroup()) and ent:GetOwner(table.HasValue((immunity2), ply:GetNWString("usergroup"))) then return false end
return true
end
hook.Add( "PhysgunPickup", "PlayerPickedUpProp", PlayerPickedUpProp )
This will return
false if the player is outranked by the owner of the prop, and
true otherwise.