SetParent Problem

im triying to attach an model to the player back but with no luck im running this on my entity init.lua
[lua]
function ENT:Touch()

local BoneIndx = ent:LookupBone("ValveBiped.Bip01_Spine")
        local BonePos , BoneAng = ent:GetBonePosition( BoneIndx )
        local model = ents.Create("prop_dynamic")
        model:SetModel("models/props_c17/GasPipes006a.mdl")
        model:SetPos(BonePos)
        model:Spawn()
        model:Activate()
        //constraint.Weld(ent,model,BoneIndx,0,0,true)
        model:SetNotSolid(true)
        model:SetColor(team.GetColor(teamNum))

end
[/lua]

[editline]2nd July 2011[/editline]

by the way once i touch the entity nothing happends

Any errors?

it prints \init.lua:41] attempt to index global ‘ent’ (a nil value)

this line local BoneIndx = ent:LookupBone(“ValveBiped.Bip01_Spine”)

[editline]2nd July 2011[/editline]

[lua]

function ENT:SpawnFunction( ply,tr)

	if ( !tr.Hit ) then return end

local SpawnPos = tr.HitPos + tr.HitNormal * 20

local ent = ents.Create( "blue_demo_afro" )
ent:SetPos( SpawnPos )
ent:Spawn()
ent:Activate()

return ent

end

function ENT:Initialize( ) –

self:SetModel( "models/props_c17/GasPipes006a.mdl" ) 

self:SetSolid(  SOLID_BBOX ) 

self:DropToFloor()

end

function ENT:Touch()

local BoneIndx = ent:LookupBone("ValveBiped.Bip01_Spine")
        local BonePos , BoneAng = ent:GetBonePosition( BoneIndx )
        local model = ents.Create("prop_dynamic")
        model:SetModel("models/props_c17/GasPipes006a.mdl")
        model:SetPos(BonePos)
        model:Spawn()
        model:Activate()
        //constraint.Weld(ent,model,BoneIndx,0,0,true)
        model:SetNotSolid(true)
        model:SetColor(team.GetColor(teamNum))

end
[/lua]

thats the full code

And now im getting this problem http://www.youtube.com/watch?v=gcfQ-HQRNlU

The variable ‘ent’ has not been specified. If you want to get the entity to weld itself to any player that touches it, replace:

[lua]
function ENT:Touch()
[/lua]

With:

[lua]
function ENT:Touch(ent)
if !(ent && ent:IsValid() && ent:IsPlayer()) then return end
[/lua]

Okay i added that but the problem persists

[editline]3rd July 2011[/editline]

It still welds to the player but if i move the player camera the model moves with the camera not with the player

I don’t know a whole lot about the valve biped structure, but it might be that the bone you are using moves with the player camera, as the spine would?

As far i know it shouldent i even tried using the Chest bone and its the same problem

Just had a look at some models in the Source SDK model viewer, it seems there is a bone in the chest area of most of the models called ValveBiped.Bip01_Spine2. You could try that.

Still l: Just wondering i looked at a diferent position while touching the prop it ATTACHS to the bone but i think the angles or offset are wrong so that MAY explain the movement problem

You could try setting the angles of the attached entity:

[lua]
model:SetAngles(BoneAng)
[/lua]

Tried that and its the same problem im wondering what is causing this

Any virtual bone structure experts around?

[lua]
function ENT:Touch(ent)
if !(ent && ent:IsValid() && ent:IsPlayer()) then return end
local attach = ent:LookupAttachment(“eyes”);
local angpos = ent:GetAttachment( attach )
local pos = angpos.Pos;
local ang = angpos.Ang;
local model = ents.Create(“prop_dynamic”)
model:SetModel(“models/props_c17/GasPipes006a.mdl”)
model:SetPos(pos)
model:SetAngles(ang)
model:Spawn()
model:Activate()
model:SetAttachment(attach) //shouldent i be putting the attachment number here?
model:SetNotSolid(true)
model:SetColor(team.GetColor(teamNum))
end

[/lua]

Is there anyway to get the attachment ID?

Yep, use LookupAttachment() to get the ID, then use the ID for GetAttachment() or SetAttachment().

So to set the attachment i use model:SetAttachment( attach ) or model:SetAttachment ( angpos ) ??

Should be model:SetAttachment( attach ).

**[Entity.SetAttachment

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

DAMMIT still Okay this is driving me fucking crazy

Just a though, probably wont work if it’s setting the angles to the camera angle, but try setting the angle of model to 0,0,0:

[lua]
model:SetAngles(Angle(0,0,0))
[/lua]

Still Nothing We truly need an virtual bone structure expert here ):