Custom Animations

From GMod Wiki

Jump to: navigation, search
Mess.pngThis page has been deemed a mess. It may contain unnecessary information or be poorly organized. You can discuss changes on this article's talk page.

Misc: Custom Animations

Yarin Kaul Icon Lua48.png
Description:Custom Player animations for a gamemode
Original Author(s):Mr. TBD

I'm going to teach you how to get an Ichthyosaur player model to animate properly.

We will be using the following Lua Files: act.lua

player.lua

located in:

garrysmod\lua\includes\enum
gamemodes\(name of gamemode)\gamemode

act.lua

After ACT_MP_ATTACK_SWIM_GRENADE_MELEE = 1109 Add:

 
ACT_ICH_BITE_MISS 				= 1110
ACT_ICH_SWIM				= 1111
ACT_ICH_THRASH				= 1112
ACT_ICH_BITE_HIT			= 1113
 

player.lua

 
 
 
local AnimTranslateTable = {}
AnimTranslateTable[ PLAYER_JUMP  ] 	= ACT_ICH_BITE_MISS 
AnimTranslateTable[ PLAYER_ATTACK1 ] 	= ACT_ICH_THRASH	
 
 
/*---------------------------------------------------------
   Name: gamemode:SetPlayerAnimation( )
   Desc: Sets a player's animation
---------------------------------------------------------*/
function GM:SetPlayerAnimation( pl, anim )
 
	local act = ACT_ICH_SWIM
	local Speed = pl:GetVelocity():Length()
        local OnGround = pl:OnGround()
 
 
	// If it's in the translate table then just straight translate it
	if ( AnimTranslateTable[ anim ] != nil ) then
 
		act = AnimTranslateTable[ anim ]
 
 
	else
 
		// Jump
		if ( OnGround ) then
 
		act = ACT_ICH_BITE_MISS
 
		end
 
	end
 
 // Attacking/Reloading is handled by the RestartGesture function
	if ( act == ACT_ICH_THRASH) then
 
		pl:RestartGesture( pl:Weapon_TranslateActivity( act ) )
 
		// If this was an attack send the anim to the weapon model
		if (act == ACT_ICH_THRASH) then
 
			pl:Weapon_SetActivity( pl:Weapon_TranslateActivity( ACT_ICH_BITE_HIT1 ), 0 );
 
		end
 
	return end
 
	// Always play the jump anim if we're in the air
	if ( !OnGround ) then
 
		act = ACT_ICH_BITE_MISS
 
	end
 
// Don't keep switching sequences if we're already playing the one we want.
	if (pl:GetSequence() == seq) then return end
 
	// Set and reset the sequence
	pl:SetPlaybackRate( 1.0 )
	pl:ResetSequence( seq )
	pl:SetCycle( 0 )
 
end
 

Notice: The Player model must be changed to the Ichthyosaur in the gamemode. For best results create a weapon for the Ichthyosaur player to use and Precache the following sounds: "NPC_Ichthyosaur.Bite" "NPC_Ichthyosaur.BiteMiss" "NPC_Ichthyosaur.AttackGrowl"

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox