spawning something on map init.

As title says, im trying to make it that when the map starts, an object is placed onto the map.
I have in my init.lua include(“map.lua”) so it uses it and includes it obviously.
then i have map.lua which has this:



function SpawnMapItems()
	if firstplayerx == 1 then else
			AddMapRock( "models/props_wasteland/rockcliff01k.mdl", 2991.239990, -915.047974, -142.352707, 47.859932, 65.359718, 0.000000, "0", 0 )
		firstplayerx = 1
	end	
end	
hook.Add("SpawnItemsOnMap",SpawnMapItems)

function AddMapRock(model, x, y, z, ap, ay, ar, m, c)
	local ent = ents.Create("mine")
	ent:SetPos(Vector(x, y, z))
	ent:SetAngles(Vector(ap, ay, ar))
	ent:SetModel(model)
	ent:PhysicsInit( SOLID_VPHYSICS )
	ent:Spawn()
	ent:GetPhysicsObject():EnableMotion(false)
	if model == "models/props_junk/plasticcrate01a.mdl" then
		ent:SetColor(0, 0, 0, 0)
	elseif c == 0 then
	elseif c == 1 then
		ent:SetColor(181, 181, 181, 255)
	elseif c == 2 then
		ent:SetColor(96, 96, 96, 255)
	end
	if m == 0 then
		ent:SetMaterial( "None" )
		ent:SetMaterial( "" )
	else
		ent:SetMaterial( "None" )
		ent:SetMaterial(m)
	end
end


Did i do something wrong? any help would be greatly appreciated.

**[Gamemode.InitPostEntity

http://wiki.garrysmod.com/favicon.ico](wiki.garrysmod.com/?title=Gamemode.InitPostEntity)**

**[LUA:Auto Spawning

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=LUA:Auto_Spawning)**

That what you want?

First of all, the hook doesnot exist, you are missing the unique identifier, and you should check if the physics object is valid to prevent erroring.

Wow, I didnt even look at that hook…

You should look at this **[Hook.Add

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Hook.Add)**
For future reference.

And try something like
[lua]hook.Add( “InitPostEntity”, “SpawnRocks”, function()
AddMapRock( “models/props_wasteland/rockcliff01k.mdl”, 2991.239990, -915.047974, -142.352707, 47.859932, 65.359718, 0.000000, “0”, 0 )
end)[/lua]

Could you elaborate more please?

I tried this instead and it didn’t work. I tried copying the code right from LUA:Auto Spawning and it didn’t work either. I’m not sure why anything isn’t working.

here’s what i tried



function SpawnProps()
SpawnProp(Vector( 2991.239990, -915.047974, -141.352707 ), "models/props_wasteland/rockcliff01k.mdl")
end
hook.Add("InitPostEntity","SpawnTheProps",timer.Simple(1,SpawnProps))
 
function SpawnProp(position, model)
	local ent1 = ents.Create("prop_physics") 
	local ang = Vector(0,0,1):Angle();
	ang.pitch = ang.pitch + 90;
	print("Prop spawned with model: " .. model)
	ang:RotateAroundAxis(ang:Up(), math.random(0,360))
	ent1:SetAngles(ang)
	ent1:SetModel(model)
	local pos = position
	pos.z = pos.z - ent1:OBBMaxs().z
	ent1:SetPos( pos )
	ent1:Spawn()
end



[lua]
hook.Add(“InitPostEntity”, “SpawnTheProps”, function() timer.Simple(1, SpawnProps); end);
[/lua]

Try that.

Worked great. Thanks! :smiley: