Entity Error

-EDITED- People dont collide with the entity.

[lua]–shared.lua------------------------

ENT.Type = “anim”
ENT.Base = “base_anim”
ENT.PrintName = “”
ENT.Author = “”
ENT.Contact = “”
ENT.Purpose = “”
ENT.Instructions = “”

ENT.Spawnable = false
ENT.AdminSpawnable = false

–init.lua--------------------------------------------

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

include(‘shared.lua’)

util.PrecacheModel(“models/props_wasteland/barricade002a.mdl”)

function ENT:Initialize()

self.health = 80
self.Entity:SetModel("models/props_wasteland/barricade002a.mdl")
self.Entity:PhysicsInit( SOLID_VPHYSICS )
self.Entity:SetMoveType( MOVETYPE_NONE )
self.Entity:SetSolid( SOLID_VPHYSICS )
self.Entity:SetCollisionGroup( COLLISION_GROUP_PLAYER )

end

function ENT:PhysicsCollide( data, physobj )
local aq = true
if aq then return true
end
end

function ENT:Think()
self.Entity:SetColor( Color( 0, 0, (self.health/80)*255, 255 ) )
if self.health < -0 then
self.Entity:Remove()
self.Owner:SetNWInt(“struc.Cur”, self.Owner:GetNWInt(“struc.Cur”)-1)
end
end

function ENT:OnTakeDamage( damage )
self.health = self.health - damage:GetDamage()
end

–cl_init.lua------------------------------

include(‘shared.lua’)

function ENT:Draw()
self.Entity:DrawModel()
end

ENT.RenderGroup = RENDERGROUP_BOTH[/lua]
I get no errors either.

EDIT - Swep Code here.

[lua]–shared.lua–

SWEP.HoldType = “ar2”

SWEP.Base = “iw_base”
SWEP.Spawnable = true
SWEP.AdminSpawnable = true

SWEP.ViewModel = “models/weapons/v_hands.mdl”
SWEP.WorldModel = “”

SWEP.DrawAmmo = false
SWEP.DrawCrosshair = false
SWEP.Weight = 5
SWEP.AutoSwitchTo = false
SWEP.AutoSwitchFrom = false
SWEP.Primary.ClipSize = 5
SWEP.Primary.DefaultClip = 5

function SWEP:Initialize()
curStruc = “eng_barricade”
self.Owner:SetNWInt(“struc.Max”, 5)
self.Owner:SetNWInt(“struc.Cur”, 0)
end

function SWEP:SecondaryAttack()
self.NextSecondaryAttack = CurTime() + 0.3

OpenStrucMenu()

end

function SWEP:PrimaryAttack()
end

–init.lua–

AddCSLuaFile(“shared.lua”)
AddCSLuaFile(“cl_init.lua”)
include(‘shared.lua’)

function SWEP:PrimaryAttack()
self.TakePrimaryAmmo(1)
local tr = self.Owner:GetEyeTrace()

if self.Owner:GetNWInt("struc.Max") == self.Owner:GetNWInt("struc.Cur") and !tr.HitWorld then return false else

local ent = ents.Create( "eng_barricade" )
ent:SetPos( tr.HitPos + self.Owner:GetAimVector() * -16 )
ent:SetAngles( tr.HitNormal:Angle() )
ent:Spawn()
ent:SetOwner(self.Owner)

local weld = constraint.Weld( tr.Entity, ent, tr.PhysicsBone, 0, 0 )
end

end

–cl_init.lua–

include('shared.lua')

SWEP.PrintName = "Constructor V1"			
SWEP.Author	= "Carnifex"
SWEP.Slot = 2
SWEP.SlotPos = 3
SWEP.ViewModelFOV = 70
SWEP.ViewModelFlip = true

SWEP.IconLetter = "b"
killicon.AddFont("iw_engt1", "CSKillIcons", SWEP.IconLetter, Color(255, 80, 0, 255 ))

function OpenStrucMenu()
local strucmenu = vgui.Create("DFrame")
	strucmenu:SetPos( (ScrW()/2)-300,(ScrH()/2)-250 )
	strucmenu:SetSize( 600, 500 )
	strucmenu:SetTitle( "Structures Menu" )
	strucmenu:SetVisible( true )
	strucmenu:SetDraggable( false )
	strucmenu:ShowCloseButton( false )
	strucmenu:MakePopup()
local barricade = vgui.Create("DButton", strucmenu)
	barricade:SetPos( 30, 30 )
	barricade:SetSize( 540, 440 )
	barricade:SetText( "Barricade" )
	barricade.DoClick = function()
		curStruc = "eng_barricade"
		strucmenu:Close()
	end
end[/lua]

So far it looks ok, can you show the code where you create the entity? also please use lua tags -> [noparse][lua][/lua][/noparse] instead of code tags it’s easier to read.

EDIT:

ok, reading

Posted the swep code.

Put a print statement before the return in this line
[lua]if self.Owner:GetNWInt(“struc.Max”) == self.Owner:GetNWInt(“struc.Cur”) and !tr.HitWorld then return false else[/lua] in your swep primary fire and see if it even makes it to the creation code, because yea, it looks like it should work.

[editline]18th March 2011[/editline]

I think it might be leaving the primary fire instead of calling the creation code, sorry I have broken thoughts

I did that but it still dosnt work, obviously something is wrong with the entity.

But did it print what you put in there? if so then it’s not going as far as creating the entity, have you tried spawning the entity from the console in singleplayer with ent_create? I still say the code looks fine, I’ll take another look later if i have more time.

So when i spawn it, it will disappear instantly. It is there but invisible and does break, i see the shadow from a flashlight, i collide with it as well.

SetColor or SetAlpha.

I’m like 50 miles from a PC so I have to use my slow phone.

I don’t even know if SetAlpha exists.

Only for panels

ok now i understand, and see SetColor doesn’t take a color object
**[Entity.SetColor

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

I think I read in niggles that it’s supposed to be getting changed to take Color(r,g,b,a) but not sure

[editline]18th March 2011[/editline]

I’ve done this myself quite a few times. I thought you were saying it wouldn’t spawn at all.

So i can spawn the entity now via console command but it wont spawn using the swep.

Did you ever add that print statement to the swep to see if it made it through the if statement? If somethings not working try spamming your code with print statements like print(“Made it to before the if”) and print(“In contition 1 of if”) or print(“The entity won’t spawn if you see this”).
so your swep primary fire should look like this.
[lua]
function SWEP:PrimaryAttack()
self.TakePrimaryAmmo(1)
local tr = self.Owner:GetEyeTrace()

if self.Owner:GetNWInt("struc.Max") == self.Owner:GetNWInt("struc.Cur") and !tr.HitWorld then 
	print("struc.Max is not equal to struc.Cur, entity no spawning")
	return false 
else
	print("It worked there's something else wrong if the entity didn't spawn")
	local ent = ents.Create( "eng_barricade" )
	ent:SetPos( tr.HitPos + self.Owner:GetAimVector() * -16 )
	ent:SetAngles( tr.HitNormal:Angle() )
	ent:Spawn()
	ent:SetOwner(self.Owner)
  
	local weld = constraint.Weld( tr.Entity, ent, tr.PhysicsBone, 0, 0 )
end

end
[/lua]

then watch the console for those lines when you fire, depending on what you see you’ll know a little more of where the problem is.

It got through all the code, the print. SO it seems to be working but its not.

Try and spawn one with the SWEP and after you do check the ents table to see if it created I usually do it from the console, “lua_run PrintTable(ents.GetAll())”, if it shows your ent in the list then you have a problem with your spawn position, If it’s not in the list then i’m really not sure what’s going on at that point.

It spawns the entity but it doesn’t appear to be initializing.

So i tweaked the code, they spawn now and work but people dont collide with the props.

have you tried using a different collision group, try COLLISION_GROUP_NONE that should make it collide with everything.