Entity auto spawning, server side file problems.



weapon=ents.Create("weapon_physgun")
weapon:SetPos(Vector(805.244568,1765.582520,159.906982))
weapon:Spawn()
 

So I put this in my gamemode’s init file, the server just wont load.
I put it in lua/autorun/server same thing.
Is there a certain way I should put this?

Wait so the server won’t load? Like it won’t even start up? I highly doubt that’s caused by that code if that’s what you did. Are you saying it works if you take that code out?

I put it in, server wont load. I take it out, server loads. I covered this.

You never said if you actually tried to take it out or not. You’d be surprised how many people don’t.

Either way, you could try something like this
[lua]
hook.Add( “InitPostEntity”, “SpawnPhysgun”, function ()
local ent = ents.Create(“weapon_physgun”)
ent:SetPos( Vector(805.244568, 1765.582520, 159.906982) )
ent:SetAngles( Angle(0, 0, 0) ) – probably not needed
ent:Spawn()
ent:DropToFloor()
end
[/lua]

The “InitPostEntity” hook, does this work on the client code as well? When the client itself loaded everything?

http://puu.sh/aYogl/d87e710754.png

Yes



[ERROR] lua/autorun/ents.lua:7: ')' expected (to close '(' at line 1) near '<eof>'
  1. unknown - lua/autorun/ents.lua:0


This is what I got, and just copy and pasted what you said.

Your getting that error because he forgot a closing parentheses in his code on the last line. This should work, I just added the missing bracket:



hook.Add( "InitPostEntity", "SpawnPhysgun", function ()
	local ent = ents.Create("weapon_physgun")
	ent:SetPos( Vector(805.244568, 1765.582520, 159.906982) )
	ent:SetAngles( Angle(0, 0, 0) ) -- probably not needed
	ent:Spawn()
	ent:DropToFloor()
end )