2024-03-06 17:47:44 -05:00
|
|
|
|
|
|
|
AddCSLuaFile()
|
|
|
|
|
|
|
|
SWEP.Base = "weapon_base"
|
2024-03-07 22:34:29 -05:00
|
|
|
SWEP.BennyItemHandler = true
|
2024-03-06 17:47:44 -05:00
|
|
|
|
2024-09-17 17:46:44 -04:00
|
|
|
SWEP.ViewModel = "models/weapons/c_pistol.mdl"
|
2024-03-06 17:47:44 -05:00
|
|
|
SWEP.ViewModelFOV = 74
|
|
|
|
SWEP.ViewModelFlip = false
|
|
|
|
SWEP.UseHands = true
|
|
|
|
SWEP.WorldModel = "models/weapons/w_pistol.mdl"
|
|
|
|
SWEP.DrawWorldModel = true
|
|
|
|
|
|
|
|
|
|
|
|
SWEP.Primary.ClipSize = -1
|
|
|
|
SWEP.Primary.DefaultClip = 0
|
|
|
|
SWEP.Primary.Ammo = "none"
|
|
|
|
SWEP.Primary.Automatic = true
|
|
|
|
|
|
|
|
SWEP.Secondary.ClipSize = -1
|
|
|
|
SWEP.Secondary.DefaultClip = 0
|
|
|
|
SWEP.Secondary.Ammo = "none"
|
|
|
|
SWEP.Secondary.Automatic = true
|
|
|
|
|
|
|
|
function SWEP:SetupDataTables()
|
2024-09-20 16:20:22 -04:00
|
|
|
self:NetworkVar( "Entity", "ActiveR" )
|
|
|
|
self:NetworkVar( "Entity", "ActiveL" )
|
|
|
|
self:NetworkVar( "Entity", "DesireR" )
|
|
|
|
self:NetworkVar( "Entity", "DesireL" )
|
2024-03-06 17:47:44 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
function SWEP:ItemR( run )
|
|
|
|
local active = self:GetActiveR()
|
|
|
|
if run and active:IsValid() then
|
|
|
|
return active.Class[run]( active.Class, active, self )
|
|
|
|
else
|
|
|
|
return active:IsValid() and active or false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function SWEP:ItemL( run )
|
|
|
|
local active = self:GetActiveL()
|
|
|
|
if run and active:IsValid() then
|
|
|
|
active.Class[run]( active.Class, active, self )
|
|
|
|
else
|
|
|
|
return active:IsValid() and active or false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function SWEP:Initialize()
|
|
|
|
end
|
|
|
|
|
|
|
|
local size = 8/2
|
|
|
|
local tracedef = {
|
|
|
|
mins = Vector( -size, -size, -size ),
|
|
|
|
maxs = Vector( size, size, size ),
|
|
|
|
}
|
|
|
|
function SWEP:ItemCheckTrace()
|
|
|
|
local p = self:GetOwner()
|
|
|
|
p:LagCompensation( true )
|
|
|
|
tracedef.filter = p
|
|
|
|
tracedef.start = p:EyePos()
|
2024-04-06 09:30:09 -04:00
|
|
|
tracedef.endpos = p:EyePos() + (p:GetAimVector() * 90)
|
2024-03-06 17:47:44 -05:00
|
|
|
local trace = util.TraceHull(tracedef)
|
2024-04-06 09:30:09 -04:00
|
|
|
--print(trace.StartPos:Distance(trace.HitPos))
|
2024-08-30 18:30:03 -04:00
|
|
|
p:LagCompensation( false )
|
2024-03-06 17:47:44 -05:00
|
|
|
return trace
|
|
|
|
end
|
|
|
|
|
|
|
|
function SWEP:SetActive( ent )
|
|
|
|
local p = self:GetOwner()
|
|
|
|
if ent:GetOwner() != p then return false end
|
2024-09-21 14:08:48 -04:00
|
|
|
--if self:GetActiveR():IsValid() then self:Deactive() end
|
2024-03-06 17:47:44 -05:00
|
|
|
self:SetActiveR( ent )
|
2024-03-12 18:43:31 -04:00
|
|
|
if self:ItemR() then
|
|
|
|
self:ItemR( "Deploy" )
|
|
|
|
self:ItemR():SetNoDraw( false )
|
|
|
|
end
|
2024-03-06 17:47:44 -05:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function SWEP:Deactive()
|
|
|
|
end
|
|
|
|
|
|
|
|
function SWEP:PrimaryAttack()
|
|
|
|
local p = self:GetOwner()
|
|
|
|
if self:ItemR() then
|
|
|
|
self:ItemR("Attack")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function SWEP:Reload()
|
|
|
|
if self:ItemR() then
|
|
|
|
self:ItemR("Reload")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function SWEP:SecondaryAttack()
|
|
|
|
local p = self:GetOwner()
|
2024-04-06 09:30:09 -04:00
|
|
|
if self:ItemR() then
|
2024-04-07 19:04:18 -04:00
|
|
|
self:ItemR("AttackAlt")
|
2024-03-06 17:47:44 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if SERVER then
|
|
|
|
util.AddNetworkString("AEINV_PredictItem")
|
|
|
|
else
|
|
|
|
net.Receive("AEINV_PredictItem", function()
|
|
|
|
local ent = net.ReadEntity()
|
|
|
|
if ent:IsValid() then
|
|
|
|
ent:SetPredictable( net.ReadBool() )
|
2024-09-27 16:10:50 -04:00
|
|
|
print("[prediction] cl prediction start:", ent)
|
2024-03-06 17:47:44 -05:00
|
|
|
else
|
2024-09-27 16:10:50 -04:00
|
|
|
print("[prediction] cl tried to predict invalid ent")
|
2024-03-06 17:47:44 -05:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
|
|
|
function SWEP:EquipItem( ent )
|
|
|
|
local p = self:GetOwner()
|
|
|
|
if CLIENT then print("FUCK OFF") debug.Trace() return end
|
2024-03-07 22:34:29 -05:00
|
|
|
if IsValid(ent) and ent.BennyItem then
|
2024-03-06 17:47:44 -05:00
|
|
|
if ent:GetOwner() != NULL then
|
2024-09-27 16:10:50 -04:00
|
|
|
print( "[equip]", ent, "belongs to", ent:GetOwner(), "not equipping" )
|
2024-03-06 17:47:44 -05:00
|
|
|
return
|
2024-09-27 16:10:50 -04:00
|
|
|
elseif p:GetInventory()[ent] then
|
|
|
|
print( "[equip]", ent, "already belongs to", p )
|
2024-03-06 17:47:44 -05:00
|
|
|
return
|
|
|
|
end
|
2024-09-27 16:10:50 -04:00
|
|
|
print("[equip]", ent)
|
2024-03-06 17:47:44 -05:00
|
|
|
|
2024-09-20 16:20:22 -04:00
|
|
|
self:SetDesireR( ent )
|
|
|
|
|
2024-03-06 17:47:44 -05:00
|
|
|
ent:AddEFlags( EFL_KEEP_ON_RECREATE_ENTITIES )
|
2024-03-08 20:10:47 -05:00
|
|
|
ent:AddEffects( EF_BONEMERGE )
|
2024-03-25 00:48:36 -04:00
|
|
|
ent:PhysicsInit( SOLID_NONE )
|
2024-03-08 20:10:47 -05:00
|
|
|
ent:SetMoveType( MOVETYPE_NONE )
|
2024-03-12 18:43:31 -04:00
|
|
|
ent:SetNoDraw( true )
|
2024-03-06 17:47:44 -05:00
|
|
|
ent:SetParent( p )
|
|
|
|
ent:SetOwner( p )
|
2024-09-17 17:46:44 -04:00
|
|
|
ent:SetLocalPos( vector_origin )
|
|
|
|
ent:SetLocalAngles( angle_zero )
|
2024-03-06 17:47:44 -05:00
|
|
|
ent:SetAcquisition( CurTime() )
|
|
|
|
|
|
|
|
ent:EmitSound( "ae/items/pickup.ogg", 70, 100, 1, CHAN_STATIC )
|
|
|
|
|
2024-03-07 22:58:30 -05:00
|
|
|
--self:SetActive( ent )
|
2024-03-06 17:47:44 -05:00
|
|
|
local inv = p:GetInventory()
|
|
|
|
inv[ent] = true
|
|
|
|
inv:Sync()
|
|
|
|
|
|
|
|
net.Start("AEINV_PredictItem")
|
|
|
|
net.WriteEntity( ent )
|
|
|
|
net.WriteBool( true )
|
|
|
|
net.Send( p )
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function SWEP:DropItem()
|
|
|
|
local p = self:GetOwner()
|
|
|
|
local ent = self:GetActiveR()
|
|
|
|
if ent:IsValid() then
|
2024-09-27 16:10:50 -04:00
|
|
|
if CLIENT then print("[drop] DropItem called on cl not allowed") return end
|
2024-09-21 14:08:48 -04:00
|
|
|
|
2024-09-20 16:20:22 -04:00
|
|
|
self:SetDesireR( NULL )
|
|
|
|
|
2024-03-06 17:47:44 -05:00
|
|
|
ent:SetParent( NULL )
|
|
|
|
ent:SetOwner( NULL )
|
|
|
|
|
|
|
|
ent:RemoveEFlags( EFL_KEEP_ON_RECREATE_ENTITIES )
|
2024-03-08 20:10:47 -05:00
|
|
|
ent:RemoveEffects( EF_BONEMERGE )
|
2024-03-25 00:48:36 -04:00
|
|
|
ent:PhysicsInit( SOLID_VPHYSICS )
|
2024-03-08 20:10:47 -05:00
|
|
|
ent:SetMoveType( MOVETYPE_VPHYSICS )
|
2024-04-06 09:30:09 -04:00
|
|
|
ent:SetCollisionGroup( COLLISION_GROUP_PROJECTILE )
|
2024-03-12 18:43:31 -04:00
|
|
|
ent:SetNoDraw( false )
|
2024-03-07 22:34:29 -05:00
|
|
|
|
2024-03-06 17:47:44 -05:00
|
|
|
ent:SetPos( p:EyePos() + p:GetAimVector() * 0 )
|
|
|
|
ent:SetAngles( p:EyeAngles() + Angle( 0, 180, 0 ) )
|
|
|
|
|
|
|
|
|
|
|
|
local inv = p:GetInventory()
|
|
|
|
inv[ent] = nil
|
|
|
|
inv:Sync()
|
|
|
|
|
|
|
|
local ep = ent:GetPhysicsObject()
|
2024-04-06 09:30:09 -04:00
|
|
|
ep:SetVelocity( p:GetAimVector() * 800 )
|
|
|
|
ep:SetAngleVelocity( Vector( 0, -360*3, 0 ) )
|
2024-03-06 17:47:44 -05:00
|
|
|
ep:Wake()
|
2024-04-06 09:30:09 -04:00
|
|
|
--net.Start("AEINV_PredictItem")
|
|
|
|
-- net.WriteEntity( ent )
|
|
|
|
-- net.WriteBool( false )
|
|
|
|
--net.Send( p )
|
2024-03-06 17:47:44 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function SWEP:Think()
|
|
|
|
local p = self:GetOwner()
|
|
|
|
|
|
|
|
if p:IsValid() then
|
2024-09-20 16:20:22 -04:00
|
|
|
local DesireR = self:GetDesireR()
|
|
|
|
local ActiveR = self:GetActiveR()
|
|
|
|
local DesireR_Valid = DesireR:IsValid()
|
|
|
|
local ActiveR_Valid = ActiveR:IsValid()
|
|
|
|
|
2024-09-21 14:08:48 -04:00
|
|
|
if DesireR != ActiveR then
|
2024-09-20 16:20:22 -04:00
|
|
|
if ActiveR_Valid then
|
2024-09-21 14:08:48 -04:00
|
|
|
if ActiveR:GetHolsterIn() == 0 then
|
|
|
|
ActiveR.Class.Holster( ActiveR.Class, ActiveR, self )
|
|
|
|
else
|
2024-09-21 23:44:08 -04:00
|
|
|
-- Waiting for holster to finish
|
2024-09-21 14:08:48 -04:00
|
|
|
end
|
2024-09-20 16:20:22 -04:00
|
|
|
else
|
2024-09-21 14:08:48 -04:00
|
|
|
if DesireR_Valid then
|
|
|
|
self:SetActive( DesireR )
|
|
|
|
end
|
2024-09-20 16:20:22 -04:00
|
|
|
end
|
2024-09-21 14:08:48 -04:00
|
|
|
else
|
|
|
|
if ActiveR_Valid and ActiveR:GetHolsterIn() != 0 then
|
|
|
|
ActiveR.Class.UndoHolster( ActiveR.Class, ActiveR, self )
|
2024-09-20 16:20:22 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if p:KeyPressed(IN_WEAPON1) then
|
2024-09-21 16:55:44 -04:00
|
|
|
if self:GetDesireR() == NULL then
|
2024-09-21 14:08:48 -04:00
|
|
|
if SERVER then
|
2024-04-06 09:30:09 -04:00
|
|
|
local trace = self:ItemCheckTrace()
|
|
|
|
self:EquipItem( trace.Entity )
|
2024-09-21 14:08:48 -04:00
|
|
|
end
|
|
|
|
else
|
2024-09-21 16:55:44 -04:00
|
|
|
if self:GetActiveR() != NULL then
|
|
|
|
ActiveR.Class.Drop( ActiveR.Class, ActiveR, self )
|
|
|
|
if SERVER then
|
|
|
|
self:DropItem()
|
|
|
|
end
|
|
|
|
self:SetActiveR( NULL )
|
2024-04-06 09:30:09 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if p:KeyPressed(IN_WEAPON2) then
|
|
|
|
end
|
|
|
|
if p:KeyPressed(IN_ALT1) then
|
|
|
|
end
|
|
|
|
if p:KeyPressed(IN_ALT2) then
|
|
|
|
end
|
|
|
|
if p:KeyPressed(IN_GRENADE1) then
|
|
|
|
if self:ItemR() and self:ItemR().Class.Alt then
|
|
|
|
self:ItemR("Alt")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if p:KeyPressed(IN_GRENADE2) then
|
|
|
|
|
|
|
|
end
|
2024-03-06 17:47:44 -05:00
|
|
|
if self:ItemR() then
|
|
|
|
self:ItemR("Think")
|
|
|
|
end
|
|
|
|
else
|
|
|
|
print( self, "Thinking without an owner." )
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function SWEP:Deploy()
|
|
|
|
end
|
|
|
|
|
2024-09-20 16:20:22 -04:00
|
|
|
function SWEP:Holster( ent )
|
|
|
|
return false
|
2024-03-06 17:47:44 -05:00
|
|
|
end
|