• How to spawn entities automatically on server start?
    4 replies, posted
Hello all! I'm hosting a cinema server and I want to add an entity which will spawn on the map after the server is started. It's a jukebox which plays songs when you press the "Use" button on it. I need the jukebox to stay in the cinema lobby and make players unable to push it across the map. Usually I spawn the jukebox with the ULX menu, then move and fix it with a physgun, which is annoying. So, how do I avoid such a procedure and make the entity spawn automatically on server start?
[CODE] hook.Add("InitPostEntity", "spawnent", function() local ent = ents.Create("yourent") ent:SetPos(Vector(0, 0, 0)) ent:SetAngles(Angle(0, 0, 0)) ent:Spawn() ent:DropToFloor() end) [/CODE] Just change up the pos and angles to your preference.
[QUOTE=Tupac;50310032][CODE] hook.Add("InitPostEntity", "spawnent", function() local ent = ents.Create("yourent") ent:SetPos(Vector(0, 0, 0)) ent:SetAngles(Angle(0, 0, 0)) ent:Spawn() ent:DropToFloor() end) [/CODE] Just change up the pos and angles to your preference.[/QUOTE] Thanks, it helped me. But there is one issue: I can move it by pushing. How to fix it?
[QUOTE=SlyFox27;50310097]Thanks, it helped me. But there is one issue: I can move it by pushing. How to fix it?[/QUOTE] use [code] ent:GetPhysicsObject():EnableMotion(false) [/code] this freezes the entity as long as it has a valid physics object associated with it, but if it is moved with the physgun it will have motion enabled again. to disable it moving at all use [code] ent:SetMoveType(MOVETYPE_NONE) [/code] this will make the entity static, it will have no physics, and can still be moved with the physgun, but it will be frozen when you let go of it again
[QUOTE=AJ10017;50310152]use [code] ent:GetPhysicsObject():EnableMotion(false) [/code] this freezes the entity as long as it has a valid physics object associated with it, but if it is moved with the physgun it will have motion enabled again. to disable it moving at all use [code] ent:SetMoveType(MOVETYPE_NONE) [/code] this will make the entity static, it will have no physics, and can still be moved with the physgun, but it will be frozen when you let go of it again[/QUOTE] That worked, thank you too.
Sorry, you need to Log In to post a reply to this thread.