• How do I change the player animation to swimming?
    6 replies, posted
I wanted to change the player animation to swimming when I do a command and then to the normal walking animation when the player hits the ground. Is there any way to do that? If there is, how do I change it to the swimming animations and how do I change it back to the walkin animation? Thanks! [editline]27th April 2014[/editline] I'm pretty sure I have to use ply:SetSequence(idle) for the normal walking but idk what to put in the "idle" thing for swimming.
Just modify this function: [code] function GM:HandlePlayerSwimming( ply, velocity ) if ( ply:WaterLevel() < 2 or ply:IsOnGround() ) then ply.m_bInSwim = false return false end ply.CalcIdeal = ACT_MP_SWIM ply.m_bInSwim = true return true end [/code] This needs to be shared, and loaded [u]after[/u] the base gamemode.
[QUOTE=dingusnin;44656869]Just modify this function: [code] function GM:HandlePlayerSwimming( ply, velocity ) if ( ply:WaterLevel() < 2 or ply:IsOnGround() ) then ply.m_bInSwim = false return false end ply.CalcIdeal = ACT_MP_SWIM ply.m_bInSwim = true return true end [/code] This needs to be shared, and loaded [u]after[/u] the base gamemode.[/QUOTE] Isn't there a way to do that with ply:SetSequence()? I tried ply:SetSequence(ACT_MP_SWIM) but nothing happens. I mean, the thing that I want to do should work with sandbox.
[QUOTE=shadowsaints;44659603]Isn't there a way to do that with ply:SetSequence()? I tried ply:SetSequence(ACT_MP_SWIM) but nothing happens. I mean, the thing that I want to do should work with sandbox.[/QUOTE] No, those hooks will constantly override the animations for the player. You can try hooking onto [url]http://wiki.garrysmod.com/page/GM/UpdateAnimation[/url] and doing some stuff in it, you can find source for the hook in base/gamemode/animations.lua.
[QUOTE=Robotboy655;44659733]No, those hooks will constantly override the animations for the player. You can try hooking onto [url]http://wiki.garrysmod.com/page/GM/UpdateAnimation[/url] and doing some stuff in it, you can find source for the hook in base/gamemode/animations.lua.[/QUOTE] Thank you a lot! Now it works!
Shit, this doesn't work, I thought it was working. But it actually wasnt. Any ideas? [editline]30th April 2014[/editline] I tried to do this: [CODE]hook.Add("UpdateAnimation", "FordodgeAnimation", function(ply) if ply.fordodge then ply:SetSequence("ACT_MP_SWIM") return true end end) hook.Add("SetPlayerAnimation", "FordodgeAnimation2", function(ply) if ply.fordodge then ply:SetSequence("ACT_MP_SWIM") return true end end) [/CODE] And then using ply:FordodgeAnimation when I pressed some keys but it said "attempt to call method 'ForodgeAnimation' (a nil value)", What should I do?
That error has nothing to do with this code. This won't work because 1) The model doesn't have sequences starting with ACT_. Don't confuse activities and sequences. 2) Look into source code of those hooks in base/gamemode/animations.lua for how you are supposed to set animations.
Sorry, you need to Log In to post a reply to this thread.