Weapon Model Repositioning Error

I’ve been scripting and editing a few weapons on the game mode Trouble in Terrorist Town (TTT) please keep in mind that I’m fairly new to LUA, and I’ve come to an end with this one error. I play with friends privately, server hosted via hamachi, and everybody has the same add-on and models, but to no extent, I can’t fix this model error from occurring. So I’ve been using this code to reposition the custom weapon so that it fits in the player’s hand. However the downside to this, is that whenever a player drops the weapon they see the weapon drop, but others view it in the air. http://puu.sh/8QAri.png
If I remove the code(below) the weapon appears inside the player model’s body, when I use the code, players see the weapon in the air when dropped. I was wondering if there is any solution to this? I’ve searched almost everywhere for the past week, and I can’t seem to find anything on this. Please keep in mind that this is a custom weapon, not the vanilla ones.
Any input will be helpful, thank you.

Code that fixes weapon appearing in player model but weapon appears in air when dropped.


SWEP.Offset = {
Pos = {
Up = 0,
Right = 1,
Forward = -3,
},
Ang = {
Up = 0,
Right = 0,
Forward = 0,
}
}

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

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

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

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

if not hand then
self:DrawModel( )
return
end

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( )
end

Full code for the custom weapon


if ( SERVER ) then
	AddCSLuaFile( "shared.lua" )
	SWEP.HoldType = "ar2"

end

if ( CLIENT ) then

	SWEP.PrintName			= "AN-94"	
	SWEP.Slot				= 2
	SWEP.ViewModelFOV		= 70
	SWEP.IconLetter			= "an-94"

end

SWEP.Base				= "weapon_tttbase"
SWEP.Kind				= WEAPON_HEAVY
SWEP.ShowWorldModel			= true
SWEP.Spawnable			= true
SWEP.AdminSpawnable		= true
SWEP.AutoSpawnable		= true
SWEP.ViewModel				= "models/weapons/v_rif_an47.mdl"
SWEP.WorldModel				= "models/weapons/w_rif_an47.mdl"
SWEP.ViewModelFlip		= true
SWEP.HoldType = "ar2"
SWEP.Primary.Sound 		= Sound("weapons/an47/MP5-1.wav")
SWEP.Primary.Recoil 		= 3
SWEP.Primary.Damage 		= 18
SWEP.Primary.Automatic   = true
SWEP.Primary.ClipSize 		= 30
SWEP.Primary.DefaultClip	= 30
SWEP.Primary.Delay 			= 0.14
SWEP.Primary.Cone        = 0.035
SWEP.Primary.Ammo        = "smg1"
SWEP.AmmoEnt = "item_ammo_smg1_ttt"
SWEP.NoSights = false
SWEP.Primary.ClipMax = 90

SWEP.IronSightsPos = Vector (2.2829, -3.7942, 1.389)
SWEP.IronSightsAng = Vector (-0.5703, 1.9105, 0.4451)

--- TTT config values

-- Kind specifies the category this weapon is in. Players can only carry one of
-- each. Can be: WEAPON_... MELEE, PISTOL, HEAVY, NADE, CARRY, EQUIP1, EQUIP2 or ROLE.
-- Matching SWEP.Slot values: 0      1       2     3      4      6       7        8
SWEP.Kind = WEAPON_HEAVY

-- If AutoSpawnable is true and SWEP.Kind is not WEAPON_EQUIP1/2, then this gun can
-- be spawned as a random weapon. Of course this AK is special equipment so it won't,
-- but for the sake of example this is explicitly set to false anyway.
SWEP.AutoSpawnable = true

-- The AmmoEnt is the ammo entity that can be picked up when carrying this gun.
SWEP.AmmoEnt = "item_ammo_smg1_ttt"

-- If IsSilent is true, victims will not scream upon death.
SWEP.IsSilent = false

resource.AddFile("models/weapons/w_rif_an47")
resource.AddFile("models/weapons/v_rif_an47.mdl")

function SWEP:SetZoom(state)
   if CLIENT then return end
   if not (IsValid(self.Owner) and self.Owner:IsPlayer()) then return end
   if state then
      self.Owner:SetFOV(35, 0.5)
   else
      self.Owner:SetFOV(0, 0.2)
   end
end


function SWEP:Reload()
    if (self:Clip1() == self.Primary.ClipSize or
        self.Owner:GetAmmoCount(self.Primary.Ammo) <= 0) then
       return
    end
    self:DefaultReload(ACT_VM_RELOAD)
    self:SetIronsights(false)
    self:SetZoom(false)
end

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


SWEP.Offset = {
Pos = {
Up = 0,
Right = 1,
Forward = -3,
},
Ang = {
Up = 0,
Right = 0,
Forward = 0,
}
}

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

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

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

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

if not hand then
self:DrawModel( )
return
end

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( )
end

bump-- been searching for a week now, can’t find a solution.

Is the actual .mdl for the weapon on your server?

Yes, and it’s a listen server, so my friends have the add-on and the models.

While the weapon is held you are calling SetRenderPosition/Angles.
When it’s dropped, you are no longer calling that, so it will be stuck at the last position you updated.

Simply change:
[lua]
if not IsValid( self.Owner ) then
–Add this
self:SetRenderOrigin( self:GetPos() )
self:SetRenderAngles( self:GetAngles() )
–End of changes
self:DrawModel( )
return
end[/lua]

Thank you for replying and taking time to look this over. However I inserted the code in and the weapon still floats in the air.

https://dl.dropboxusercontent.com/u/26074909/tutoring/server_srcds_steamcmd/setting_up_a_server_with_steamcmd.lua.html

Make sure CS:S is properly mounted… I helped someone yesterday with this issue with FA:S mod ( it wasn’t properly installed on the server and didn’t mount as a result )… Make sure the addon folder is all lowercase, and make sure there aren’t hyphens in the name.

There used to be a helpful function you could call to fix the issue in the game; but it was removed so it is only a part of the main-menu now…

Double-check that everything is correct, have your friend try and create a dedicated server; it is REALLY EASY, just follow my tutorial above; it takes about 15 minutes with the downloads, all of the batch file contents are listed and in what order you run them. It goes over trouble-shooting in case of an issue and I update it as things appear…

Make sure you don’t have any CS:S content packs or models overriding the default ones.

To add to this, grab GCFScape and look in the Garry’s Mod _dir.vpk; there are “fallback” CS:S models; try those and see if they work ( if they do, then the issue is with the originals not being properly mounted ) — ( Actually, they might be the ones loading as I believe they share names with CS:S weapons… ).

Since it is a listen-server; make sure the host has the CS:S checkmarked from within the main-menu for games to mount.

Thank you both so much for helping, but I have disabled the CS;S content packs, and checked everything you both said. I’m the host, I do have the CS:S check marked and it’s mounted properly, the original models work as well, but to no avail the weapon seems to be still floating. A few other custom weapons work, but it’s just this one, and I can’t seem to wrap my head around it. Again, I thank you both for helping, hopefully I can keep searching for a solution or someone here has another solution to it. Or maybe it may just be the model itself.

The fallback models don’t exist, and my addon providing the models was removed by Steam mods.