I cannot seem to get hooks to work. For whatever reason they never get called. Anyways I need a good example of a prop_physics being spawned using an autorun lua script and a working hook included.
local ent = ents.Create(“npc_zombie”) --what to create
ent:SetPos(Vector(0,0,0)) – what pos
ent:Spawn() – spawn that shit
hook.Add( “InitPostEntity”, “SpawnZombies”, SpawnZombies) – this is called after the gamemode and map load and start(wiki definition)
if SERVER then --check if serverside because of shared filepath
local ent = ents.Create(“npc_zombie”) --what to spawn
hook.Add( “InitPostEntity”, “SpawnZombies”, SpawnZombies)
That’s almost exactly what I have, using another hook however.
This will not work. Nothing happens when removed.
There is a wiki for things like this if you didn’t already know.
Alright. I’ve looked through it completely. I’m still unsure as to how I would be able to call in a function whenever anything touches it. Do you mind running me through how I would do that?
It would have to be a custom entity if you want to check if something touches it:
Alright that helps a lot. Now I’m trying to add it to a server when it starts. I tried using ents.Create and using it within autorun, but that didn’t seem to spawn the Entity. How would I go about spawning this before anyone joins?
You have to create the entire entity first for your gamemode or addon. Then use ents.Create(“entityfoldername”) blablabla
I’ve created an entity with a working entity folder. But if I run ents.Create(“spawnprotect”) it returns that it is an unknown type.
I checked and spawnprotect is the name of the entity folder within Lua/Entities.
Not sure, if you did everything I posted it should be working fine.
I figured it out. Thanks for your help and patience!