Activating map entity through lua

I started lua day before yesterday, and I’ve run into a bit of a snag. Im using the “template npc” method to spawn npcs. In other words, i already have spawn points set up, and the npc i wish to spawn “prebuilt” into the map. It works beautifully activating the npc_template_maker “INSIDE” hammer, but i’d like to choose between sandbox mode, and that. So i thought i would try some gamemode scripting.

I was able to set all the basics up, and i wanted to create a function to activate the npc_template_maker thus beginning the headcrab spawning. Here is that function:

BeginSpawn = function()
    local Spawner = ents.GetByClass("npc_template_maker")

In my mind this should work well after thoroughly reading through the lua documentation for the “Fire” action. But i receive the error

attempt to call method 'Fire' (a nil value)

Any clue what im doing wrong here? I know i just started the other day, but im normally good at figuring things out, but this is just stumping me.

ents.GetByClass doesn’t exist.
Do you mean **[Ents.FindByClass](** ? And it also returns a table, which means you have to loop through all stuff first, like:
local Spawner = ents.FindByClass(“npc_template_maker”)
for k,v in pairs(Spawner) do
v:Fire(“Enable”, “”, 5)

yes i meant FindByClass,im about to try right now.


Works beautifully, thanks man. I didnt know it would return a table if there was just one instance of the spawner. How would i pick a SPECIFIC spawner from the table?

Sorry to ask more questions, its just that im new, and you’re the first person to answer any question ive had.

Depends on what you are doing, entity index is usually a good way to interact with map entities.