Initial commit

This commit is contained in:
pavetr
2026-03-15 14:54:49 +03:00
commit 64f8029c06
4027 changed files with 254888 additions and 0 deletions

View File

@@ -0,0 +1,114 @@
function SWEP:OnRemove()
for k, v in pairs(self._attachments or {}) do
if IsValid(v.csEnt) then v.csEnt:Remove() end
end
end
local function drawOpticAttach(self, flags)
local weap = self.parent
if not IsValid(weap) then return end
local ply = self:GetParent()
if not IsValid(ply) then return end
if ply:GetActiveWeapon() ~= weap then return end
self:DrawModel(flags)
if not qwb.ironsighted then return end
local scopeMat = self.opticMat
local attID = weap:LookupAttachment('muzzle')
if not attID then return end
local att = weap:GetAttachment(attID)
if not att then return end
local pos, ang = LocalToWorld(self.opticPos, self.opticAng or angle2, self:GetPos(), att.Ang)
local w, h = unpack(self.opticSize)
local radius = math.max(w, h)
local semiRadius = radius * 0.5
qwb.fullyClearStencil()
render.SetStencilEnable(true)
render.SetStencilCompareFunction(STENCIL_ALWAYS)
render.SetStencilFailOperation(STENCIL_ZERO)
render.SetStencilZFailOperation(STENCIL_ZERO)
render.SetStencilPassOperation(STENCIL_REPLACE)
render.SetStencilReferenceValue(1)
cam.Start3D2D(pos, ang, 0.01)
draw.NoTexture()
surface.SetDrawColor(color_black)
draw_Circle(semiRadius, semiRadius, semiRadius, 30)
cam.End3D2D()
render.SetStencilCompareFunction(STENCIL_EQUAL)
cam.Start3D2D(pos, ang, 0.01)
surface.SetDrawColor(color_white)
surface.SetMaterial(mat)
surface.DrawTexturedRect(0, 0, w, h)
surface.SetDrawColor(color_white)
surface.SetMaterial(scopeMat)
surface.DrawTexturedRect(0, 0, w, h)
cam.End3D2D()
render.SetStencilEnable(false)
end
net.Receive('qwb.setAttachment', function()
local weap = net.ReadEntity()
if not IsValid(weap) then return end
local attachType, attachID = net.ReadString(), net.ReadString()
local data = weap.Attachments[attachType] and weap.Attachments[attachType][attachID]
if not data then return end
weap._attachments = weap._attachments or {}
weap._attachments[attachType] = weap._attachments[attachType] or {}
local tbl = weap._attachments[attachType]
tbl.id = attachID
if IsValid(tbl.csEnt) then tbl.csEnt:Remove() end
local owner = weap:GetOwner()
if not IsValid(tbl.csEnt) then
tbl.csEnt = ClientsideModel(data.mdl)
tbl.csEnt:SetParent(LocalPlayer(), LocalPlayer():LookupAttachment('anim_attachment_rh'))
tbl.csEnt:SetLocalPos(data.pos)
tbl.csEnt:SetLocalAngles(data.ang)
tbl.csEnt:SetModelScale(data.scale or 1)
tbl.csEnt.parent = weap
if data.opticPos and owner == LocalPlayer() then
tbl.csEnt.opticPos = data.opticPos
tbl.csEnt.opticAng = data.opticAng
tbl.csEnt.opticSize = data.opticSize
tbl.csEnt.opticMat = data.opticMat or weap.DefaultScopeMat
tbl.csEnt.RenderOverride = drawOpticAttach
end
tbl.csEnt:Spawn()
end
end)
net.Receive('qwb.removeAttachment', function()
local weap = net.ReadEntity()
if not IsValid(weap) then return end
if not weap._attachments then return end
local attachType = net.ReadString()
if not weap._attachments[attachType] then return end
if IsValid(weap._attachments[attachType].csEnt) then weap._attachments[attachType].csEnt:Remove() end
weap._attachments[attachType] = nil
end)

View File

@@ -0,0 +1,38 @@
local color_bg = Color(0, 0, 0, 190)
function SWEP:OpenAttMenu()
self._attMenu = vgui.Create('DPanel')
local pnl = self._attMenu
pnl:SetSize(ScrW(), ScrH())
function pnl:Paint(w, h)
surface.SetDrawColor(color_bg)
surface.DrawRect(0, 0, w, h)
end
qwb.attMenuOpened = true
end
function SWEP:CloseAttMenu()
self._attMenu:Remove()
self._attMenu = nil
qwb.attMenuOpened = nil
end
function SWEP:ToggleAttMenu()
if IsValid(self._attMenu) then
self:CloseAttMenu()
else
self:OpenAttMenu()
end
end
-- hook.Add('OnContextMenuOpen', 'qwb.att.menu', function()
-- local weap = LocalPlayer():GetActiveWeapon()
-- if not IsValid(weap) then return end
-- if not weap.IsQWB then return end
-- weap:ToggleAttMenu()
-- end)

View File

@@ -0,0 +1,128 @@
include('shared.lua')
include('sh_att.lua')
include('cl_att.lua')
include('cl_att_menu.lua')
local size = 512
local RT = GetRenderTarget('qwb_scope', size, size)
local mat = CreateMaterial('qwb_scope', 'UnlitGeneric', {
['$basetexture'] = RT:GetName(),
['$translucent'] = 1,
['$vertexcolor'] = 1,
})
local vector_origin = Vector()
local angle1, angle2 = Angle(0, 0, -90), Angle(-90, 0, 0)
local color_white, color_black = Color(255, 255, 255), Color(0, 0, 0)
local function draw_Circle( x, y, radius, seg )
local cir = {}
table.insert( cir, { x = x, y = y, u = 0.5, v = 0.5 } )
for i = 0, seg do
local a = math.rad( ( i / seg ) * -360 )
table.insert( cir, { x = x + math.sin( a ) * radius, y = y + math.cos( a ) * radius, u = math.sin( a ) / 2 + 0.5, v = math.cos( a ) / 2 + 0.5 } )
end
local a = math.rad( 0 ) -- This is needed for non absolute segment counts
table.insert( cir, { x = x + math.sin( a ) * radius, y = y + math.cos( a ) * radius, u = math.sin( a ) / 2 + 0.5, v = math.cos( a ) / 2 + 0.5 } )
surface.DrawPoly( cir )
end
hook.Add('Think', 'qwb.renderScope', function()
if not qwb.ironsighted then return end
local weap = LocalPlayer():GetActiveWeapon()
if not IsValid(weap) or not weap.IsQWB then return end
local sightData = weap:GetAttach('sights')
if not weap.ScopeOffset and (not sightData or not IsValid(sightData.csEnt) or not sightData.csEnt.opticPos) then return end
local att = weap:GetAttachment( weap:LookupAttachment('muzzle') )
if not att then return end
local pos, ang = att.Pos, att.Ang
local _, scopeAng = LocalToWorld( vector_origin, angle1, pos, ang )
local data = sightData and weap.Attachments and weap.Attachments.sights and weap.Attachments.sights[ sightData.id ]
render.PushRenderTarget(RT)
render.RenderView({
origin = pos,
angles = scopeAng,
fov = weap.ScopeFOV or (data and data.opticFOV) or 10,
})
render.PopRenderTarget()
end)
net.Receive('qwb.muzzleFlashLight', function()
local weap = net.ReadEntity()
if not IsValid(weap) then return end
local dlight = DynamicLight( weap:EntIndex() )
if dlight then
dlight.pos = weap:GetBulletSourcePos()
dlight.r = 255
dlight.g = 145
dlight.b = 10
dlight.brightness = 1
dlight.Decay = 6666
dlight.Size = 512
dlight.DieTime = CurTime() + 0.2
end
end)
function SWEP:DrawWorldModel(flags)
self:DrawModel(flags)
if not self.ScopeOffset or not self.ScopeSize then return end
if not qwb.ironsighted then return end
local owner = self:GetOwner()
if not IsValid(owner) then return end
if owner ~= LocalPlayer() then return end
local scopeMat = self.ScopeMat or self.DefaultScopeMat
local att = self:GetAttachment( self:LookupAttachment('muzzle') )
if not att then return end
local pos, ang = LocalToWorld(self.ScopeOffset, angle2, att.Pos, att.Ang)
local w, h = unpack(self.ScopeSize)
local radius = math.max(w, h)
local semiRadius = radius * 0.5
qwb.fullyClearStencil()
render.SetStencilEnable(true)
render.SetStencilCompareFunction(STENCIL_ALWAYS)
render.SetStencilFailOperation(STENCIL_ZERO)
render.SetStencilZFailOperation(STENCIL_ZERO)
render.SetStencilPassOperation(STENCIL_REPLACE)
render.SetStencilReferenceValue(1)
cam.Start3D2D(pos, ang, 0.01)
draw.NoTexture()
surface.SetDrawColor(color_black)
draw_Circle(semiRadius, semiRadius, semiRadius, 30)
cam.End3D2D()
render.SetStencilCompareFunction(STENCIL_EQUAL)
cam.Start3D2D(pos, ang, 0.01)
surface.SetDrawColor(color_white)
surface.SetMaterial(mat)
surface.DrawTexturedRect(0, 0, w, h)
surface.SetDrawColor(color_white)
surface.SetMaterial(scopeMat)
surface.DrawTexturedRect(0, 0, w, h)
cam.End3D2D()
render.SetStencilEnable(false)
end
function SWEP:SecondaryAttack()
end

View File

@@ -0,0 +1,35 @@
AddCSLuaFile('cl_init.lua')
AddCSLuaFile('shared.lua')
AddCSLuaFile('sh_att.lua')
AddCSLuaFile('cl_att.lua')
AddCSLuaFile('cl_att_menu.lua')
include('shared.lua')
include('sh_att.lua')
include('sv_att.lua')
function SWEP:CreateShootRage()
if not self.ShootRage then self.ShootRage = 0 end
self.ShootRage = self.ShootRage + self.HorizontalRecoil / 15
end
function SWEP:SecondaryAttack()
if self:GetSafetyStance() then return end
if not IsValid(self:GetOwner()) then return end
local owner = self:GetOwner()
if qwb.isPlayerRunning(owner) then return end
self.Ironsighted = not self.Ironsighted
if self.AimSound then
owner:EmitSound(self.AimSound, nil, nil, self.AimSoundVolume or 0.25)
end
net.Start('qwb.setIronsight')
net.WriteBool(self.Ironsighted)
net.Send(owner)
end

View File

@@ -0,0 +1,3 @@
function SWEP:GetAttach(att)
return self._attachments and self._attachments[att]
end

View File

@@ -0,0 +1,356 @@
SWEP.Weight = 5
SWEP.DrawAmmo = true
SWEP.DrawCrosshair = false
SWEP.CSMuzzleFlashes = true
SWEP.Base = 'weapon_base'
SWEP.IsQWB = true
SWEP.Author = 'qurs'
SWEP.Contact = ''
SWEP.Purpose = ''
SWEP.Instructions = ''
SWEP.ViewModel = 'models/weapons/v_knife_t.mdl'
SWEP.DefaultScopeMat = Material('materials/qwb/scope/awp.png')
SWEP.Category = 'qurs\' weapons base'
SWEP.Spawnable = false
SWEP.UseHands = true
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = 0
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = 'none'
SWEP.ShellType = '9mm'
SWEP.SafetyStanceSound = Sound('weapons/smg1/switch_single.wav')
local angle_zero = Angle()
local passiveHoldTypes = {
revolver = 'normal',
ar2 = 'passive',
smg = 'passive',
}
-- Thanks to octothorp team for this solution, which calculates the shot position
local defaultBulletPosAng = {
default = { Vector(7.7, 0.4, 3.95), Angle(-3, 5.5, 0) },
revolver = { Vector(7.7, 0.4, 3.95), Angle(-3, 5.5, 0) },
ar2 = { Vector(20, -0.8, 11.2), Angle(-9.5, 0, 0) },
smg = { Vector(14, -0.8, 6.8), Angle(-9.5, 0, 0) },
}
function SWEP:CalculatePassiveHoldType()
return passiveHoldTypes[self.HoldType] or 'normal'
end
function SWEP:SafetyStanceChanged(_, old, new)
self:GetOwner():EmitSound(self.SafetyStanceSound)
if new == true then
self:SetHoldType(self.PassiveHoldType or self:CalculatePassiveHoldType())
else
self:SetHoldType(self.HoldType)
end
end
function SWEP:SetupDataTables()
self:NetworkVar('Bool', 0, 'SafetyStance')
self:NetworkVar('Vector', 0, 'LocalMuzzlePos')
self:NetworkVar('Angle', 0, 'LocalMuzzleAng')
if SERVER then
self:NetworkVarNotify('SafetyStance', self.SafetyStanceChanged)
end
end
function SWEP:Initialize()
self:SetHoldType(self.HoldType)
local lpos, lang = unpack( defaultBulletPosAng[ self:GetHoldType() ] or defaultBulletPosAng.default )
self._sourceLocalMuzzlePos = self.ShootPos or lpos
self._sourceLocalMuzzleAng = self.ShootAng or lang
if CLIENT then return end
self:SetLocalMuzzlePos(self._sourceLocalMuzzlePos)
self:SetLocalMuzzleAng(self._sourceLocalMuzzleAng)
end
function SWEP:Deploy()
return true
end
function SWEP:Holster()
if SERVER then
self.Ironsighted = false
end
return true
end
function SWEP:OnRemove()
self:Holster()
end
function SWEP:Reload()
if not IsFirstTimePredicted() then return end
local owner = self:GetOwner()
if not IsValid(owner) then return end
if owner:KeyDown(IN_USE) then return end
if qwb.isPlayerRunning(owner) then return end
if not self:DefaultReload(ACT_VM_RELOAD) then return end
owner:SetAnimation(PLAYER_RELOAD)
if SERVER then
self.Ironsighted = false
net.Start('qwb.setIronsight')
net.WriteBool(self.Ironsighted)
net.Send(owner)
end
self:SetNextPrimaryFire(CurTime() + 2)
end
function SWEP:GetMuzzlePos()
local owner = self:GetOwner()
if not IsValid(owner) then return end
local att = owner:GetAttachment( owner:LookupAttachment('anim_attachment_rh') )
if not att then return end
local lpos, lang = self:GetLocalMuzzlePos(), self:GetLocalMuzzleAng()
local pos, ang = LocalToWorld(lpos, lang, att.Pos, att.Ang)
return pos, ang
end
function SWEP:GetBoneAng()
local ang = self:GetLocalMuzzleAng()
local sourceAng = self._sourceLocalMuzzleAng
local pitch = ang.p - sourceAng.p
return Angle(-pitch, 0, 0)
end
function SWEP:GetBulletSourcePos()
return self:GetMuzzlePos()
end
function SWEP:ShootBullet( src, dir, num_bullets, aimcone, tracer )
local bullet = {}
bullet.Num = num_bullets
bullet.Src = src
bullet.Dir = dir
bullet.Spread = Vector( aimcone, aimcone, 0 )
bullet.Tracer = tracer or 5
bullet.Force = 1
bullet.Damage = self.Primary.Damage
bullet.AmmoType = self.Primary.Ammo
bullet.TracerName = self.TracerName
self:GetOwner():FireBullets( bullet )
self:TakePrimaryAmmo(1)
self:ShootEffects()
end
function SWEP:MuzzleFlashCustom()
if SERVER then
net.Start('qwb.muzzleFlashLight')
net.WriteEntity(self)
net.SendPVS(self:GetBulletSourcePos())
return
end
local effectData = EffectData()
effectData:SetEntity(self)
effectData:SetFlags(1)
util.Effect('MuzzleFlash', effectData)
end
function SWEP:ShellEffect()
if SERVER then return end
if self.NoShell then return end
local shellType = self.ShellType
local effectData = EffectData()
local pos = self:GetPos()
if self.ShellOffset then
local att = self:GetAttachment( self:LookupAttachment('muzzle') )
if att then
pos = LocalToWorld(self.ShellOffset, angle_zero, att.Pos, att.Ang)
end
end
effectData:SetOrigin(pos)
effectData:SetFlags(self.ShellVelocity or 75)
util.Effect('EjectBrass_' .. shellType, effectData)
end
function SWEP:ShootEffects()
self:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
self:MuzzleFlashCustom()
self:ShellEffect()
self:EmitSound( self.Primary.Sound )
self.RecoilAnimBack = nil
self.RecoilAnim = true
end
function SWEP:PrimaryAttack()
if not self:CanPrimaryAttack() then return end
if not IsValid(self) or not IsValid(self:GetOwner()) then return end
local owner = self:GetOwner()
local pos, ang = self:GetBulletSourcePos()
if not pos or not ang then return end
local forward = ang:Forward()
owner:LagCompensation(true)
self:ShootBullet(pos, forward, self.Primary.NumShots or 1, 0, 1) -- pre-last self.Primary.Spread or 0.01
owner:LagCompensation(false)
self:SetNextPrimaryFire(CurTime() + self.Primary.Delay)
if SERVER then self:CreateShootRage() end
-- if not self.IronSighted and self.HipFireRecoil then
-- local pitch = math.random() >= 0.5 and -self.HipFireRecoil or self.HipFireRecoil
-- local yaw = math.random() >= 0.5 and -self.HipFireRecoil or self.HipFireRecoil
-- local roll = math.random() >= 0.5 and -self.HipFireRecoil or self.HipFireRecoil
-- owner:SetViewPunchAngles(Angle(pitch, yaw, roll))
-- end
if self.PostPrimaryAttack then self:PostPrimaryAttack() end
end
function SWEP:CanPrimaryAttack()
if self:GetSafetyStance() then return end
local owner = self:GetOwner()
if not IsValid(owner) then return end
if qwb.isPlayerRunning(owner) then return end
if self:Clip1() <= 0 then
self:EmitSound('weapons/clipempty_rifle.wav')
self:SetNextPrimaryFire(CurTime() + 0.7)
return false
end
if owner:WaterLevel() > 2 then return false end
return true
end
function SWEP:Think()
local owner = self:GetOwner()
if not IsValid(self:GetOwner()) then return end
if owner:KeyDown(IN_USE) and owner:KeyDown(IN_RELOAD) and (not self.SafetyStanceCD or CurTime() >= self.SafetyStanceCD) then
self.SafetyStanceCD = CurTime() + 0.4
self:SetSafetyStance( not self:GetSafetyStance() )
end
local passiveHoldType = self.PassiveHoldType or self:CalculatePassiveHoldType()
if qwb.isPlayerRunning(owner) and self:GetHoldType() ~= passiveHoldType then
self:SetHoldType(passiveHoldType)
if self.Ironsighted then self.Ironsighted = false end
elseif not qwb.isPlayerRunning(owner) and not self:GetSafetyStance() and self:GetHoldType() == passiveHoldType then
self:SetHoldType(self.HoldType)
end
if not self.ShootRageDelta then self.ShootRageDelta = 0 end
if self.ShootRage and self.ShootRage > 0 then
self.ShootRageDelta = self.ShootRageDelta + 0.2
self.ShootRage = self.ShootRage - 0.05
if self.ShootRage < 0 then self.ShootRage = 0 end
else
self.ShootRageDelta = 0
end
if self.RecoilAnim then
local bone = owner:LookupBone('ValveBiped.Bip01_R_Hand')
local bone2 = owner:LookupBone('ValveBiped.Bip01_R_UpperArm')
local needle = Angle(self.Recoil / 50 * 90, 0, 0)
local needle2 = Angle(0, (self.ShootRage or 0) * math.sin(self.ShootRageDelta or 0), 0)
owner:ManipulateBoneAngles( bone, LerpAngle(0.8, owner:GetManipulateBoneAngles(bone), needle), true )
owner:ManipulateBoneAngles( bone2, LerpAngle(0.45, owner:GetManipulateBoneAngles(bone2), needle2), true )
local ang = owner:GetManipulateBoneAngles(bone)
if math.abs(ang[1] - needle[1]) <= 0.1 then
self.RecoilAnim = nil
self.RecoilAnimBack = true
end
elseif self.RecoilAnimBack then
local bone = owner:LookupBone('ValveBiped.Bip01_R_Hand')
local bone2 = owner:LookupBone('ValveBiped.Bip01_R_UpperArm')
local needle = Angle(0, 0, 0)
local needle2 = Angle(0, (self.ShootRage or 0) * math.sin(self.ShootRageDelta or 0), 0)
owner:ManipulateBoneAngles( bone, LerpAngle(0.1, owner:GetManipulateBoneAngles(bone), needle), true )
owner:ManipulateBoneAngles( bone2, LerpAngle(0.1, owner:GetManipulateBoneAngles(bone2), needle2), true )
local ang = owner:GetManipulateBoneAngles(bone)
if math.abs(ang[1] - needle[1]) <= 0.1 then
self.RecoilAnimBack = nil
end
end
-- if CLIENT then
-- local bone = owner:LookupBone('ValveBiped.Bip01_R_Hand')
-- local ang = self:GetBoneAng()
-- owner:ManipulateBoneAngles(bone, ang)
-- end
-- if CLIENT then return end
-- if owner.RecoilAnim then
-- local curAng = self:GetLocalMuzzleAng()
-- local sourceAng = self._sourceLocalMuzzleAng
-- local needle = Angle(sourceAng[1] - (self.Recoil / 50 * 90), curAng[2], curAng[3])
-- self:SetLocalMuzzleAng( LerpAngle(0.8, self:GetLocalMuzzleAng(), needle) )
-- local ang = self:GetLocalMuzzleAng()
-- if math.abs(ang[1] - needle[1]) <= 0.1 then
-- owner.RecoilAnim = nil
-- owner.RecoilAnimBack = true
-- end
-- elseif owner.RecoilAnimBack then
-- local needle = self._sourceLocalMuzzleAng
-- self:SetLocalMuzzleAng( LerpAngle(0.025, self:GetLocalMuzzleAng(), needle) )
-- local ang = self:GetLocalMuzzleAng()
-- if math.abs(ang[1] - needle[1]) <= 0.1 then
-- owner.RecoilAnimBack = nil
-- end
-- end
end

View File

@@ -0,0 +1,52 @@
function SWEP:CanAttach(attachType, attachID)
return true
end
function SWEP:SetAttach(attachType, attachID)
if not self.Attachments[attachType] or not self.Attachments[attachType][attachID] then return end
self._attachments = self._attachments or {}
if self._attachments[attachType] == attachID then return end
if not self:CanAttach(attachType, attachID) then return end
self._attachments[attachType] = attachID
net.Start('qwb.setAttachment')
net.WriteEntity(self)
net.WriteString(attachType)
net.WriteString(attachID)
net.Broadcast()
end
function SWEP:RemoveAttach(attachType)
if not self._attachments then return end
if not self._attachments[attachType] then return end
self._attachments[attachType] = nil
net.Start('qwb.removeAttachment')
net.WriteEntity(self)
net.WriteString(attachType)
net.Broadcast()
end
net.Receive('qwb.setAttachment', function(_, ply)
local weap = ply:GetActiveWeapon()
if not IsValid(weap) or not weap.IsQWB or not weap.SetAttach then return end
local attachType, attachID = net.ReadString(), net.ReadString()
if not attachType or not attachID then return end
weap:SetAttach(attachType, attachID)
end)
net.Receive('qwb.removeAttachment', function(_, ply)
local weap = ply:GetActiveWeapon()
if not IsValid(weap) or not weap.IsQWB or not weap.RemoveAttach then return end
local attachType = net.ReadString()
if not attachType then return end
weap:RemoveAttach(attachType)
end)