• Bonemerging a Model to an Entity?
    11 replies, posted
I'm trying to attach a misc to an entity, [lua] function ENT:Initialize() if CLIENT then self.Misc= ClientsideModel("models/player/items/sniper/mymischere.mdl") self.Misc:SetPos(self:GetPos()) self.Misc:SetParent(self) self.Misc:AddEffects(EF_BONEMERGE) end [/lua] But for some reason, the model isn't attached to the ent, it doesn't show up at all. Any advice?
Try self.Misc:SetNoDraw(true) in ENT:Initialize and self.Misc:DrawModel() in ENT:Draw()
[QUOTE=Robotboy655;45259438]Try self.Misc:SetNoDraw(true) in ENT:Initialize and self.Misc:DrawModel() in ENT:Draw()[/QUOTE] Thanks for the reply. But I get this error :( [lua] [ERROR] addons/myaddon/lua/entities/mynpc/shared.lua:146: attempt to index field 'Misc' (a nil value) 1. unknown - addons/myaddon/lua/entities/mynpc/shared.lua:146 [/lua] Here is the line at 146 [lua] self.Misc:SetNoDraw(true) [/lua] Edit: This is my code [lua] function ENT:Draw() self.Entity:DrawModel() self.Misc:DrawModel() end function ENT:Initialize() if CLIENT then self.Misc= ClientsideModel("models/player/sniper.mdl") self.Misc:SetPos(self:GetPos()) self.Misc:SetParent(self) self.Misc:AddEffects(EF_BONEMERGE) end self.Misc:SetNoDraw(true) [/lua]
[QUOTE=ErrolLiamP;45259576]Thanks for the reply. But I get this error :( [lua] [ERROR] addons/myaddon/lua/entities/mynpc/shared.lua:146: attempt to index field 'Misc' (a nil value) 1. unknown - addons/myaddon/lua/entities/mynpc/shared.lua:146 [/lua] Here is the line at 146 [lua] self.Misc:SetNoDraw(true) [/lua] Edit: This is my code [lua] function ENT:Draw() self.Entity:DrawModel() self.Misc:DrawModel() end function ENT:Initialize() if CLIENT then self.Misc= ClientsideModel("models/player/sniper.mdl") self.Misc:SetPos(self:GetPos()) self.Misc:SetParent(self) self.Misc:AddEffects(EF_BONEMERGE) end self.Misc:SetNoDraw(true) [/lua][/QUOTE] self.Misc only exists on the client, so you should only be running self.Misc:SetNoDraw(true) on the client.
[code] function ENT:Initialize() if CLIENT then self.Misc= ClientsideModel("models/player/sniper.mdl") self.Misc:SetPos(self:GetPos()) self.Misc:SetParent(self) self.Misc:AddEffects(EF_BONEMERGE) self.Misc:SetNoDraw(true) end end[/code] And don't use self.Entity, use self.
[QUOTE=Robotboy655;45259694][code] function ENT:Initialize() if CLIENT then self.Misc= ClientsideModel("models/player/sniper.mdl") self.Misc:SetPos(self:GetPos()) self.Misc:SetParent(self) self.Misc:AddEffects(EF_BONEMERGE) self.Misc:SetNoDraw(true) end end[/code] And don't use self.Entity, use self.[/QUOTE] I took both of your tips and nothing worked :\ Weird, I happen to be using a moving nextbot with a cl_init.lua. Turns the tables at all?
Right. Nextbots don't have cl_init.lua part. They cannot have clientside Lua at all.
[QUOTE=Robotboy655;45260361]Right. Nextbots don't have cl_init.lua part. They cannot have clientside Lua at all.[/QUOTE] [lua] function ENT:Draw() self.DrawModel() self.Misc:DrawModel() end function ENT:Initialize() -- if CLIENT then if CLIENT then self.Misc = ClientsideModel("models/player/items/sniper/snipermodel.mdl") self.Misc:SetPos(self:GetPos()) self.Misc:SetParent(self) self.Misc:AddEffects(EF_BONEMERGE) self.Misc:SetNoDraw(true) end [/lua] Sorry to keep dragging this out guys but it won't seem to work :(
[QUOTE=ErrolLiamP;45261330][lua] function ENT:Draw() self.DrawModel() self.Misc:DrawModel() end function ENT:Initialize() -- if CLIENT then if CLIENT then self.Misc = ClientsideModel("models/player/items/sniper/snipermodel.mdl") self.Misc:SetPos(self:GetPos()) self.Misc:SetParent(self) self.Misc:AddEffects(EF_BONEMERGE) self.Misc:SetNoDraw(true) end [/lua] Sorry to keep dragging this out guys but it won't seem to work :([/QUOTE] Robotboy just explained why, so the draw hook inside of the nextbot isn't going to do anything.
[url]https://github.com/Facepunch/garrysmod-requests/issues/25[/url]
[QUOTE=Robotboy655;45260361]Right. Nextbots don't have cl_init.lua part. They cannot have clientside Lua at all.[/QUOTE] SO THAT'S WHY CLIENTSIDE MODELS NEVER FUCKING WORK THAT'S WHY I ALWAYS HAVE TO USE PROP_PHYSICS So why not put it in init.lua instead of shared? [editline]1st July 2014[/editline] To get around this, use ents.Create to make a prop_physics. Set the model and bonemerge it but DON'T Spawn() it or else your nextbot will move weirdly upon spawning.
[QUOTE=BFG9000;45263320]SO THAT'S WHY CLIENTSIDE MODELS NEVER FUCKING WORK THAT'S WHY I ALWAYS HAVE TO USE PROP_PHYSICS So why not put it in init.lua instead of shared? [editline]1st July 2014[/editline] To get around this, use ents.Create to make a prop_physics. Set the model and bonemerge it but DON'T Spawn() it or else your nextbot will move weirdly upon spawning.[/QUOTE] I took a look at ents.create Figured it out, thanks! :eng101:
Sorry, you need to Log In to post a reply to this thread.