• Code for spawning NPCs?
    2 replies, posted
I'm trying to code (I'm new at coding) a custom NPC Spawner tool, but I don't know the code to spawn NPCs Any help?
[url]http://wiki.garrysmod.com/page/ents/Create[/url]
Hey, this is my method of spawning an NPC, you can check it out if you feel like <3 [LUA] local ent = ents.Create(class) ent:SetPos(Vector:pos) local spawnFlag = list.Get("NPC")[type].SpawnFlags local KeyValues = list.Get("NPC")[type].KeyValues or {} ent:SetKeyValue("additionalequipment",String:weapon) local flags = spawnFlag || 0 if (spawnFlag) then flags = bit.bor(flags,spawnFlag) end for key,val in pairs(KeyValues) do ent:SetKeyValue(key,val) end ent:SetKeyValue("spawnflags", flags) ent:Spawn() ent:Activate() ent:SetHealth(Number:health) ent:SetCurrentWeaponProficiency(Number:NPCproficiency) if !(model == "") then ent:SetModel(String:model) end cleanup.Add(pl,"npcs",ent) undo.Create("NPC") undo.AddEntity(ent) undo.SetPlayer(pl) -- Where pl is the spawner player. undo.SetCustomUndoText("Undone NPC!") undo.Finish("Scripted Entity (NPC)")[/LUA]
Sorry, you need to Log In to post a reply to this thread.