Floating SWEPS

Currently having an issue with newly added TTT SWEPs floating whenever players drop them.

Ex: user picks up gun -> drops it -> works fine for user who initially picked up gun -> other players see it as floating. I checked around and it does seem the server is loading the model/physics correctly, as sometimes the weapons drop without issue. But 8/10 times they end up floating.


local soundData = {
    name 		= "Weapon_Cawp.Draw" ,
    channel 	= CHAN_ITEM,
    volume 		= 1,
    soundlevel 	= 80,
    pitchstart 	= 100,
    pitchend 	= 100,
    sound 		= "csgo/awp/awp_draw.wav"
}

sound.Add(soundData)

local soundData = {
    name 		= "Weapon_Cawp.BoltBack" ,
    channel 	= CHAN_ITEM,
    volume 		= 1,
    soundlevel 	= 80,
    pitchstart 	= 100,
    pitchend 	= 100,
    sound 		= "csgo/awp/awp_boltback.wav"
}

sound.Add(soundData)

local soundData = {
    name 		= "Weapon_Cawp.BoltForward" ,
    channel 	= CHAN_ITEM,
    volume 		= 1,
    soundlevel 	= 80,
    pitchstart 	= 100,
    pitchend 	= 100,
    sound 		= "csgo/awp/awp_boltforward.wav"
}

sound.Add(soundData)

local soundData = {
    name 		= "Weapon_Cawp.Clipout",
    channel 	= CHAN_ITEM,
    volume 		= 1,
    soundlevel 	= 80,
    pitchstart 	= 100,
    pitchend 	= 100,
    sound 		= "csgo/awp/awp_clipout.wav"
}

sound.Add(soundData)

local soundData = {
    name 		= "Weapon_Cawp.Clipin" ,
    channel 	= CHAN_ITEM,
    volume 		= 1,
    soundlevel 	= 80,
    pitchstart 	= 100,
    pitchend 	= 100,
    sound 		= "csgo/awp/awp_clipin.wav"
}

sound.Add(soundData)

local soundData = {
    name 		= "Weapon_Cawp.Cliphit" ,
    channel 	= CHAN_ITEM,
    volume 		= 1,
    soundlevel 	= 80,
    pitchstart 	= 100,
    pitchend 	= 100,
    sound 		= "csgo/awp/awp_cliphit.wav"
}

sound.Add(soundData)

if (SERVER) then
	AddCSLuaFile("shared.lua")
end


SWEP.PrintName 		= "AWP | Dragon Lore"
SWEP.ViewModelFOV		= 57
SWEP.Slot 			= 2
SWEP.SlotPos 		= 2
SWEP.ViewModelFlip		= false


/*-------------------------------------------------------*/

SWEP.HoldType 		= "ar2"
SWEP.DrawCrosshair		= false		-- set false if you want no crosshair

-- TTT settings
SWEP.AutoSpawnable	= false
SWEP.Kind			= WEAPON_HEAVY
SWEP.AmmoEnt 		= "item_ammo_357_ttt"
SWEP.IsSilent 		= false
SWEP.NoSights 		= false
SWEP.Base 			= "weapon_tttbase"
SWEP.AllowDrop		= true
-- TTT

SWEP.ViewModel 			= "models/weapons/c_csgo_awp.mdl"
SWEP.WorldModel 		= "models/weapons/csgo_world/w_snip_awp.mdl"
SWEP.ShowViewModel = true
SWEP.ShowWorldModel = true
SWEP.UseHands			= true
SWEP.ViewModelFOV		= 60
SWEP.HeadshotMultiplier 	= 10
SWEP.Primary.Sound 		= Sound("csgo/awp/awp1.wav")
SWEP.Primary.Damage 		= 55
SWEP.Primary.Recoil 		= 1.9
SWEP.Primary.NumShots 		= 1
SWEP.Primary.KickUp				= 1.0				-- Maximum up recoil (rise)
SWEP.Primary.KickDown			= 0.4			-- Maximum down recoil (skeet)
SWEP.Primary.KickHorizontal		= 0.4 		-- Maximum up recoil (stock
SWEP.Primary.Spread 		= 0.0001
SWEP.Primary.Cone			= 0.0001
SWEP.Primary.ClipSize 		= 10
SWEP.Primary.Delay 		= 1.3
SWEP.Primary.DefaultClip 	= 20
SWEP.Primary.Automatic 		= false
SWEP.Primary.Ammo 		= "357"

SWEP.IronSightsPos = Vector (0, 0, 0)
SWEP.IronSightsAng = Vector (0, 0, 0)
SWEP.RunSightsPos = Vector (0, 0, 0)
SWEP.RunSightsAng = Vector (0, 0, 0)

SWEP.Secondary.ScopeZoom		= 6
SWEP.Secondary.UseAWP			= true
SWEP.data 				= {}
SWEP.data.ironsights			= 1
SWEP.ScopeScale 			= 0.51
SWEP.ReticleScale 			= 0.6

-- Weapon Variations
SWEP.UseScope				= true -- Use a scope instead of iron sights.
SWEP.ScopeScale 			= 0.65 -- The scale of the scope's reticle in relation to the player's screen size.
SWEP.ScopeZoom				= 6.25
SWEP.BoltAction			= true --Self Explanatory
-- Accuracy
SWEP.CrouchCone				= 0.0001 -- Accuracy when we're crouching
SWEP.CrouchWalkCone			= 0.1 -- Accuracy when we're crouching and walking
SWEP.WalkCone				= 0.1 -- Accuracy when we're walking
SWEP.AirCone				= 0.25 -- Accuracy when we're in air
SWEP.StandCone				= 0.0001 -- Accuracy when we're standing still

function SWEP:DrawWorldModel()

local hand, offset, rotate

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

hand = self.Owner:GetAttachment(self.Owner:LookupAttachment("anim_attachment_rh"))

offset = hand.Ang:Right() * 0.5 + hand.Ang:Forward() * 0.5 + hand.Ang:Up() * -1

hand.Ang:RotateAroundAxis(hand.Ang:Right(), 10)
hand.Ang:RotateAroundAxis(hand.Ang:Forward(), 10)
hand.Ang:RotateAroundAxis(hand.Ang:Up(), 0)

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

self:DrawModel()

if (CLIENT) then
self:SetModelScale(1,1,1)
end
end

function SWEP:PreDrop()
   self:SetZoom(false)
   return self.BaseClass.PreDrop(self)
end

function SWEP:Holster()
   self:SetZoom(false)
   return true
end

function SWEP:Reload()
   self.Weapon:DefaultReload( ACT_VM_RELOAD );
   self:SetIronsights( false )
   self:SetZoom(false)
end

/*---------------------------------------------------------
IronSight
---------------------------------------------------------*/

if CLIENT then
   SWEP.Icon = "vgui/ttt/icon_awp"
end

function SWEP:SetZoom(state)
    if CLIENT then
       return
    elseif IsValid(self.Owner) and self.Owner:IsPlayer() then
       if state then
          self.Owner:SetFOV(20, 0.3)
       else
          self.Owner:SetFOV(0, 0.2)
       end
    end
end

function SWEP:SecondaryAttack()
    if not self.IronSightsPos then return end
    if self:GetNextSecondaryFire() > CurTime() then return end

    bIronsights = not self:GetIronsights()

    self:SetIronsights( bIronsights )

    if SERVER then
        self:SetZoom(bIronsights)
     else
        --self:EmitSound(self.Secondary.Sound)
    end

    self:SetNextSecondaryFire( CurTime() + 0.3)
end

if CLIENT then
   local scope = surface.GetTextureID("sprites/scope")
   function SWEP:DrawHUD()
      if self:GetIronsights() then
         surface.SetDrawColor( 0, 0, 0, 255 )
         
         local x = ScrW() / 2.0
         local y = ScrH() / 2.0
         local scope_size = ScrH()

         -- crosshair
         local gap = 80
         local length = scope_size
         surface.DrawLine( x - length, y, x - gap, y )
         surface.DrawLine( x + length, y, x + gap, y )
         surface.DrawLine( x, y - length, x, y - gap )
         surface.DrawLine( x, y + length, x, y + gap )

         gap = 0
         length = 50
         surface.DrawLine( x - length, y, x - gap, y )
         surface.DrawLine( x + length, y, x + gap, y )
         surface.DrawLine( x, y - length, x, y - gap )
         surface.DrawLine( x, y + length, x, y + gap )


         -- cover edges
         local sh = scope_size / 2
         local w = (x - sh) + 2
         surface.DrawRect(0, 0, w, scope_size)
         surface.DrawRect(x + sh - 2, 0, w, scope_size)

         surface.SetDrawColor(255, 0, 0, 255)
         surface.DrawLine(x, y, x + 1, y + 1)

         -- scope
         surface.SetTexture(scope)
         surface.SetDrawColor(255, 255, 255, 255)

         surface.DrawTexturedRectRotated(x, y, scope_size, scope_size, 0)

      else
         return self.BaseClass.DrawHUD(self)
      end
   end

   function SWEP:AdjustMouseSensitivity()
      return (self:GetIronsights() and 0.2) or nil
   end
end

/*---------------------------------------------------------
IronSight
---------------------------------------------------------*/

You may need to call Wake on the physics object if everything is loaded / mounted properly but it hangs… I’ve seen this happen before with other objects and typically waking or even if the player nudges it, it’ll spring back to life.

How would I go about doing that?

Entity:PhysWake

I tried adding “self:PhysWake()” to SWEP.PreDrop and that didn’t fix anything. Maybe I’m not putting it in the right place?

I think you should put it in

WEAPON/OnDrop

Side note: is PreDrop a real hook? I don’t see it on the wiki. (although it could be that it’s just not documented)

Just added this, no dice.


function SWEP:OnDrop()
   self:PhysWake()
   return self.BaseClass.OnDrop(self)
end

Try this instead:
[lua]function SWEP:OnDrop()
local ret = self.BaseClass.OnDrop(self)
self:PhysWake()
return ret
end[/lua]

Untested (and typed up on a phone :P)

Tested, no dice.

Then I’m afraid I’m clueless :S

Any way I could just run self:Remove() onDrop and then create another weapon entity?