Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- include("sh_grapple_config.lua")
- function ProjectVectorOnNormal(vec, norm)
- norm:Normalize()
- return vec:Dot(norm) * u
- end
- sound.Add( {
- name = "grapple_launch_loop",
- channel = CHAN_AUTO,
- volume = 1.0,
- level = 80,
- pitch = { 95, 110 },
- sound = "ambient/tones/steam_loop1.wav"
- } )
- function Grapple.CreateEntry(ply, dest)
- local ret = {Player = ply, Destination = dest, Points = {}}
- for i = 1, Grapple.Config.Resolution, 1 do
- ret.Points[i] = Vector(0,0,0)
- end
- return ret
- end
- function Grapple.MovePlayer(self)
- if (!self or self == NULL) then return end
- local ply = self:GetOwner()
- local dest = self:GetPos()
- local nrm = (dest - ply:EyePos())
- local dist = nrm:Length()
- if (dist > Grapple.Config.MaxDistance) then
- local nrmLen = dest - ply:GetPos()
- nrmLen:Normalize();
- ply:SetPos(dest - nrmLen * Grapple.Config.MaxDistance)
- end
- nrm = nrm / dist;
- //ply:SetVelocity(nrm * Grapple.Config.GrapplePower * 4)
- local vel = ply:GetVelocity()
- local mag = ply:GetVelocity():LengthSqr()
- if (mag > Grapple.Config.MaxGrappleVelocitySqr) then
- vel:Normalize()
- //ply:SetAbsVelocity(vel * Grapple.Config.MaxGrappleVelocity)
- end
- return nrm * Grapple.Config.GrapplePower, dist
- end
- hook.Add("PlayerSpawn", "zgrapplePlayerJump", function(ply)
- ply:SetJumpPower(1200)
- ply.OnWall = false
- ply.WallNrm = Vector(0,0,1)
- if (ply.CurrentGrapple) then
- ply.CurrentGrapple:Remove()
- end
- print(ply:GetJumpPower())
- end)
- hook.Add("Move", "grapplePlayerEarlyMove", function(ply, mv)
- ply.OnWall = ply.OnWall or false
- ply.WallNrm = ply.WallNrm or Vector(0,0,1)
- if (ply:IsOnGround()) then
- if (!ply.canGDoubleJump) then
- ply.canGDoubleJump = true
- end
- elseif (ply:KeyPressed(IN_JUMP)) then
- if (ply.OnWall) then
- ply.OnWall = false
- local vel = mv:GetVelocity()
- vel.x = ply.WallNrm.x * ply:GetJumpPower()
- vel.y = ply.WallNrm.y * ply:GetJumpPower()
- vel.z = vel.z + ply.WallNrm.z + ply:GetJumpPower()
- mv:SetVelocity(vel)
- elseif (ply.canGDoubleJump) then
- print("jump")
- local vel = mv:GetVelocity()
- vel.z = 0
- local eyeFwd = ply:GetAngles():Forward()
- vel.x = eyeFwd.x
- vel.y = eyeFwd.y
- vel = vel * mag
- vel.z = ply:GetJumpPower() * 0.75
- mv:SetVelocity(vel)
- ply.canGDoubleJump = false
- end
- else
- //for i = 1, 8, 1 do
- local nrmVel = mv:GetVelocity()
- nrmVel:Normalize()
- local tr = nil
- if (ply.OnWall) then
- tr = util.TraceLine({start = mv:GetOrigin(), endpos = mv:GetOrigin() + -ply.WallNrm * 100, mask = MASK_SOLID_BRUSHONLY})
- else
- tr = util.TraceLine({start = mv:GetOrigin(), endpos = mv:GetOrigin() + nrmVel * 100, mask = MASK_SOLID_BRUSHONLY})
- end
- if (tr.Hit and math.abs(tr.HitNormal.z) < 0.1) then
- ply.OnWall = true
- ply.WallNrm = tr.HitNormal
- end
- //end
- end
- end)
- hook.Add("FinishMove", "zgrapplePlayerMove", function(ply, mv)
- /*if (ply:KeyDown(IN_JUMP)) then
- local vel = mv:GetVelocity()
- //vel.z = vel.z + 7
- if (vel.z < 0) then
- vel.z = vel.z / 1.1
- end
- //vel.z = math.max(vel.z, -0.2)
- mv:SetVelocity(vel)
- end*/
- if (ply.OnWall) then
- print("running")
- local temp = mv:GetVelocity()
- temp.z = temp.z + 8
- mv:SetVelocity(temp)
- end
- if (ply.CurrentGrapple and IsValid(ply.CurrentGrapple) and ply.CurrentGrapple:GetState() >= 3) then
- //print(Grapple.MovePlayer(ply.CurrentGrapple))
- // TODO: add max length
- local move, dist = Grapple.MovePlayer(ply.CurrentGrapple)
- if (!move) then
- ply.CurrentGrapple = nil
- return
- end
- local nrmmove = Vector(move.x, move.y, move.z)
- nrmmove:Normalize()
- local mult = (math.Clamp(-ply:EyeAngles():Forward():Dot(nrmmove), 0, 1) + 1)
- //print(mult)
- local tg = mv:GetVelocity() + move / 4 * mult
- local len = tg:LengthSqr()
- if (dist < 50) then
- tg = tg / 1.2
- else
- tg = tg - Vector(0,0,1)
- if (len > Grapple.Config.MaxGrappleVelocitySqr) then
- tg = tg / math.sqrt(len) * Grapple.Config.MaxGrappleVelocity
- end
- end
- mv:SetVelocity(tg)
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement