1. Post #1

    December 2010
    112 Posts
    I found this online. The view models are fine, but it appears as if the gun is coming out of player's waists. There is also no physics when a gun is dropped, so it will just float there.

    Search engine didnt help, so I'm crossing my fingers someone will post, Thanks guys!

    Code:
    if SERVER then
       AddCSLuaFile( "shared.lua" )
       resource.AddFile("models/weapons/v_snip_hex.mdl")
       resource.AddFile("models/weapons/w_snip_hex.mdl")
       resource.AddFile("materials/models/weapons/v_models/M82/M82.vmt")
       resource.AddFile("materials/models/weapons/w_models/M82/M82.vmt")
    end
    
    SWEP.HoldType           = "ar2"
    
    if CLIENT then
       SWEP.PrintName          = "AW Magnum Snip."
    
       SWEP.Slot               = 7
    
       SWEP.Icon = "VGUI/ttt/icon_bb_awm"
       SWEP.EquipMenuData = {
          type="Sniper Weapon",
          model="models/weapons/w_snip_awp.mdl",
          name="Artic Warfare Magnum",
          desc="The Artic Warfare Magnum\n (AWM) is a powerful sniper rifle.\n One shot is almost deadly,\n but it's extremely loud. And you need a good aim. You get two chances tho."
       };
    end
    
    
    SWEP.Base               = "weapon_tttbase"
    SWEP.Spawnable = true
    SWEP.AdminSpawnable = true
    
    SWEP.Kind = WEAPON_HEAVY
    
    SWEP.Primary.Delay          = 2
    SWEP.Primary.Recoil         = 5
    SWEP.Primary.Automatic = true
    SWEP.Primary.Ammo = "None";
    SWEP.Primary.Damage = 105
    SWEP.Primary.Cone = 0.0001
    SWEP.Primary.ClipSize = 2
    SWEP.Primary.ClipMax = 2 -- keep mirrored to ammo
    SWEP.Primary.DefaultClip = 2
    
    SWEP.Kind = WEAPON_EQUIP2
    SWEP.CanBuy = {ROLE_TRAITOR} -- only traitors can buy
    SWEP.LimitedStock = true -- only buyable once
    
    SWEP.HeadshotMultiplier = 6
    
    SWEP.AutoSpawnable      = false
    SWEP.AmmoEnt = "item_ammo_awm_ttt"
    SWEP.ViewModel          = Model("models/weapons/v_snip_hex.mdl")
    SWEP.WorldModel         = Model("models/weapons/w_snip_hex.mdl")
    
    SWEP.Primary.Sound = Sound("weapon_AWP.Single")
    
    SWEP.Secondary.Sound = Sound("Default.Zoom")
    
    SWEP.IronSightsPos = Vector (5.5479, -21.9574, 1.5427)
    SWEP.IronSightsAng = Vector (-11.6507, 0.5963, 0)
    
    
    function SWEP:SetZoom(state, reset)
        if CLIENT then 
           return
        else
                    if reset then
                            self.Owner:SetFOV(0, 0.2)
                            return 0
                    end        
                    if self.Owner:GetFOV() == 25 then 
                    self.Owner:SetFOV(10, 0.2)
                    return 10
                    else
                       if state then
                              self.Owner:SetFOV(25, 0.3)
                              return 25
                       else
                              self.Owner:SetFOV(0, 0.2)
                              return 0
                       end
               end
            end        
    end
    
    -- Add some zoom to ironsights for this gun
    function SWEP:SecondaryAttack()
            local result = 0
        if not self.IronSightsPos then return end
        if self.Weapon:GetNextSecondaryFire() > CurTime() then return end
        
        bIronsights = not self:GetIronsights()
        
        
        
        if SERVER then
            result = self:SetZoom(bIronsights)
                    if result == 0 then
                            self:SetIronsights( false )
                    else
                            self:SetIronsights( true )
                    end
         else
            self:EmitSound(self.Secondary.Sound)
        end
        
        self.Weapon:SetNextSecondaryFire( CurTime() + 0.15)
    end
    
    function SWEP:PreDrop()
        self:SetZoom(false, true)
        self:SetIronsights(false)
        return self.BaseClass.PreDrop(self)
    end
    
    function SWEP:Reload()
        self.Weapon:DefaultReload( ACT_VM_RELOAD );
        self:SetIronsights( false )
        self:SetZoom(false, true)
    end
    
    
    function SWEP:Holster()
        self:SetIronsights(false)
        self:SetZoom(false, true)
        return true
    end
    
    function SWEP:OnRestore()
       self.NextSecondaryAttack = 0
       self:SetIronsights( false )
       self:SetZoom(false, true)
    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
    end
    (User was banned for this post ("Wrong section yet again." - postal))
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  2. Post #2
    ElPunto's Avatar
    June 2009
    34 Posts
    The problem with crotch guns (waist guns) as they are known isnt to do with the lua scripting.

    All weapon world happens have attachments that are used to position the weapon view model. Those attachments are then attached the LH and RH anim attachments of a player model. In this case the attachments are not present in the model. The engine defaults to origin of the player model (roughly the crotch afaik) and the weapon model.

    You need to find a version of this model that has valid attachments for the hands.
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  3. Post #3
    Gold Member
    Kogitsune's Avatar
    September 2005
    2,860 Posts
    Define SWEP:DrawWorldModel, and position it yourself.

    Code:
    SWEP.Offset = {
        Pos = {
            Up = 0,
            Right = 0,
            Forward = 0,
        },
        Ang = {
            Up = 0,
            Right = 0,
            Forward = 0,
        }
    }
    
    function SWEP:DrawWorldModel( )
        local hand, offset, rotate
        
        if not ValidEntity( 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
    Figure the angle first and then figure out the position.
    Reply With Quote Edit / Delete Windows 7 United States Show Events Disagree Disagree x 1 (list)

  4. Post #4
    sentrygunman's Avatar
    September 2008
    796 Posts
    Define SWEP:DrawWorldModel, and position it yourself.

    Code:
    SWEP.Offset = {
        Pos = {
            Up = 0,
            Right = 0,
            Forward = 0,
        },
        Ang = {
            Up = 0,
            Right = 0,
            Forward = 0,
        }
    }
    
    function SWEP:DrawWorldModel( )
        local hand, offset, rotate
        
        if not ValidEntity( 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
    Figure the angle first and then figure out the position.
    Or you can do it the proper way and re-rig the bones.
    Reply With Quote Edit / Delete Windows 7 United States Show Events Agree Agree x 1 (list)

  5. Post #5

    December 2010
    112 Posts
    Thanks for all the replies everyone. I have no experience with creating models and materials, so that option I would like to avoid. As for the code from Kog, I added it to the swep and put "2" as the position for up, it didnt do anything.

    As for sentrygun's reriging idea, i have no idea how or what that is.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  6. Post #6
    Gold Member
    Kogitsune's Avatar
    September 2005
    2,860 Posts
    Or you can do it the proper way and re-rig the bones.
    Let's recompile models and break usage licenses when we can use simple code!

    For models that are licensed as no-derivative, does a hex/recompile of the model legally count a derivative work?
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  7. Post #7
    NaRyan's Avatar
    November 2009
    244 Posts
    Or the OP could read his post on the TTT forums where the answer to his problem has already been given....
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events