Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if SERVER then
- AddCSLuaFile( "shared.lua" )
- end
- if CLIENT then
- SWEP.Slot = 2
- SWEP.SlotPos = 2
- SWEP.ViewModelFlip = false --true for CSS, false for non-css
- end
- SWEP.Base = "weapon_base" --weapon_zw_base
- SWEP.PrintName = "ZW Weapon Base" --name
- SWEP.Author = "Fizzadar"
- SWEP.Instructions = "Shoot stuff."
- SWEP.ViewModel = "models/weapons/v_357.mdl" --view model
- SWEP.WorldModel = "models/weapons/w_357.mdl" --world model
- SWEP.ShootWhileSprinting = true --can they shoot while sprinting?
- SWEP.HoldType = "pistol" --pistol, ar2, normal, melee, smg, grenade, shotgun
- SWEP.MuzzleEffect = "rg_muzzle_pistol" --rg_muzzle_grenade, rg_muzzle_highcal, rg_muzzle_hmg, rg_muzzle_pistol, rg_muzzle_rifle, rg_muzzle_silenced
- SWEP.ShellEffect = "rg_shelleject" --rg_shelleject, rg_shelleject_rifle, rg_shelleject_shotgun
- SWEP.MuzzleAttachment = "1" -- Should be "1" for CSS models or "muzzle" for hl2 models
- SWEP.ShellEjectAttachment = "2" -- Should be "2" for CSS models or "1" for hl2 models
- SWEP.IconLetter = "f" --get from other weps (image that appears in wep selection)
- SWEP.Primary.ClipSize = 6 --clip size
- SWEP.Primary.Ammo = "Pistol" --pistol, buckshot, smg1
- SWEP.Primary.Damage = 50 --damage
- SWEP.Primary.Spread = 0.03 --bullet spread (make it tiny)
- SWEP.Primary.Bullets = 1 --bullets to fire
- SWEP.Primary.FireSound = Sound( "Weapon_357.Single" ) --shooting sound
- SWEP.Primary.Delay = 0.35 --delay per shot
- SWEP.Primary.Automatic = false --automatic fire?
- SWEP.Primary.Recoil = 1
- --//////////////////////////End Config
- SWEP.Contact = ""
- SWEP.Purpose = ""
- SWEP.Spawnable = true
- SWEP.AdminSpawnable = true
- if( SERVER ) then
- SWEP.AutoSwitchTo = false
- SWEP.AutoSwitchFrom = false
- end
- if( CLIENT ) then
- SWEP.DrawAmmo = true
- SWEP.DrawCrosshair = false
- SWEP.ViewModelFOV = 62
- end
- --fixed weapons giving ammo
- SWEP.Primary.DefaultClip = SWEP.Primary.ClipSize
- --secondary ammo (no secondary fire)
- SWEP.Secondary.ClipSize = -1
- SWEP.Secondary.DefaultClip = -1
- SWEP.Secondary.Automatic = false
- SWEP.Secondary.Ammo = "none"
- util.PrecacheSound( SWEP.Primary.FireSound )
- --startup
- function SWEP:Initialize()
- if( SERVER ) then
- self:SetWeaponHoldType( self.Weapon.HoldType )
- end
- end
- --get the wep out
- function SWEP:Deploy()
- if self.DeploySound then
- self.Owner:EmitSound( self.DeploySound )
- end
- self.Weapon:SendWeaponAnim( ACT_VM_DEPLOY )
- return true
- end
- --calculate recoil
- function SWEP:CalcRecoil()
- --basic start
- local RecoilBase = self.Primary.Recoil
- if self.Owner:KeyDown( IN_MOVELEFT ) or self.Owner:KeyDown( IN_MOVERIGHT ) or self.Owner:KeyDown( IN_FORWARD ) or self.Owner:KeyDown( IN_BACK ) then
- RecoilBase = RecoilBase * 1.2
- if self.Owner:KeyDown( IN_SPEED ) then
- RecoilBase = RecoilBase * 1.2
- end
- end
- RecoilBase = RecoilBase * 2
- --compensate for crouch
- if self.Owner:KeyDown( IN_DUCK ) then
- RecoilBase = RecoilBase * 0.25
- end
- --compensate for ironsights
- if self.Owner:KeyDown( IN_ATTACK2 ) then
- RecoilBase = RecoilBase * 0.75
- end
- return Angle( ( math.Clamp( math.random( RecoilBase - 10, RecoilBase + 10 ) , 0.3, 100 ) ) * -1, 0, 0 )
- end
- --left click attack
- function SWEP:PrimaryAttack()
- if not self:CanPrimaryAttack() or self.Owner:WaterLevel() >= 2 then return end
- self.Weapon:SetNextPrimaryFire( CurTime() + self.Weapon.Primary.Delay )
- self.Owner:MuzzleFlash()
- self.Owner:SetAnimation( PLAYER_ATTACK1 )
- self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
- if SERVER then self.Owner:EmitSound( self.Primary.FireSound ) end
- self:TakePrimaryAmmo( 1 )
- self.Owner:ViewPunch( self:CalcRecoil() * 0.2 )
- self.Owner:SetEyeAngles( self.Owner:EyeAngles() + ( self:CalcRecoil() * 0.2 ) )
- local bullet = {}
- bullet.Num = self.Weapon.Primary.Bullets
- bullet.Src = self.Owner:GetShootPos()
- bullet.Dir = self.Owner:GetAimVector()
- bullet.Spread = Vector( self.Weapon.Primary.Spread, self.Weapon.Primary.Spread, 0 )
- bullet.Tracer = 1
- bullet.Force = self.Weapon.Primary.Damage
- bullet.Damage = self.Weapon.Primary.Damage
- self.Owner:FireBullets( bullet )
- if CLIENT then
- if guneffects then
- local fx = EffectData()
- fx:SetEntity(self.Weapon)
- fx:SetOrigin(self.Owner:GetShootPos())
- fx:SetNormal(self.Owner:GetAimVector())
- fx:SetAttachment(self.MuzzleAttachment)
- util.Effect(self.MuzzleEffect,fx)
- local fx = EffectData()
- fx:SetEntity(self.Weapon)
- fx:SetNormal(self.Owner:GetAimVector())
- fx:SetAttachment(self.ShellEjectAttachment)
- util.Effect(self.ShellEffect,fx)
- end
- end
- end
- function SWEP:CanPrimaryAttack()
- if self.Weapon:Clip1() <= 0 then
- self.Weapon:SetNextPrimaryFire( CurTime() + 0.5 )
- self.Owner:EmitSound( "Weapons/ClipEmpty_Pistol.wav" )
- return false
- end
- local IsMoving = false
- if self.Owner:KeyDown( IN_MOVELEFT ) or self.Owner:KeyDown( IN_MOVERIGHT ) or self.Owner:KeyDown( IN_FORWARD ) or self.Owner:KeyDown( IN_BACK ) then
- IsMoving = true
- end
- if self.Owner:KeyDown( IN_SPEED ) and IsMoving and not self.ShootWhileSprinting then
- return false
- end
- return true
- end
- --secondary
- function SWEP:SecondaryAttack()
- return false
- end
- --think
- function SWEP:Think()
- if self.Owner:KeyPressed( IN_ATTACK2 ) then
- if self.IsSniper then
- if not self:GetNWBool( "IsScoped" ) then
- self:SetNWBool( "IsScoped", true )
- self.Owner:SetFOV( 40, 0.15 )
- end
- else
- self.Owner:SetFOV( 65, 0.15 )
- self.DrawCrosshair = true
- end
- end
- if self.Owner:KeyReleased( IN_ATTACK2 ) then
- if self.IsSniper then
- if self:GetNWBool( "IsScoped" ) then
- self:SetNWBool( "IsScoped", false )
- self.Owner:SetFOV( 0, 0.15 )
- end
- else
- self.Owner:SetFOV( 0, 0.15 )
- self.DrawCrosshair = false
- end
- end
- end
- --reload
- function SWEP:Reload()
- self.Weapon:DefaultReload( ACT_VM_RELOAD )
- self.Owner:SetFOV( 0, 0.15 )
- end
- --weapon icon in selection bit
- function SWEP:DrawWeaponSelection( x, y, wide, tall, alpha )
- --draw.SimpleText( self.Weapon.IconLetter, "CSSelectIcons", x + wide/2, y + tall*0.2, Color( 255, 210, 0, 255 ), TEXT_ALIGN_CENTER )
- draw.SimpleText( self.Weapon.PrintName, "ZWFontTypeSmall", x + wide/2, y + tall*0.2, Color( 255, 210, 0, 255 ), TEXT_ALIGN_CENTER )
- end
- --scopes
- function SWEP:DrawHUD()
- if not self.IsSniper then return end
- if self:GetNWBool( "IsScoped" ) then
- local w = ScrW()
- local h = ScrH()
- local wr = ( h / 3 ) * 4
- --draw scope
- surface.SetTexture( surface.GetTextureID( "gmod/scope" ) )
- surface.SetDrawColor( 0, 0, 0, 255 )
- surface.DrawTexturedRect( ( w / 2 ) - wr / 2, 0, wr, h )
- surface.SetDrawColor( 0, 0, 0, 255 )
- surface.DrawRect( 0, 0, ( w / 2 ) - wr / 2, h )
- surface.DrawRect( ( w / 2 ) + wr / 2, 0, w - ( ( w / 2 ) + wr / 2 ), h )
- surface.DrawLine( 0, h * 0.50, w, h * 0.50 )
- surface.DrawLine( w * 0.50, 0, w * 0.50, h )
- local tr = util.TraceLine( util.GetPlayerTrace(self.Owner) )
- local dist = math.Clamp( math.ceil( tr.HitPos:Distance( self.Owner:GetPos() ) / 16 ), 2, 999999 )
- local target = "N/A"
- if tr.Entity:IsNPC() then
- target = tr.Entity:GetClass()
- elseif tr.Entity:IsPlayer() then
- target = tr.Entity:GetName()
- end
- surface.SetFont( "Default" )
- surface.SetTextColor( 255, 255, 255, 255 )
- surface.SetTextPos( w * 0.90, h * 0.50 )
- surface.DrawText( "Distance: "..dist.." feet" )
- surface.SetTextPos( w * 0.90, h * 0.52 )
- surface.DrawText( "Target: "..target )
- end
- end
- --sprint stuff
- SWEP.RunArmAngle = Angle( 10, 50, 20 )
- SWEP.RunArmOffset = Vector( 1, 2, -5 ) --down, forward, right
- function SWEP:GetViewModelPosition( pos, ang )
- if self.ShootWhileSprinting then
- return pos, ang
- end
- local Owner = self.Owner
- if (!Owner) then
- return pos, ang
- end
- local DashDelta = 0
- // If we're running, or have just stopped running, lerp between the
- local IsMoving = false
- if self.Owner:KeyDown( IN_MOVELEFT ) or self.Owner:KeyDown( IN_MOVERIGHT ) or self.Owner:KeyDown( IN_FORWARD ) or self.Owner:KeyDown( IN_BACK ) then
- IsMoving = true
- end
- if self.Owner:KeyDown( IN_SPEED ) and IsMoving then
- if (!self.DashStartTime) then
- self.DashStartTime = CurTime()
- end
- DashDelta = math.Clamp( ((CurTime() - self.DashStartTime) / 0.1) ^ 1.2, 0, 1 )
- else
- if ( self.DashStartTime ) then
- self.DashEndTime = CurTime()
- end
- if ( self.DashEndTime ) then
- DashDelta = math.Clamp( ((CurTime() - self.DashEndTime) / 0.1) ^ 1.2, 0, 1 )
- DashDelta = 1 - DashDelta
- if ( DashDelta == 0 ) then self.DashEndTime = nil end
- end
- self.DashStartTime = nil
- end
- if ( DashDelta ) then
- local Down = ang:Up() * -1
- local Right = ang:Right()
- local Forward = ang:Forward()
- // Offset the viewmodel to self.RunArmOffset
- pos = pos + ( Down * self.RunArmOffset.x + Forward * self.RunArmOffset.y + Right * self.RunArmOffset.z ) * DashDelta
- // Rotate the viewmodel to self.RunArmAngle
- ang:RotateAroundAxis( Right, self.RunArmAngle.pitch * DashDelta )
- ang:RotateAroundAxis( Down, self.RunArmAngle.yaw * DashDelta )
- ang:RotateAroundAxis( Forward, self.RunArmAngle.roll * DashDelta )
- end
- return pos, ang
- end
Add Comment
Please, Sign In to add comment