• Entity spawning
    4 replies, posted
I was wondering how to spawn an entity like when the server starts or even just like on a timer since obviously I can't put it in ENT:Initialize since that's right after the entity spawns. cl_init: [CODE]include("shared.lua")[/CODE] shared: [CODE]ENT.Type = "anim" ENT.Base = "base_gmodentity" ENT.PrintName = "Cocaine Plant" ENT.Author = "Skashh" ENT.Spawnable = true[/CODE] init: [CODE]AddCSLuaFile("cl_init.lua") AddCSLuaFile("shared.lua") include("shared.lua") function ENT:Initialize() self:SetModel( "models/props/cs_office/plant01.mdl" ) self:SetMoveType( MOVETYPE_VPHYSICS ) self:SetSolid( SOLID_VPHYSICS ) if ( SERVER ) then self:PhysicsInit( SOLID_VPHYSICS ) end local phys = self:GetPhysicsObject() if ( IsValid( phys ) ) then phys:Wake() end self:SetPos(Vector(-2268, -152, -132)) end function PlayerPickup( ply, ent ) if (ply:IsValid()) then return true end end hook.Add( "PhysgunPickup", "Allow Player Pickup", PlayerPickup )[/CODE] [editline]21st December 2015[/editline] Also this is on my darkrp test server and I don't want it to spawn from the F4 menu I want it to spawn automatically at the position I set. xP
Could you just tell me the directorys you have in your npc's folder like NPC/lua/
1. I couldn't find NPC/lua/ anywhere, 2. I didn't think this would have anything to do with NPC's I'm just wondering how I spawn my entity at a certain position, like if there was a hook for that or something. xP
Okay Go into Lua/ autorun/ Server create a new lua file and do something like this! [code] hook.Add("InitPostEntity", "spawnnpc", function() local npc = ents.Create("npc_something") -- THIS HAS TO BE THE Name of your entitys folder npc:SetPos(Vector(-219.683640, -16.870455, 64.031250 )) -- position npc:SetAngles(Angle(9.524036, -46.654648, 0.000000)) -- angles npc:Spawn() -- this spawns the entity end) [/code] This should help [URL="https://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index7853.html"]NpcShop[/URL] [editline]22nd December 2015[/editline] And heres a working example that spawns the entity also [URL="https://garrysmods.org/download/1821/shop-npc-examplezip"]In case your interested[/URL]
That worked thanks!
Sorry, you need to Log In to post a reply to this thread.