So I have a weapon that when the player picks it up, it slaps a client-side model on to that player and bone merges it. It works 100% of the time, but when tested in multiplayer, when a player gets far enough from another player wearing armor, far enough that the armored player is no longer rendered, the client-side model detaches from the player and sits T-Posed, so when the unarmored player can render the armored player, there’s just a T-Posed model floating in the last place the armored player was rendered. I have a function for attaching the models that runs in SWEP:Initialize() with an If CLIENT then Statement.
Now I know it seems really weird to use a weapon as a placeholder for an armor, system but I don’t really see any other way to do it in the gamemode I’m working on. As far as the functionality of the armor, it’s 100% functional and un-exploitable, I’m just tying to get it to represent your armor visually, and that’s the biggest issue I’m having.
Here’s what I have:
function SWEP:Initialize() -- clientside
if CLIENT then
local realmodel = self.Owner:GetNWString("RPMODEL") --gamemode specific
if string.find(realmodel, "female") or string.find(realmodel, "alyx") or string.find(realmodel, "mossman") then
female = true
else
female = false
end
if female then
self.newmodel = self.ArmorModel_female
else
self.newmodel = self.ArmorModel_male
end
self.Owner:SetNWString("armormodel", self.newmodel)
self:EquipArmor()
end
end
function SWEP:EquipArmor()
armormodel = self.Owner:GetNWString("armormodel")
armor = self.Owner
armor.mdl = ClientsideModel(armormodel)
armor.mdl:SetParent(armor)
armor.mdl:AddEffects(EF_BONEMERGE)
self.Owner:SetMaterial("models/effects/vol_light001")
end
I’m still a fairly new programmer and my only teacher is the gmod wiki, so I’m doing the best I can. Thanks for any replies or suggestions you guys might have!