Garry's Mod Wiki

Revision Difference

WEAPON:DrawWorldModel#512119

<function name="DrawWorldModel" parent="WEAPON" type="hook">⤶ <ishook>yes</ishook>⤶ <description>Called when we are about to draw the world model.</description>⤶ <realm>Client</realm>⤶ <predicted>No</predicted>⤶ </function>⤶ ⤶ <example>⤶ <description>The default action - render the world model.</description>⤶ <code>⤶ function SWEP:DrawWorldModel()⤶ self:DrawModel()⤶ end⤶ </code>⤶ ⤶ </example>⤶ ⤶ ⤶ <example>⤶ <description>Draw The World model when needed. Placing the SWEPs World model in the right hand of the Player.</description>⤶ <code>⤶ -- ...⤶ SWEP.HoldType = "pistol" -- You might need to do self:SetHoldType(self.HoldType) under the initialization hook for the SWEP.⤶ ⤶ if CLIENT then⤶ local WorldModel = ClientsideModel(SWEP.WorldModel)⤶ ⤶ -- Settings...⤶ WorldModel:SetSkin(1)⤶ WorldModel:SetNoDraw(true)⤶ ⤶ function SWEP:DrawWorldModel()⤶ local _Owner = self:GetOwner()⤶ ⤶ if (IsValid(_Owner)) then⤶ -- Specify a good position⤶ local offsetVec = Vector(5, -2.7, -3.4)⤶ local offsetAng = Angle(180, 90, 0)⤶ ⤶ local boneid = _Owner:LookupBone("ValveBiped.Bip01_R_Hand") -- Right Hand⤶ if !boneid then return end⤶ ⤶ local matrix = _Owner:GetBoneMatrix(boneid)⤶ if !matrix then return end⤶ ⤶ local newPos, newAng = LocalToWorld(offsetVec, offsetAng, matrix:GetTranslation(), matrix:GetAngles())⤶ ⤶ WorldModel:SetPos(newPos)⤶ WorldModel:SetAngles(newAng)⤶ ⤶ WorldModel:SetupBones()⤶ else⤶ WorldModel:SetPos(self:GetPos())⤶ WorldModel:SetAngles(self:GetAngles())⤶ end⤶ ⤶ WorldModel:DrawModel()⤶ end⤶ end⤶ </code>⤶ <output></output>⤶ ⤶ </example>