Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ForceSequence - Add 'loop', 'speed' arguments + Fix animation speed bug #431

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 50 additions & 1 deletion gamemode/core/hooks/sh_hooks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,55 @@ function GM:TranslateActivity(client, act)
end
end

function GM:UpdateAnimation(client, velocity, maxSeqGroundSpeed)
if (client:GetNetVar("forcedSequence")) then
client:SetPlaybackRate(client:GetNetVar("sequenceSpeed", 1))
else
local len = velocity:Length()
local movement = 1.0

if (len > 0.2) then
movement = (len / maxSeqGroundSpeed)
end

local rate = math.min(movement, 2)

-- if we're under water we want to constantly be swimming..
if (client:WaterLevel() >= 2) then
rate = math.max(rate, 0.5)
elseif (!client:IsOnGround() && len >= 1000) then
rate = 0.1
end

client:SetPlaybackRate(rate)
end

-- We only need to do this clientside..
if (CLIENT) then
if (client:InVehicle()) then
--
-- This is used for the 'rollercoaster' arms
--
local Vehicle = client:GetVehicle()
local Velocity = Vehicle:GetVelocity()
local fwd = Vehicle:GetUp()
local dp = fwd:Dot(Vector(0, 0, 1))

client:SetPoseParameter("vertical_velocity", (dp < 0 && dp || 0) + fwd:Dot(Velocity) * 0.005)

-- Pass the vehicles steer param down to the player
local steer = Vehicle:GetPoseParameter("vehicle_steer")
steer = steer * 2 - 1 -- convert from 0..1 to -1..1
if (Vehicle:GetClass() == "prop_vehicle_prisoner_pod") then steer = 0 client:SetPoseParameter("aim_yaw", math.NormalizeAngle(client:GetAimVector():Angle().y - Vehicle:GetAngles().y - 90)) end
client:SetPoseParameter("vehicle_steer", steer)

end

GAMEMODE:GrabEarAnimation(client)
GAMEMODE:MouthMoveAnimation(client)
end
end

function GM:CanPlayerUseBusiness(client, uniqueID)
local itemTable = ix.item.list[uniqueID]

Expand Down Expand Up @@ -334,7 +383,7 @@ do
local forcedSequence = client:GetNetVar("forcedSequence")

if (forcedSequence) then
if (client:GetSequence() != forcedSequence) then
if (client:GetSequence() != forcedSequence or (client:GetCycle() == 1 and client:GetNetVar("sequenceLoop"))) then
client:SetCycle(0)
end

Expand Down
14 changes: 11 additions & 3 deletions gamemode/core/libs/sh_anims.lua
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,13 @@ if (SERVER) then
-- fails to play
-- @number[opt=nil] time How long to play the animation for. This defaults to the duration of the animation
-- @bool[opt=false] bNoFreeze Whether or not to avoid freezing this player in place while the animation is playing
-- @bool[opt=false] loop Whether or not to have the animation loop. This does nothing if time is not set to greater than the duration of the animation
-- @number[opt=1] speed The speed at which the animation should play
-- @see LeaveSequence
function playerMeta:ForceSequence(sequence, callback, time, bNoFreeze)
hook.Run("PlayerEnterSequence", self, sequence, callback, time, bNoFreeze)
function playerMeta:ForceSequence(sequence, callback, time, bNoFreeze, loop, speed)
speed = speed or 1

hook.Run("PlayerEnterSequence", self, sequence, callback, time, bNoFreeze, loop, speed)

if (!sequence) then
net.Start("ixSequenceReset")
Expand All @@ -434,13 +438,15 @@ if (SERVER) then
sequence = self:LookupSequence(tostring(sequence))

if (sequence and sequence > 0) then
time = time or self:SequenceDuration(sequence)
time = time or (self:SequenceDuration(sequence) * (1/speed))

self.ixCouldShoot = self:GetNetVar("canShoot", false)
self.ixSeqCallback = callback
self:SetCycle(0)
self:SetPlaybackRate(1)
self:SetNetVar("forcedSequence", sequence)
self:SetNetVar("sequenceLoop", loop)
self:SetNetVar("sequenceSpeed", speed)
self:SetNetVar("canShoot", false)

if (!bNoFreeze) then
Expand Down Expand Up @@ -478,6 +484,8 @@ if (SERVER) then

self:SetNetVar("canShoot", self.ixCouldShoot)
self:SetNetVar("forcedSequence", nil)
self:SetNetVar("sequenceLoop", nil)
self:SetNetVar("sequenceSpeed", nil)
self:SetMoveType(MOVETYPE_WALK)
self.ixCouldShoot = nil

Expand Down