Author Topic: Restricting NPC Spawning  (Read 7344 times)

0 Members and 1 Guest are viewing this topic.

Offline johnlukeg

  • Newbie
  • *
  • Posts: 27
  • Karma: -1
Restricting NPC Spawning
« on: July 15, 2008, 02:08:17 PM »
Ok... I know for a fact this has been explained before on the boards, but I've been searching for the last 15 minutes and cannot find it. Sorry if you can easily find the post for this - I just need to know what file I had to edit so I can back it up before reinstalling my server.

I recall editing a file to disable the spawning of NPCs from Clients while allowing Admins to spawn them.  You had to set the maximum NPCs variable to 1 above the limit you wanted for admins, if I recall.  Anyway, can anyone remember which file this is and/or what you need to do?

Or actually finding that post would be even better.  I'm very sorry for bringing it up again....

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: Restricting NPC Spawning
« Reply #1 on: July 15, 2008, 03:21:20 PM »
Here you go, NOT tested:

Code: [Select]
// Dev-Solution.org  and Ulyssesmod.net

local Max_User_NPC = 0 // Set this to what you want the max number of npc's spawnable to non-admins
local Max_Admin_NPC = nil // Same as above except for admins, and if you set to nil it will default to the server's max npc's

//===========================END OF CONFIG============================//

if Max_Admin_NPC == nil then
Max_Admin_NPC = GetConVarNumber("sbox_maxnpcs")
end

function Restrict_NPCS( ply, npc, weapon )
if ply:IsAdmin() or ply:IsSuperadmin() then
if not ply:CheckLimit("sbox_maxnpcs") <= Max_Admin_NPC then
return false
end
else
if not ply:CheckLimit("sbox_maxnpcs") <= Max_User_NPC then
return false
end
end
end
hook.Add("PlayerSpawnNPC", "Restict_NPCS_Hook", Restrict_NPCS )

To use:
copy and paste to a text file, then save as "anything.lua" NO QUOTES, then place the lua file in your <server>/garrysmod/lua/autorun/anything.lua
set your Max_User_NPC and your Max_Admin_NPC, and you'll be done :D
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly

Offline johnlukeg

  • Newbie
  • *
  • Posts: 27
  • Karma: -1
Re: Restricting NPC Spawning
« Reply #2 on: July 15, 2008, 03:27:18 PM »
Thanks, I'll test it once my server finishes reinstalling.  Different than what I was using, but this looks cleaner.

Offline Samusaaron3

  • Newbie
  • *
  • Posts: 20
  • Karma: 0
Re: Restricting NPC Spawning
« Reply #3 on: October 23, 2008, 07:14:58 PM »
Is there any chance that this could be modified so that it would support different numbers of npc's for different groups?

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Restricting NPC Spawning
« Reply #4 on: October 23, 2008, 07:50:41 PM »
Jay, perhaps group NPC or other entity, prop limits like this could be added to URestrict?
Seems to me that it might be a reasonable addition.
Perhaps a new tab for each major item? <wire> tab. <NPC tab>
I don't know. Just rambling right now.

All, Remember our motto though. We strive for simplicity. If it would be more difficult to incorporate into URestrict than hoped, jay could nix it.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: Restricting NPC Spawning
« Reply #5 on: October 25, 2008, 07:30:08 AM »
Jay, perhaps group NPC or other entity, prop limits like this could be added to URestrict?
Seems to me that it might be a reasonable addition.
Perhaps a new tab for each major item? <wire> tab. <NPC tab>
I don't know. Just rambling right now.

All, Remember our motto though. We strive for simplicity. If it would be more difficult to incorporate into URestrict than hoped, jay could nix it.

     -Hmm... It's do-able, but it'll be some time before I get to it with work/school.
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly