floating weapon when dropped - ttt -

I am having problems with a weapon floating after it is dropped. This is for TTT. The problem is not css being mounted as it is only for one weapon and not every weapon.
The weird thing is that the weapon appears to drop correctly for the person that dropped it but it appears to float in mid-air for others.

The problem lies with the DrawWorldModel function I believe. I think for some reason it isn’t invalidating/nil the owner quick enough for other players. Here is the code.

Any help or ideas would be appreciated.

function SWEP:DrawWorldModel( )
        local hand, offset, rotate

        if not IsValid( self.Owner ) then
                self:DrawModel( )

        if not self.Hand then
                self.Hand = self.Owner:LookupAttachment( "anim_attachment_rh" )

        hand = self.Owner:GetAttachment( self.Hand )

        if not hand then
                self:DrawModel( )

        offset = hand.Ang:Right( ) * self.Offset.Pos.Right + hand.Ang:Forward( ) * self.Offset.Pos.Forward + hand.Ang:Up( ) * self.Offset.Pos.Up

        hand.Ang:RotateAroundAxis( hand.Ang:Right( ), self.Offset.Ang.Right )
        hand.Ang:RotateAroundAxis( hand.Ang:Forward( ), self.Offset.Ang.Forward )
        hand.Ang:RotateAroundAxis( hand.Ang:Up( ), self.Offset.Ang.Up )

        self:SetRenderOrigin( hand.Pos + offset )
        self:SetRenderAngles( hand.Ang )

        self:DrawModel( )

You’re only drawing the positioning for the owner, not all players.

So how do I get it to “drop” correctly for other players viewing the model when the player drops it and not just float in mid air. It drops correctly for the person who dropped it but not for anyone viewing it.

I tried messing with the DrawWorldModel because I thought the problem is in there but most of my attempts just lead to “crotch gun” syndrome. So I know this function is needed so the weapon doesn’t become a crotch gun.

In your init.lua do you this? Some MoveTypes would cause it to float.

	self:SetMoveType( MOVETYPE_VPHYSICS )

Make sure if its a custom weapon that you include the .phy file. Pretty self explanatory, but thought id say it.

Nope nothing like that. Should I try adding that and if so where? Make a PreDrop function?

Yep the physics file is there in resource.AddFile. It drops fine for the person who dropped it just not for others which is what is really weird about this bug.

Sorry I don’t think my post applies. You’re working on a weapon.

I can call Initialize… I’ll try playing around with that when I get home. Hopefully it will work. Thanks.

In TTT you normally call SetMoveType for an entity of a weapon (ie something that is thrown or created from the weapon) The actual weapon entity itself doesn’t need the SetMoveType set… at least for any TTT weapon SWEPS I have came across.

Hey check out this Thread, http://forum.facepunch.com/showthread.php?t=1278821
Seems like your problem, this might fix it.

That thread didn’t help and adding self:SetMoveType( MOVETYPE_VPHYSICS ) to initialize didn’t help… :frowning:

[editline]4th February 2014[/editline]

This seems to work

function SWEP:DrawWorldModel( )
        local hand, offset, rotate

        local pl = self:GetOwner()

        if IsValid( pl ) then
                        local boneIndex = pl:LookupBone( "ValveBiped.Bip01_R_Hand" )
                        if boneIndex then
                                local pos, ang = pl:GetBonePosition( boneIndex )
                                pos = pos + ang:Forward() * self.Offset.Pos.Forward + ang:Right() * self.Offset.Pos.Right + ang:Up() * self.Offset.Pos.Up

                                ang:RotateAroundAxis( ang:Up(), self.Offset.Ang.Up)
                                ang:RotateAroundAxis( ang:Right(), self.Offset.Ang.Right )
                                ang:RotateAroundAxis( ang:Forward(),  self.Offset.Ang.Forward )

                                self:SetRenderOrigin( pos )
                                self:SetRenderAngles( ang )
                self:SetRenderOrigin( nil )
                self:SetRenderAngles( nil )