aboutsummaryrefslogtreecommitdiff
path: root/entities/weapons
diff options
context:
space:
mode:
Diffstat (limited to 'entities/weapons')
-rw-r--r--entities/weapons/hands.lua52
1 files changed, 45 insertions, 7 deletions
diff --git a/entities/weapons/hands.lua b/entities/weapons/hands.lua
index 1354941..4220f5e 100644
--- a/entities/weapons/hands.lua
+++ b/entities/weapons/hands.lua
@@ -7,7 +7,7 @@ SWEP.HoldType = "normal"
SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = -1
-SWEP.Primary.Automatic = true
+SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = "none"
SWEP.Secondary.Clipsize = -1
@@ -32,6 +32,42 @@ function SWEP:Initialize()
]]
end
+SWEP.Pickup = nil
+SWEP.PickupAngles = Angle(0,0,0)
+SWEP.PickupOffset = 100
+function SWEP:DefaultPickup()
+ if self.Pickup == nil then
+ local tr = self.Owner:GetEyeTrace()
+ local dist = self.Owner:GetPos():Distance(tr.HitPos)
+ if dist < 100 and tr.Entity:GetMass() < 100 then
+ self.Pickup = tr.Entity
+ self.PickupAngles = tr.Entity:GetAngles()
+ self.PickupOffset = dist
+ end
+ else
+ self.Pickup = nil
+ end
+end
+
+function SWEP:Tick()
+ if self.Pickup ~= nil then
+
+ --Set position
+ local targetpos = (self.Owner:EyeAngles():Forward() * self.PickupOffset * 2) + self.Owner:GetPos() + Vector(0,0,64)
+ local deltavel = targetpos - (self.Pickup:GetPos() + self.Pickup:GetVelocity())
+ local clampvel = Vector(math.Clamp(deltavel.x,-100,100),math.Clamp(deltavel.y,-100,100),math.Clamp(deltavel.z,-100,100))
+ self.Pickup:GetPhysicsObject():SetVelocity(clampvel)
+
+ --Set angles
+ local targetang = self.Owner:EyeAngles() + self.PickupAngles
+ local angvel = self.Pickup:GetAngles() - targetang
+ local deltaang = self.Pickup:GetPhysicsObject():GetAngleVelocity() - angvel:Forward()
+ print("target",targetang,"vel",angvel,"delta",deltaang)
+ print("Cur is", self.Pickup:GetPhysicsObject():GetAngleVelocity())
+ self.Pickup:GetPhysicsObject():AddAngleVelocity(angvel:Forward())
+ end
+end
+
function SWEP:ShouldDropOnDie()
return false
end
@@ -48,10 +84,11 @@ function SWEP:PrimaryAttack()
--Get the weapon we want to fire, and fire it!
local weapon = eqpd:Get({"Left Hand"}) or eqpd:Get({"Dual"})
- if not weapon then return end --Make sure we have a weapon
- if weapon.onClick ~= nil then
+ if not weapon then
+ self:DefaultPickup()
+ elseif weapon.onClick ~= nil then
weapon:onClick(self.Owner)
- end
+ end --Make sure we have a weapon
end
function SWEP:SecondaryAttack()
@@ -66,8 +103,9 @@ function SWEP:SecondaryAttack()
--Get the weapon we want to fire, and fire it!
local weapon = eqpd:Get({"Right Hand"}) or eqpd:Get({"Dual"})
- if not weapon then return end --Make sure we have a weapon
- if weapon.onClick ~= nil then
+ if not weapon then
+ self:DefaultPickup()
+ elseif weapon.onClick ~= nil then
weapon:onClick(self.Owner)
- end
+ end --Make sure we have a weapon
end