• trying to get an ent/npc table without it existing.
    2 replies, posted
Hello, I am trying to spawn an NPC without hard coding it. I want to spawn for example an NPC called "ShotgunSoldier". However, "ShotgunSoldier" isn't recognized by ents.Create. But this is what copies to my clipboard in the NPC section. I've scoured the gmod wiki already with no luck, I tried the scripted ents libraries with also no luck. Can someone help me out? [url]https://github.com/garrynewman/garrysmod/blob/master/garrysmod/lua/autorun/base_npcs.lua[/url] On line 332 you can see the add npc class, of course for whatever reason "ShotgunSoldier" is in the spawn flags.
You will notice on like 334 is the actual NPC class the NPC spawns as, the key is named CLASS. "ShotgunSoldier" is a unique identifier to get the information about the NPC user wants to spawn from the "NPC" list, which can be gotten via list.Get("NPC")["ShotgunSoldier"]. "ShotgunSoldier" is what the spawnmenu tells the server to spawn, which then uses that list to see what "ShotgunSoldier" actually means, i.e. what class and model to use, etc. All of the logic for this is available on the sandbox/commands.lua file. [url]https://github.com/garrynewman/garrysmod/blob/master/garrysmod/gamemodes/sandbox/gamemode/commands.lua#L290-L511[/url]
[QUOTE=Robotboy655;52260663]You will notice on like 334 is the actual NPC class the NPC spawns as, the key is named CLASS. "ShotgunSoldier" is a unique identifier to get the information about the NPC user wants to spawn from the "NPC" list, which can be gotten via list.Get("NPC")["ShotgunSoldier"]. "ShotgunSoldier" is what the spawnmenu tells the server to spawn, which then uses that list to see what "ShotgunSoldier" actually means, i.e. what class and model to use, etc. All of the logic for this is available on the sandbox/commands.lua file. [url]https://github.com/garrynewman/garrysmod/blob/master/garrysmod/gamemodes/sandbox/gamemode/commands.lua#L290-L511[/url][/QUOTE] Thanks man, the list.Get("NPC") is what I was trying to find!
Sorry, you need to Log In to post a reply to this thread.