Hello All,
I've recently thought about adding some custom animations to my gamemode I've been working on. It's turned out to be a bit harder than I expected. Currently I'm using this snippet of code to initiate animations:
[CODE]hook.Add("CalcMainActivity", "animations", function(ply, velocity)
if velocity:Length2D() > 325 then
ply:AnimRestartGesture(GESTURE_SLOT_ATTACK_AND_RELOAD, ACT_MP_SPRINT, true)
end
end)
[/CODE]
I'm currently trying to change the run animation into a slightly better suited sprint animation. It doesn't seem to work for whatever reason. It's been hit and miss with other animations I've been testing. I'm wondering what I may be doing wrong or if there's a better way about doing what I said.
Thanks!
return true or false ( I don't remember which ) to supress the default action. Right now what happens is that your console is being executed, and then the default base gamemode hook is called overriding your stuff.
[QUOTE=Robotboy655;45613022]return true or false ( I don't remember which ) to supress the default action. Right now what happens is that your console is being executed, and then the default base gamemode hook is called overriding your stuff.[/QUOTE]
Thank you!
I returned true and it seems to work, however my character model goes into a no animation "T" pose when it's called. I'm not sure whether I called it incorrectly or it just doesn't have a "ACT_MP_SPRINT" animation.
[CODE]hook.Add("CalcMainActivity", "animations", function(ply, velocity)
if velocity:Length2D() > 325 then
ply:AnimRestartGesture(GESTURE_SLOT_ATTACK_AND_RELOAD, ACT_MP_SPRINT, true)
return true
end
end)[/CODE]
Try using the following instead of ply.AnimRestartGesture
[lua]ply.CalcIdeal = ACT_MP_SPRINT[/lua]
[QUOTE=samm5506;45613407]Try using the following instead of ply.AnimRestartGesture
[lua]ply.CalcIdeal = ACT_MP_SPRINT[/lua][/QUOTE]
No luck unfortunately, thanks though!
[CODE]hook.Add("CalcMainActivity", "animations", function(ply, velocity)
if velocity:Length2D() > 330 then
ply.CalcIdeal = ACT_MP_SPRINT
return true
end
end)[/CODE]
You might want to try completely overriding the function by [URL="https://github.com/garrynewman/garrysmod/blob/8bbd0baf143c884afe97ed1abe8550e7d644ab70/garrysmod/gamemodes/base/gamemode/animations.lua#L279"]copying and pasting the code from gmod[/URL]. At least until you can get it working. Setting the ply.CalcIdeal property should work. Maybe you have to return that instead of true? Not sure.
[QUOTE=samm5506;45613460]You might want to try completely overriding the function by [URL="https://github.com/garrynewman/garrysmod/blob/8bbd0baf143c884afe97ed1abe8550e7d644ab70/garrysmod/gamemodes/base/gamemode/animations.lua#L279"]copying and pasting the code from gmod[/URL]. At least until you can get it working. Setting the ply.CalcIdeal property should work. Maybe you have to return that instead of true? Not sure.[/QUOTE]
I completely overrode it. However the "T" pose keeps happening. I'm starting to think that something is wrong with the "ACT_MP_SPRINT" animation and quite a few others for that matter...
[CODE]function GM:CalcMainActivity( ply, velocity )
ply.CalcIdeal = ACT_MP_STAND_IDLE
ply.CalcSeqOverride = -1
self:HandlePlayerLanding( ply, velocity, ply.m_bWasOnGround );
if ( self:HandlePlayerNoClipping( ply, velocity ) ||
self:HandlePlayerDriving( ply ) ||
self:HandlePlayerVaulting( ply, velocity ) ||
self:HandlePlayerJumping( ply, velocity ) ||
self:HandlePlayerDucking( ply, velocity ) ||
self:HandlePlayerSwimming( ply, velocity ) ) then
else
local len2d = velocity:Length2D()
if ( len2d > 150 ) then ply.CalcIdeal = ACT_MP_SPRINT elseif ( len2d > 0.5 ) then ply.CalcIdeal = ACT_MP_WALK end
end
ply.m_bWasOnGround = ply:IsOnGround()
ply.m_bWasNoclipping = ( ply:GetMoveType() == MOVETYPE_NOCLIP && !ply:InVehicle() )
return ply.CalcIdeal, ply.CalcSeqOverride
end[/CODE]
[editline]6th August 2014[/editline]
I figured it after some experimentation. I'm not sure why "ACT_MP_SPRINT" was in the wiki if it wasn't a valid animation. After some digging I found one that did what I wanted "ACT_HL2MP_RUN_FAST". It seems you have to return the animation you want, with "-1" as a second argument. I'm not sure as to why but it works as I needed.
[B]For the future curious:[/B]
[CODE]hook.Add("CalcMainActivity", "animations", function(ply, velocity)
if velocity:Length2D() > 326 then
return ACT_HL2MP_RUN_FAST, -1
end
end)[/CODE]
Also a list of valid animations I apparently misread/didn't understand: [URL="http://wiki.garrysmod.com/page/Player_animations"]http://wiki.garrysmod.com/page/Player_animations[/URL]
You can thank me later :wink:
Thanks to everyone who helped me out!
Many thanks for your answers. Including @LearningLua for an answer in my two threads.
Sorry, you need to Log In to post a reply to this thread.