Skip to content
This repository was archived by the owner on Mar 11, 2021. It is now read-only.

Commit

Permalink
Fixed weapon prediction
Browse files Browse the repository at this point in the history
- Fixed weapon prediction
- Added secondary sound to AUG
- Fixed small gaps while zooming (AUG and AWP)
- Respect "Lowered ironsights"
  • Loading branch information
MinIsMin committed Dec 14, 2017
1 parent 4e73290 commit 3a8a17d
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 56 deletions.
43 changes: 24 additions & 19 deletions lua/weapons/weapon_ghost_augbar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ SWEP.HeadshotMultiplier = 2.5
SWEP.Secondary.Automatic = false
SWEP.UseHands = true
SWEP.Secondary.Ammo = "none"
SWEP.Secondary.Sound = Sound("Default.Zoom")

SWEP.ScopeZooms = {1}
SWEP.ViewModel = Model("models/weapons/cstrike/c_rif_aug.mdl")
Expand All @@ -52,15 +53,13 @@ SWEP.IronSightsAng = Vector( 2.6, 1.37, 3.5 )
SWEP.IronSightZoom = 1

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

-- Add some zoom to ironsights for this gun
Expand All @@ -72,10 +71,10 @@ function SWEP:SecondaryAttack()

self:SetIronsights( bIronsights )

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

self.Weapon:SetNextSecondaryFire( CurTime() + 0.3)
end
Expand Down Expand Up @@ -104,10 +103,12 @@ if CLIENT then
function SWEP:DrawHUD()
if self:GetIronsights() then
surface.SetDrawColor( 0, 0, 0, 255 )
local scrW = ScrW()
local scrH = ScrH()

local x = ScrW() / 2.0
local y = ScrH() / 2.0
local scope_size = ScrH()
local x = scrW / 2.0
local y = scrH / 2.0
local scope_size = scrH

-- crosshair
local gap = 80
Expand All @@ -130,6 +131,10 @@ if CLIENT then
local w = (x - sh) + 2
surface.DrawRect(0, 0, w, scope_size)
surface.DrawRect(x + sh - 2, 0, w, scope_size)

-- cover gaps on top and bottom of screen
surface.DrawLine( 0, 0, scrW, 0 )
surface.DrawLine( 0, scrH - 1, scrW, scrH - 1 )

surface.SetDrawColor(255, 0, 0, 255)
surface.DrawLine(x, y, x + 1, y + 1)
Expand All @@ -139,12 +144,12 @@ if CLIENT then
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
return (self:GetIronsights() and 0.2) or nil
end
end
end
39 changes: 21 additions & 18 deletions lua/weapons/weapon_ghost_awp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,13 @@ SWEP.IronSightsPos = Vector( 5, -15, -2 )
SWEP.IronSightsAng = Vector( 2.6, 1.37, 3.5 )

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

-- Add some zoom to ironsights for this gun
Expand All @@ -58,11 +56,10 @@ function SWEP:SecondaryAttack()

self:SetIronsights( bIronsights )

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

self.Weapon:SetNextSecondaryFire( CurTime() + 0.3)
end
Expand All @@ -74,6 +71,7 @@ function SWEP:PreDrop()
end

function SWEP:Reload()
if ( self:Clip1() == self.Primary.ClipSize or self:GetOwner():GetAmmoCount( self.Primary.Ammo ) <= 0 ) then return end
self.Weapon:DefaultReload(ACT_VM_RELOAD)
self:SetIronsights( false )
self:SetZoom(false)
Expand All @@ -90,10 +88,12 @@ if CLIENT then
function SWEP:DrawHUD()
if self:GetIronsights() then
surface.SetDrawColor( 0, 0, 0, 255 )
local scrW = ScrW()
local scrH = ScrH()

local x = ScrW() / 2.0
local y = ScrH() / 2.0
local scope_size = ScrH()
local x = scrW / 2.0
local y = scrH / 2.0
local scope_size = scrH

-- crosshair
local gap = 80
Expand All @@ -116,6 +116,10 @@ if CLIENT then
local w = (x - sh) + 2
surface.DrawRect(0, 0, w, scope_size)
surface.DrawRect(x + sh - 2, 0, w, scope_size)

-- cover gaps on top and bottom of screen
surface.DrawLine( 0, 0, scrW, 0 )
surface.DrawLine( 0, scrH - 1, scrW, scrH - 1 )

surface.SetDrawColor(255, 0, 0, 255)
surface.DrawLine(x, y, x + 1, y + 1)
Expand All @@ -125,7 +129,6 @@ if CLIENT then
surface.SetDrawColor(255, 255, 255, 255)

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

else
return self.BaseClass.DrawHUD(self)
end
Expand Down
8 changes: 4 additions & 4 deletions lua/weapons/weapon_ghost_base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ function SWEP:PrimaryAttack(worldsnd)
local owner = self:GetOwner()
if not IsValid(owner) or owner:IsNPC() or (not owner.ViewPunch) then return end

owner:ViewPunch( Angle( math.Rand(-0.2,-0.1) * self.Primary.Recoil, math.Rand(-0.1,0.1) * self.Primary.Recoil, 0 ) )
owner:ViewPunch( Angle( util.SharedRandom(self:GetClass(),-0.2,-0.1,0) * self.Primary.Recoil, util.SharedRandom(self:GetClass(),-0.1,0.1,1) * self.Primary.Recoil, 0 ) )
end

function SWEP:DryFire(setnext)
Expand Down Expand Up @@ -321,7 +321,6 @@ function SWEP:ShootBullet( dmg, recoil, numbul, cone )
self.Weapon:SendWeaponAnim(ACT_VM_PRIMARYATTACK)
-- self:GetOwner():SetAnimation( PLAYER_ATTACK1 )

if not IsFirstTimePredicted() then return end

local sights = self:GetIronsights()

Expand Down Expand Up @@ -397,7 +396,6 @@ function SWEP:DrawWeaponSelection() end
function SWEP:SecondaryAttack()

if self.NoSights or (not self.IronSightsPos) then return end
--if self:GetNextSecondaryFire() > CurTime() then return end

self:SetIronsights(not self:GetIronsights())

Expand All @@ -410,6 +408,7 @@ function SWEP:Deploy()
end

function SWEP:Reload()
if ( self:Clip1() == self.Primary.ClipSize or self:GetOwner():GetAmmoCount( self.Primary.Ammo ) <= 0 ) then return end
self.Weapon:DefaultReload(self.ReloadAnim)
self:SetIronsights( false )
end
Expand Down Expand Up @@ -544,6 +543,7 @@ function SWEP:DyingShot()
return fired
end

local ttt_lowered = CreateConVar("ttt_ironsights_lowered", "1", FCVAR_ARCHIVE)
local LOWER_POS = Vector(0, 0, -2)

local IRONSIGHT_TIME = 0.25
Expand Down Expand Up @@ -580,7 +580,7 @@ function SWEP:GetViewModelPosition( pos, ang )
if not bIron then mul = 1 - mul end
end

local offset = self.IronSightsPos + vector_origin
local offset = self.IronSightsPos + (ttt_lowered:GetBool() and LOWER_POS or vector_origin)

if self.IronSightsAng then
ang = ang * 1
Expand Down
27 changes: 12 additions & 15 deletions lua/weapons/weapon_ghost_rifle.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,13 @@ SWEP.IronSightsPos = Vector( 5, -15, -2 )
SWEP.IronSightsAng = Vector( 2.6, 1.37, 3.5 )

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

-- Add some zoom to ironsights for this gun
Expand All @@ -64,12 +62,11 @@ function SWEP:SecondaryAttack()
local bIronsights = not self:GetIronsights()

self:SetIronsights( bIronsights )

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

self:SetZoom(bIronsights)
if (CLIENT) then
self:EmitSound(self.Secondary.Sound)
end

self.Weapon:SetNextSecondaryFire( CurTime() + 0.3)
end
Expand Down

0 comments on commit 3a8a17d

Please sign in to comment.