AddCSLuaFile() SWEP.Base = "weapon_base" SWEP.BennyItemHandler = true SWEP.ViewModel = "models/weapons/c_pistol.mdl" 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() self:NetworkVar( "Entity", "ActiveR" ) self:NetworkVar( "Entity", "ActiveL" ) self:NetworkVar( "Entity", "DesireR" ) self:NetworkVar( "Entity", "DesireL" ) 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() tracedef.endpos = p:EyePos() + (p:GetAimVector() * 90) local trace = util.TraceHull(tracedef) --print(trace.StartPos:Distance(trace.HitPos)) p:LagCompensation( false ) return trace end function SWEP:SetActive( ent ) local p = self:GetOwner() if ent:GetOwner() != p then return false end --if self:GetActiveR():IsValid() then self:Deactive() end self:SetActiveR( ent ) if self:ItemR() then self:ItemR( "Deploy" ) self:ItemR():SetNoDraw( false ) end 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() if self:ItemR() then self:ItemR("AttackAlt") 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() ) print("[prediction] cl prediction start:", ent) else print("[prediction] cl tried to predict invalid ent") end end) end function SWEP:EquipItem( ent ) local p = self:GetOwner() if CLIENT then print("FUCK OFF") debug.Trace() return end if IsValid(ent) and ent.BennyItem then if ent:GetOwner() != NULL then print( "[equip]", ent, "belongs to", ent:GetOwner(), "not equipping" ) return elseif p:GetInventory()[ent] then print( "[equip]", ent, "already belongs to", p ) return end print("[equip]", ent) self:SetDesireR( ent ) ent:AddEFlags( EFL_KEEP_ON_RECREATE_ENTITIES ) ent:AddEffects( EF_BONEMERGE ) ent:PhysicsInit( SOLID_NONE ) ent:SetMoveType( MOVETYPE_NONE ) ent:SetNoDraw( true ) ent:SetParent( p ) ent:SetOwner( p ) ent:SetLocalPos( vector_origin ) ent:SetLocalAngles( angle_zero ) ent:SetAcquisition( CurTime() ) ent:EmitSound( "ae/items/pickup.ogg", 70, 100, 1, CHAN_STATIC ) --self:SetActive( ent ) 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 if CLIENT then print("[drop] DropItem called on cl not allowed") return end self:SetDesireR( NULL ) ent:SetParent( NULL ) ent:SetOwner( NULL ) ent:RemoveEFlags( EFL_KEEP_ON_RECREATE_ENTITIES ) ent:RemoveEffects( EF_BONEMERGE ) ent:PhysicsInit( SOLID_VPHYSICS ) ent:SetMoveType( MOVETYPE_VPHYSICS ) ent:SetCollisionGroup( COLLISION_GROUP_PROJECTILE ) ent:SetNoDraw( false ) 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() ep:SetVelocity( p:GetAimVector() * 800 ) ep:SetAngleVelocity( Vector( 0, -360*3, 0 ) ) ep:Wake() --net.Start("AEINV_PredictItem") -- net.WriteEntity( ent ) -- net.WriteBool( false ) --net.Send( p ) end end function SWEP:Think() local p = self:GetOwner() if p:IsValid() then local DesireR = self:GetDesireR() local ActiveR = self:GetActiveR() local DesireR_Valid = DesireR:IsValid() local ActiveR_Valid = ActiveR:IsValid() if DesireR != ActiveR then if ActiveR_Valid then if ActiveR:GetHolsterIn() == 0 then ActiveR.Class.Holster( ActiveR.Class, ActiveR, self ) else -- Waiting for holster to finish end else if DesireR_Valid then self:SetActive( DesireR ) end end else if ActiveR_Valid and ActiveR:GetHolsterIn() != 0 then ActiveR.Class.UndoHolster( ActiveR.Class, ActiveR, self ) end end if p:KeyPressed(IN_WEAPON1) then if self:GetDesireR() == NULL then if SERVER then local trace = self:ItemCheckTrace() self:EquipItem( trace.Entity ) end else if self:GetActiveR() != NULL then ActiveR.Class.Drop( ActiveR.Class, ActiveR, self ) if SERVER then self:DropItem() end self:SetActiveR( NULL ) 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 if self:ItemR() then self:ItemR("Think") end else print( self, "Thinking without an owner." ) end end function SWEP:Deploy() end function SWEP:Holster( ent ) return false end