Is this the right way to restrict spawn and context menu to ranks?
6 replies, posted
[code]
if SANDBOX:SpawnMenuOpen() then
function checkULX(ply)
if table.HasValue({"owner", "dev", "superadmin"}, ply:GetNWString("usergroup")) then
return true
else return false
end
end
end,
})
if GM:ContextMenuOpen() then
function checkULX(ply)
if table.HasValue({"owner", "dev", "superadmin"}, ply:GetNWString("usergroup")) then
return true
else return false
end
end
end,
})
[/code]
[code]if SANDBOX:SpawnMenuOpen() then --SANDBOX is nil, it will cause an error
function checkULX(ply) --This function is never ran
if table.HasValue({"owner", "dev", "superadmin"}, ply:GetNWString("usergroup")) then
return true
else return false
end
end
end, --There is no reason for this comma to be here, it will cause an error
}) --There is no reason for these to be here, it will cause an error
if GM:ContextMenuOpen() then --Unless you're editing gamemode files, GM will be nil, it will cause an error
function checkULX(ply) --This is overwriting the function you made earlier
if table.HasValue({"owner", "dev", "superadmin"}, ply:GetNWString("usergroup")) then
return true
else return false
end
end
end, --No reason for this comma to be here either, it will cause an error
}) --No reason for these to be here either, it will cause an error[/code]
I commented some the problems, and you should probably give these a read:
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/hook/Add]hook.Add[/url]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/SANDBOX/SpawnMenuOpen]SANDBOX:SpawnMenuOpen[/url]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/ContextMenuOpen]GM:ContextMenuOpen[/url]
Also, this will only prevent players from opening the spawnmenu, it will not prevent them from using console commands like gm_spawn or other methods to spawn things without the spawnmenu. If you want to prevent that as well, use these:
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/SANDBOX/PlayerSpawnNPC]SANDBOX:PlayerSpawnNPC[/url]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/SANDBOX/PlayerSpawnObject]SANDBOX:PlayerSpawnObject[/url]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/SANDBOX/PlayerSpawnProp]SANDBOX:PlayerSpawnProp[/url]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/SANDBOX/PlayerSpawnRagdoll]SANDBOX:PlayerSpawnRagdoll[/url]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/SANDBOX/PlayerSpawnSENT]SANDBOX:PlayerSpawnSENT[/url]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/SANDBOX/PlayerSpawnSWEP]SANDBOX:PlayerSpawnSWEP[/url]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/SANDBOX/PlayerSpawnVehicle]SANDBOX:PlayerSpawnVehicle[/url]
And for preventing context menu things:
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/SANDBOX/CanProperty]SANDBOX:CanProperty[/url]
[QUOTE=AwfulRanger;51545387][code]if SANDBOX:SpawnMenuOpen() then --SANDBOX is nil, it will cause an error
function checkULX(ply) --This function is never ran
if table.HasValue({"owner", "dev", "superadmin"}, ply:GetNWString("usergroup")) then
return true
else return false
end
end
end, --There is no reason for this comma to be here, it will cause an error
}) --There is no reason for these to be here, it will cause an error
if GM:ContextMenuOpen() then --Unless you're editing gamemode files, GM will be nil, it will cause an error
function checkULX(ply) --This is overwriting the function you made earlier
if table.HasValue({"owner", "dev", "superadmin"}, ply:GetNWString("usergroup")) then
return true
else return false
end
end
end, --No reason for this comma to be here either, it will cause an error
}) --No reason for these to be here either, it will cause an error[/code]
I commented some the problems, and you should probably give these a read:
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/hook/Add]hook.Add[/url]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/SANDBOX/SpawnMenuOpen]SANDBOX:SpawnMenuOpen[/url]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/ContextMenuOpen]GM:ContextMenuOpen[/url]
Also, this will only prevent players from opening the spawnmenu, it will not prevent them from using console commands like gm_spawn or other methods to spawn things without the spawnmenu. If you want to prevent that as well, use these:
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/SANDBOX/PlayerSpawnNPC]SANDBOX:PlayerSpawnNPC[/url]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/SANDBOX/PlayerSpawnObject]SANDBOX:PlayerSpawnObject[/url]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/SANDBOX/PlayerSpawnProp]SANDBOX:PlayerSpawnProp[/url]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/SANDBOX/PlayerSpawnRagdoll]SANDBOX:PlayerSpawnRagdoll[/url]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/SANDBOX/PlayerSpawnSENT]SANDBOX:PlayerSpawnSENT[/url]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/SANDBOX/PlayerSpawnSWEP]SANDBOX:PlayerSpawnSWEP[/url]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/SANDBOX/PlayerSpawnVehicle]SANDBOX:PlayerSpawnVehicle[/url]
And for preventing context menu things:
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/SANDBOX/CanProperty]SANDBOX:CanProperty[/url][/QUOTE]
Don't forget to make the functions local, as from looking at your code you aren't using them anywhere else.
Sorry, I just started trying Lua yesterday :/
A friend gave me this :D
[code]
hook.Add("PlayerSpawnObject", "gay", function(ply, model, skin)
if !ply:IsSuperAdmin() then return false end
end)
hook.Add( "CanProperty", "gay2", function( ply, property, ent )
if !ply:SuperAdmin() then return false end
end )
[/code]
someone close this thread please
Upper left conner of the OP > Press that and it will lock
Sorry, you need to Log In to post a reply to this thread.