I want to set a player to run the ACT_HL2MP_SIT_FIST animation until I tell them not to, for a vehicle seating addon.
However, using ply:SetAnimation, they do it for 0.1s and then stand up again.
Any help?
From base/gamemode/animations.lua:
[lua]function GM:HandlePlayerDriving( ply )
if ply:InVehicle() then
local pVehicle = ply:GetVehicle()
if ( pVehicle.HandleAnimation != nil ) then
local seq = pVehicle:HandleAnimation( ply )
if ( seq != nil ) then
ply.CalcSeqOverride = seq
return true
end
else
local class = pVehicle:GetClass()
if ( class == "prop_vehicle_jeep" ) then
ply.CalcSeqOverride = ply:LookupSequence( "drive_jeep" )
elseif ( class == "prop_vehicle_airboat" ) then
ply.CalcSeqOverride = ply:LookupSequence( "drive_airboat" )
elseif ( class == "prop_vehicle_prisoner_pod" && pVehicle:GetModel() == "models/vehicles/prisoner_pod_inner.mdl" ) then
// HACK!!
ply.CalcSeqOverride = ply:LookupSequence( "drive_pd" )
else
ply.CalcSeqOverride = ply:LookupSequence( "sit_rollercoaster" )
end
return true
end
end
return false
end[/lua]
So apparently, if you are using a vehicle entity for your seating addon, all you’ll have to do is add a shared function “HandleAnimation” to your vehicle which returns a sequence ID.
If you need to get a sequence ID from an activity ID, use Entity:SelectWeightedSequence.
If you’re not using a vehicle entity, you can always do this:
[lua]hook.Add(“CalcMainActivity”, “SeatActivityOverride”, function(ply, velocity)
if ply:GetNWBool(“ShouldDoSeatingAnim”) then
ply.CalcIdeal = ACT_HL2MP_SIT_FIST
ply.CalcSeqOverride = -1 – set that to something else than -1 if you want to play a sequence rather than an activity
return ply.CalcIdeal, ply.CalcSeqOverride
end
end)[/lua]
Also, keep in mind that all player animation hooks are now shared.
Thanks, that worked great. A shame what I was trying to do with it didn’t.