Spawning Entities Crashes Server?

Been having some trouble with my RTS, I made a very simple anim entity for the combine base (I’m a terrible entity/SWEP coder), but when I try to spawn it on Initialize the server (My local game) crashes. I’ll post the related code so you guys know what I’m working with :saddowns:

Entity Code

cl_init.lua
[lua]
include(‘shared.lua’)

ENT.RenderGroup = RENDERGROUP_OPAQUE
[/lua]

init.lua
[lua]

AddCSLuaFile( “cl_init.lua” )
AddCSLuaFile( “shared.lua” )

include(‘shared.lua’)

function ENT:SpawnFunction(ply, tr)
local SpawnPos = Vector(0, 0, 0)
local ent = ents.Create(“CombineBase”)
ent:SetPos(SpawnPos)
ent:Spawn()
return ent
end

function ENT:Think()
end

function ENT:OnTakeDamage(dmg)
end

function ENT:Initialize()
self.Entity:SetModel(“models/props_combine/combine_bunker01.mdl”)
self.Entity:PhysicsInit(SOLID_VPHYSICS)

self.Entity:SetMoveType(MOVETYPE_NONE)

self.Entity:SetSolid(SOLID_VPHYSICS)


local phys = self.Entity:GetPhysicsObject()


if (phys:IsValid()) then

	phys:Wake()

end

end
[/lua]

shared.lua
[lua]
ENT.Base = “base_anim”
ENT.Type = “anim”
ENT.Category = “Strategic Strike”
ENT.PrintName = “Combine Base”
ENT.Author = “Kopimi”
ENT.Contact = “”
ENT.Purpose = “”
ENT.Instructions = “”
ENT.Spawnable = false
ENT.AdminSpawnable = true
[/lua]


Gamemode Code

init.lua
[lua]
function SpawnBases(pl)
local combine = ents.Create(“CombineBase”)
combine:SetPos(Vector(0, 0, 0))
combine:Spawn()
end
hook.Add(“Initialize”, “SpawnBases”, SpawnBases)
[/lua]


So once more:

Made an entity, spawned it on server start, crashes server, dont know what to do.

I’m assuming its a problem with my entity because I’m a terrible entity coder, but right now I’m just pulling my hair out trying to get a fix.

Is the problem in the code that spawns it within the gamemode or is it the entity?

The entity doesnt spawn itself, the gamemode spawns it.

If thats what you’re asking.

Use this hook instead http://wiki.garrysmod.com/?title=Gamemode.InitPostEntity

Try spawning it in InitPostEntity?

[editline]08:16PM[/editline]

Ninjas

I meant does it only crash when the gamemode spawns it, But yeah you are using wrong hook as other suggested

Ah, thanks.

I forgot initialization would be as soon as the server starts, not when the map is loaded.