Skip to content

Commit

Permalink
Add Rappelling plugin (#101)
Browse files Browse the repository at this point in the history
* Add rappelling plugin

* Update public facing plugin info
  • Loading branch information
Miyoglow committed Mar 28, 2022
1 parent 7687855 commit 398ac77
Show file tree
Hide file tree
Showing 5 changed files with 264 additions and 0 deletions.
60 changes: 60 additions & 0 deletions rappelling/entities/weapons/rappel_gear.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@

local PLUGIN = PLUGIN

AddCSLuaFile()

if (CLIENT) then
SWEP.PrintName = "Rappel Gear"
SWEP.DrawAmmo = false
SWEP.DrawCrosshair = false
end

SWEP.Category = "HL2 RP"
SWEP.Author = "wowm0d"
SWEP.Instructions = "Primary Fire: Attach/Cut Rope"

SWEP.Spawnable = true
SWEP.AdminOnly = true

SWEP.ViewModelFOV = 45
SWEP.ViewModelFlip = false
SWEP.AnimPrefix = "rpg"

SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = -1
SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = ""

SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = 0
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = ""

SWEP.ViewModel = Model("models/weapons/c_arms_animations.mdl")
SWEP.WorldModel = ""

SWEP.UseHands = false

SWEP.IsAlwaysLowered = true
SWEP.FireWhenLowered = true
SWEP.HoldType = "passive"

function SWEP:Initialize()
self:SetHoldType(self.HoldType)
end

function SWEP:PrimaryAttack()
if (!IsFirstTimePredicted()) then return end

local owner = self:GetOwner()
if (!IsValid(owner) or owner:GetMoveType() == MOVETYPE_NOCLIP) then return end

if (owner.rappelling) then
PLUGIN:EndRappel(owner)
elseif (owner:OnGround()) then
PLUGIN:StartRappel(owner)
end
end

function SWEP:SecondaryAttack()
end
112 changes: 112 additions & 0 deletions rappelling/sh_hooks.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@

local PLUGIN = PLUGIN

function PLUGIN:PostPlayerDeath(client)
if (client.rappelling) then
self:EndRappel(client)
end
end

function PLUGIN:PlayerLoadout(client)
if (client.rappelling) then
self:EndRappel(client)
end
end

function PLUGIN:DoAnimationEvent(client)
if (client:GetNetVar("forcedSequence") == client:LookupSequence("rappelloop")) then
return ACT_INVALID
end
end

function PLUGIN:OnPlayerHitGround(client, inWater, onFloater, speed)
if (client.rappelling and client.rappelPos.z - client:GetPos().z > 64) then
self:EndRappel(client)

if (SERVER) then
client:EmitSound("npc/combine_soldier/zipline_hitground" .. math.random(2) .. ".wav")
end

if (speed >= 196) then
client:ViewPunch(Angle(7, 0, 0))
end
end
end

function PLUGIN:PlayerTick(client, moveData)
if (client:HasWeapon("rappel_gear")) then
local onGround = client:OnGround()

if (onGround and !client.wasOnGround) then
client.wasOnGround = true
elseif (!onGround and client.wasOnGround) then
client.wasOnGround = false

if (!client.rappelling and moveData:KeyDown(IN_WALK) and client:GetMoveType() != MOVETYPE_NOCLIP) then
self:StartRappel(client)
end
end
end
end

function PLUGIN:Move(client, moveData)
if (client.rappelling) then
local vel = moveData:GetVelocity()

local dir = (client.rappelPos - client:GetPos()) * 0.1

vel.x = (vel.x + dir.x) * 0.95
vel.y = (vel.y + dir.y) * 0.95

local rappelFalling = false

if (!client:OnGround() and (client:EyePos().z) < client.rappelPos.z) then
rappelFalling = true

if (moveData:KeyDown(IN_WALK)) then
moveData:SetForwardSpeed(0)
moveData:SetSideSpeed(0)

vel.z = math.max(vel.z - 16, -128)
else
vel.z = math.max(vel.z - 16, -512)
end
end

moveData:SetVelocity(vel)

if (rappelFalling) then
if (SERVER) then
local sequence = client:LookupSequence("rappelloop")

if (sequence != -1) then
client:SetNetVar("forcedSequence", sequence)
end

if (!client.oneTimeRappelSound) then
client.oneTimeRappelSound = true

client:EmitSound("npc/combine_soldier/zipline" .. math.random(2) .. ".wav")
end
end

if (client:WaterLevel() >= 1) then
self:EndRappel(client)
end
else
if (SERVER) then
local sequence = client:LookupSequence("rappelloop")

if (sequence != 1 and client:GetNetVar("forcedSequence") == sequence) then
client:SetNetVar("forcedSequence", nil)
end
end

local origin = moveData:GetOrigin()

if (math.Distance(origin.x, origin.y, client.rappelPos.x, client.rappelPos.y) > 256) then
self:EndRappel(client)
end
end
end
end
33 changes: 33 additions & 0 deletions rappelling/sh_plugin.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

local PLUGIN = PLUGIN

PLUGIN.name = "Rappelling"
PLUGIN.author = "wowm0d"
PLUGIN.description = "Adds rappelling gear into the Schema."
PLUGIN.schema = "HL2 RP"
PLUGIN.license = [[
Copyright 2022 wowm0d
This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
To view a copy of this license, visit http:https://creativecommons.org/licenses/by-nc-sa/4.0/.
]]

ix.util.Include("sv_plugin.lua")
ix.util.Include("sh_hooks.lua")
ix.util.Include("sv_hooks.lua")

function PLUGIN:StartRappel(client)
client.rappelling = true
client.rappelPos = client:GetPos()

if (SERVER) then
self:CreateRope(client)
end
end

function PLUGIN:EndRappel(client)
client.rappelling = nil

if (SERVER) then
self:RemoveRope(client)
end
end
8 changes: 8 additions & 0 deletions rappelling/sv_hooks.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

local PLUGIN = PLUGIN

function PLUGIN:OnPlayerObserve(client, state)
if (client.rappelling) then
self:EndRappel(client)
end
end
51 changes: 51 additions & 0 deletions rappelling/sv_plugin.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

local PLUGIN = PLUGIN

function PLUGIN:CreateRope(client)
local attachmentIndex

if (client.ixAnimModelClass == "metrocop") then
attachmentIndex = client:LookupAttachment("anim_attachment_LH")
else
attachmentIndex = client:LookupAttachment("hips")
end

local attachment = client:GetAttachment(attachmentIndex)

if (attachmentIndex == 0 or attachmentIndex == -1) then
attachment = {Pos = client:GetBonePosition(client:LookupBone("ValveBiped.Bip01_Pelvis"))}
attachmentIndex = client:LookupAttachment("forward")
end

local rappelRope = ents.Create("keyframe_rope")
rappelRope:SetParent(client, attachmentIndex)
rappelRope:SetPos(attachment and attachment.Pos or client:GetPos())
rappelRope:SetColor(Color(150, 150, 150))
rappelRope:SetEntity("StartEntity", rappelRope)
rappelRope:SetEntity("EndEntity", Entity(0))
rappelRope:SetKeyValue("Width", 2)
rappelRope:SetKeyValue("Collide", 1)
rappelRope:SetKeyValue("RopeMaterial", "cable/cable")
rappelRope:SetKeyValue("EndOffset", tostring(client.rappelPos or client:GetPos()))
rappelRope:SetKeyValue("EndBone", 0)
client.rappelRope = rappelRope

client:DeleteOnRemove(rappelRope)
client:EmitSound("npc/combine_soldier/zipline_clip" .. math.random(2) .. ".wav")

end

function PLUGIN:RemoveRope(client)
if (IsValid(client.rappelRope)) then
client.rappelRope:Remove()
end

client.rappelRope = nil
client.oneTimeRappelSound = nil

local sequence = client:LookupSequence("rappelloop")

if (sequence != 1 and client:GetNetVar("forcedSequence") == sequence) then
client:SetNetVar("forcedSequence", nil)
end
end

0 comments on commit 398ac77

Please sign in to comment.