From 454f358ec297a025867778550a1ad7e6b0ec6a44 Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Sun, 14 Jan 2018 15:40:59 -0500 Subject: Allow players to move props easier Added code to the hands weapons that allows players to move props easier --- entities/weapons/hands.lua | 75 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 61 insertions(+), 14 deletions(-) diff --git a/entities/weapons/hands.lua b/entities/weapons/hands.lua index 8d97ab7..7b5c042 100644 --- a/entities/weapons/hands.lua +++ b/entities/weapons/hands.lua @@ -35,34 +35,81 @@ end SWEP.Pickup = nil SWEP.PickupAngles = Angle(0,0,0) SWEP.PickupOffset = 100 + +local buildzones = { + ["artery_shipyard"] = true, +} function SWEP:DefaultPickup() + print("Default pickup fired, self.pickup is", self.Pickup) + local zc = self.Owner:GetCurrentZone() + local building = zc != nil and buildzones[zc] != nil 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 and tr.Entity:GetMass() < 100 then + local mass = -1 + pcall(function() + mass = tr.Entity:GetPhysicsObject():GetMass() + end,function() + print("Failed to get mass") + end) + + if building or (dist < 100 and mass != -1 and mass < 400) then + self.OldMass = mass self.Pickup = tr.Entity - self.PickupAngles = tr.Entity:GetAngles() + self.PickupAngles = tr.Entity:GetAngles() - self.Owner:EyeAngles() self.PickupOffset = dist + tr.Entity:GetPhysicsObject():SetMass(3) + tr.Entity:GetPhysicsObject():EnableCollisions(false) + else + print("dist is:" ,dist) + if tr.Entity.GetMass then + print("Mass is", tr.Entity:GetMass()) + else + print("Ent does not have mass!", mass) + end + print("Could not pick that up") end else + if IsValid(self.Pickup) and zc != nil and buildzones[zc.class] then + --self.Pickup:GetPhysicsObject():EnableMotion(false) + end + self.Pickup:GetPhysicsObject():SetMass(self.OldMass) + self.Pickup:GetPhysicsObject():EnableCollisions(true) 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 + if self.Pickup ~= nil and IsValid(self.Pickup) then + local crouchadd + if self.Owner:Crouching() then + crouchadd = Vector(0,0,32) + else + crouchadd = Vector(0,0,64) + end + local targetpos = (self.Owner:EyeAngles():Forward() * self.PickupOffset * 2) + self.Owner:GetPos() + crouchadd local targetang = self.Owner:EyeAngles() + self.PickupAngles - local angvel = self.Pickup:GetAngles() - targetang - local deltaang = self.Pickup:GetPhysicsObject():GetAngleVelocity() - angvel:Forward() - self.Pickup:GetPhysicsObject():AddAngleVelocity(angvel:Forward()) + --Check if we're inside a build zone + local zc = self.Owner:GetCurrentZone() + if zc != nil and zc.class == "artery_shipyard" then + self.Pickup:SetPos(targetpos) + self.Pickup:SetAngles(targetang) + else + + --Set position + local pow = 100 + local deltavel = targetpos - (self.Pickup:GetPos() + (self.Pickup:GetVelocity() / pow)) + local vlim = 100000 + local clampvel = Vector(math.Clamp(deltavel.x,-vlim,vlim),math.Clamp(deltavel.y,-vlim,vlim),math.Clamp(deltavel.z,-vlim,vlim)) + local speed = 20 + self.Pickup:GetPhysicsObject():SetVelocity(clampvel * speed) + + --Set angles + local angvel = self.Pickup:GetAngles() - targetang + local deltaang = self.Pickup:GetPhysicsObject():GetAngleVelocity() - angvel:Forward() + self.Pickup:SetAngles(targetang) + --self.Pickup:GetPhysicsObject():AddAngleVelocity(angvel:Forward()) + end end end -- cgit v1.2.3-70-g09d2