Disabling NPC spawning to a group af players

Hello again.

My server is still crashy, but it won’t make me not working on it :wink:
I use ULX to have different groups of players with different rights : number of props spawned, weapons, etc… The visitors are those who have the less rights.
I still have a problem with theses visitors : many of them comes only to spawn plenty of NPCs, what makes the server very laggy and we must remove the NPCs…
I wanted to know if there’s a way to disable the NPC spawning to the “Visitors” group, but members, admins, etc… still have the right to spawn some of them. So, I won’t use the sbox_max_npcs variable or something like that, because nobody could spawn NPCs if set to 0…

Thanks by advance,
Gyoo.

Bump, I feel alone :’(

[lua]
hook.Add(“PlayerSpawnNPC”, “hook_PlayerSpawnNPC”, function(client, class, weaponClass)
return client:IsAdmin() or client:IsUserGroup(“member”);
end;
[/lua]

Thank you for the code, but I really don’t know where to put it… :frowning:
You should have an idea don’t you ?

Place it in lua/autorun/server

You can name the file anything, but make sure to have it have a .lua extension.

So, I created a file called NPC_restrict.lua in the folder you gave me.
I copied the code you wrote.
I saved the file.
I rebooted the server.
And visitors (a.k.a users in ULX) can still spawn NPCs (I tried by myself, changing my group to the users one)

Shouldn’t I add something more to the code you wrote ?

sbox_maxnpcs 0?

This is precisely what I don’t want to use…

No one else ?

Shot in the dark: Is it .lua or .lua.text? and is the user group called member, or Member? (I don’t know if lua is case sensitive, but for another programming language that could cause a problem.)

The file is a .lua one (checked twice x) )
The group is called “membre” as written here. I’ve modified the code to get the right name of the group before uploading the lua file :wink:

Bumpy post is bumpy

Just a quick question, did you save it with normal notepad?

I saved it with the normal notepad but I took care of choosing the “All files” option and name my file “NPC_retrict.lua”
When I go to the properties if the files, it IS a LUA file, not a text one.

Still nothing. I’ve tried putting the code in different places, but nothing works well.

  • any lua errors in server logs?
  • try this

hook.Add("PlayerSpawnNPC", "hook_PlayerSpawnNPC", function(client, class, weaponClass)
     if not (client:IsAdmin() or client:IsUserGroup("member")) then return false end
end)

p.s.

will make npc corpses disappear instantly

Now that you notice it, I have sometimes errors concerning hooks, but never this one, like this :

Thank you for this new code, I’ll test it ASAP (when my server will be empty so taht I can restart it without annoying people on it)

you can place script in lua/autorun/server/scriptname.lua and hotload it just now with
lua_openscript lua/autorun/server/scriptname.lua (in server console)

p.s. i hope you use changelevel <map> (NOT map <map>)

Nice command, I didn’t know about this one… but, to have less troubles with the file, I renamed it script.lua (in the right folder indeed) but I only get this :

I tried both with or without a / before lua folder, same result

BTW, I always use the changelevel command, the rare times I need to use it.

my bad…
lua_openscript autorun/server/scriptname.lua
NOT lua_openscript lua/…