I have a code that i was trying to use to disable prop spawning for users below the rank of Admin.
The code I use is;
local hooks = {
"Effect",
"NPC",
"Prop",
"Ragdoll",
"SENT",
"Vehicle"
}
for _, v in pairs (hooks) do
hook.Add("PlayerSpawn"..v, "Disallow_user_"..v, function(client)
if (client:IsUserGroup("admin"), client:IsUserGroup("doubleadmin"), client:IsUserGroup("superadmin"), client:IsUserGroup("superadmin"), client:IsUserGroup("council"), client:IsUserGroup("suduo-root"), client:IsUserGroup("root")) then
return true
end
return false
end)
end
What is wrong with it?
First I suggestion ranks go into a table and run through the function isplayergroup ()
local hooks = {
"Effect",
"NPC",
"Prop",
"Ragdoll",
"SENT",
"Vehicle"
}
Ranks = {
"superadmin" = true,
"doubleadmin" = true,
"admin" = true,
"council" = true,
"suduo-root" = true,
"root" = true
}
for _, v in pairs (hooks) do
hook.Add("PlayerSpawn", "Disallow_user_"..v, function()
if Ranks [LocalPlayer():IsUserGroup()] then
return true
end
return false
end)
--Why are you calling and passing through this function? And why are you calling playerspawn .. v?
I have a code that i was trying to use to disable prop spawning for users below the rank of Admin.
None of the options above will work. I would suggest you read a bit about lua and how it works before you attempt anything.
local hooks = {
"Effect",
"NPC",
"Prop",
"Ragdoll",
"SENT",
"Vehicle"
}
local groups = {
["superadmin"] = true,
["admin"] = true,
["doubleadmin"] = true,
["council"] = true,
["suduo-root"] = true,
["root"] = true
}
for _, v in pairs(hooks) do
hook.Add("PlayerSpawn"..v, "Remove"..v, function(ply)
if (groups[ply:GetUserGroup()]) then
return true;
end
return false;
end);
end
This will, though.
You can, if you know what you are doing. And what's with the semicolon after hook.Add?
I can't think of any situation where you would intentionally break a hook like that. The order in which hook listeners are ran isn't guaranteed to be consistent, so even if you did intentionally do it, it'd be a terrible idea anyways.
OP shouldn't be returning true at all. The default behavior is to allow them to spawn things unless their spawning limit has been reached. He should only be returning false, and only if they are not in any of the usergroups.
That's smart, but what I mean is that if you have a conditional you want to use that either wishes to completely nullify any other code (you might as well overwrite the function then but hey you never know) or is carefully manipulated. That is not the case here.
You're completely right. I've edited my original post.
Sorry, you need to Log In to post a reply to this thread.