Entity Creation Help

Hey everyone, I currently have a automatic prop spawn system that I’m messing around with that is made to create world props on server start up. Anyways, I have been trying to make the prop like how it is when you persist props in Garry’s Mod (Solid, doesn’t move, can’t be moved with physgun… etc) but I can’t seem to do it. The code is under the InitPostEntity hook and the main bit of the code I have right now is below.


local Prop = ents.Create("prop_physics")
Prop:SetModel(v[3])
Prop:DrawShadow(false)
Prop:SetSolid(SOLID_VPHYSICS)
Prop:SetMoveType(MOVETYPE_NONE)
Prop:SetPos(v[1])
Prop:SetAngles(v[2])
Prop:Spawn()

Some help would be much appreciated, thanks in advance!

Hello ShadowRanger!

If I was you, I would make a for k, v in pairs function. This makes you enable to make alot of spawns :slight_smile:

Like this:



local MyAwesomeTable = {}

local MyAwesomeTable[ 1 ] = { }
MyAwesomeTable.Ang[ 1 ] = Vector(0,0,0) -- Your angel, type getpos in console to get it
MyAwesomeTable.pos[ 1 ] = Vector(0,0,0) -- Your postion, type getpos in console to get it
MyAwesomeTable.Entity[ 1 ] = superball -- Your entity name
MyAwesomeTable.Model[ 1 ] = model/sdadas/dssd/something -- Your modelname

local MyAwesomeTable[ 2 ] = { }
MyAwesomeTable.Ang[ 2 ] = Vector(0,0,0) -- Your angel, type getpos in console to get it
MyAwesomeTable.pos[ 2 ] = Vector(0,0,0) -- Your postion, type getpos in console to get it
MyAwesomeTable.Entity[ 2 ] = "superball" -- Your entity name
MyAwesomeTable.Model[ 2 ] = model/sdadas/dssd/something -- Your modelname

for k, v in pairs(MyAwesomeTable) do
	local Prop = ents.Create(MyAwesomeTable.Entity[ k ])
	Prop:SetModel(MyAwesomeTable.Model[ k ])
	Prop:DrawShadow(false)
	Prop:SetSolid(SOLID_VPHYSICS)
	Prop:SetMoveType(MOVETYPE_NONE)
	Prop:SetPos(MyAwesomeTable.pos[ k ])
	Prop:SetAngles(MyAwesomeTable.Ang[ k ])
	Prop:Spawn()
end


Let me know if it helps you.

There might bee some errors, I didn’t test it fully out. :slight_smile:
Locate it in the init.lua file :slight_smile:

[editline]19th May 2013[/editline]

I think I missunderstod something…

Thanks Errolight for the feedback but I think you misunderstood me or I just didn’t explain what I needed help with. Anyways, I already have the tables set up and the code works and spawns the props BUT they aren’t how I want them. The spawned props are not frozen and collide with players and move when collided with. I don’t want that. I want them to be world props that are frozen in place and solid. Basically just to make a map look better by adding extra props that aren’t already there.

Oooohh! Wait a sec. I makes maps aswell. Your looking for a func_detail?

[editline]19th May 2013[/editline]

Okay, I found this at the wiki, have you seen it?

Well I was looking for a good way to add props to maps through lua coding when a server starts and I was only able to find what I’m using now. I went to the link you sent me and as you can see in my post I’m using that but even with that the props aren’t frozen. Right now the props are spawned and are solid but they aren’t frozen like I want them to be.

Ohhh… Hmm

[editline]19th May 2013[/editline]

Have you tried this:

prop:SetMoveType(MOVETYPE_NONE)
prop:DropToFloor()

Nope, doesn’t work.

This is a script from a entity NPC I made a half year back, that npc can’t be moved, and has a box around it that does so you basicly can’t move it. It’s frozen aswell. I don’t know if you can dig something up with this



function ENT:SpawnFunction( ply, tr )
	if ( !tr.Hit ) then return end
	
	local SpawnPos = tr.HitPos + tr.HitNormal * 16
	
	local ent = ents.Create( "seller" )
	ent:SetPos( SpawnPos + Vector(0, 0, 5) )
	ent:SetAngles(Angle(0, 0, 0))
	ent:Spawn()
	ent:Activate()
	ent:PhysicsInit(SOLID_VPHYSICS)
	ent:SetMoveType(MOVETYPE_NONE)
	ent:SetUseType(SIMPLE_USE)
	ent:SetSolid( SOLID_BBOX ) -- <----------------------------------------------- What about this?????
	
	return ent
end

function ENT:Initialize( )
 
	self:SetModel( "models/humans/group01/male_08.mdl" )
	self:SetHullType( HULL_HUMAN )
	self:SetHullSizeNormal( )
	self:SetNPCState( NPC_STATE_IDLE )
	self:SetSolid( SOLID_BBOX ) -- <----------------------------------------------- What about this?????
	self:CapabilitiesAdd( CAP_ANIMATEDFACE, CAP_TURN_HEAD )
	self:SetUseType( SIMPLE_USE )
	self:DropToFloor()
	self:SetMaxYawSpeed( 90 )
 
end


Okay I’ve finally got it to spawn frozen which is great but now I need to make it so you can’t move it with your physgun or any tool for that matter. Here’s the code:


local Prop = ents.Create("prop_physics")
	Prop:SetModel(v[1])
	Prop:DrawShadow(false)
	Prop:SetPos(v[2])
	Prop:SetAngles(v[3])
	Prop:SetSolid(SOLID_NONE)
	Prop:SetUnFreezable(true)
	Prop:DropToFloor()
	Prop:Activate()
	Prop:Spawn()
			
	local phys = Prop:GetPhysicsObject()
	if IsValid( phys ) then phys:EnableMotion(false) end

Use falcos prop protection? It’s a world prop, so you can just do so people can’t touch world props, witch is pretty bad if they could, because you would never know who killd you with a world prop…

Thanks for the help, I’ve gotten the information I need to sort out the code. Thanks again :slight_smile: