Crayta lets you assign a ‘grip’ to a player. A grip defines the set of movement animations that this player will start using. For example, setting a player’s grip to Shotgun
will see the player run, jump, crouch, etc, as if they were holding a shotgun with both hands. Switching this to Melee
will switch these animation to a one-handed hold of a sword-like weapon. It is up to your game to attach shotguns/swords/whatever to your player’s hands in conjunction with setting the grip type.
Depending on the grip that has been assigned various actions can be played. For example, if the player is using the Shotgun
grip, they can do a Fire
or Reload
action. However, when using the Melee
grip, there is no such thing as a reload (you can’t reload a sword!), so that doesn’t have a Reload
action.
To trigger an action, for example a reload, just call self:GetEntity():PlayAction(“Reload”)
. PlayAction
takes an optional second parameter, which is a table of optional parameters for this animation.
Name | Type | Description |
---|---|---|
playbackSpeed | number | Sets the speed to play this animation at. 2 = double speed, 0.5 = half speed. Note: If playbackTime is also set, you’ll get a warning, and playbackTime will be preferred) |
playbackTime | number | Sets the time that this animation should take. 1 = 1 second, 10 = 10 seconds. Note: If playbackSpeed is also set, you’ll get a warning, and playbackTime will be preferred) |
events | Table of lua functions | Some actions trigger events – these are functions that will be triggered in your Lua code once the animation for an action reaches a certain point. An event can be either a standard event, or a branching event. A standard event expects your lua function to return nothing. A branching event expects your lua function to return a bool. Events can be omitted from this table, if a branching event is omitted, the default return value for this branching event will be used. See examples of events below. |
Grips, actions, and events
Grip Name: Carry
Actions
None
Grip Name: Cleaver
Actions
Melee
– This will perform a ‘chopping’ animation- Standard Events:
ChopImpact
– This will trigger at the point in the animation when the cleaver looks like it has hit the chopping surface
- Branching Events::
IsChopComplete
– Iffalse
, another chop will take place immediately without playing the intro of the animation again. If true, the chop animation will play its outro sequence and complete
- Standard Events:
Grip Name: Cuff
Actions
None
Grip Name: Unarmed
Actions
None
Grip Name: Knife
Actions
Melee
– This will perform a ‘slashing’ animation- Standard Events:
MeleeImpact
– This will trigger at the point in the animation when the knife looks like it should hit its target
- Standard Events:
Grip Name: Pistol
Actions
Fire
– This will perform a ‘shooting’ animationReload
– This will perform a ‘reload’ animation- Standard Events:
AmmoAdded
– This will trigger at the point in the animation when the pistol clip has been inserted into the pistol
- Standard Events:
Melee
– This will perform a ‘pistol whip’ animation- Standard Events:
MeleeImpact
– This will trigger at the point in the animation when the pistol looks like it should hit its target
- Standard Events:
Rifle
Actions
Fire
-This will perform a ‘shooting’ animationReload
– This will perform a ‘reload’ animation- Standard Events:
AmmoAdded
– This will trigger at the point in the animation when the clip has been inserted into the pistol
- Standard Events:
RPG
Actions
Fire
– This will perform a ‘rocket launch’ animationReload
– This will perform a ‘reload’ animation- Standard Events:
AmmoAdded
– This will trigger at the point in the animation when the rocket has been inserted into the RPG
- Standard Events:
Shotgun
Actions
Fire
-This will perform a ‘shooting’ animationReload
– This will perform a ‘reload’ animation- Standard Events:
AmmoAdded
– This will trigger at the point in the animation when a shell has been inserted into the shotgun
- Branching Events:
IsReloadComplete
– If false, another shell will be inserted into the barrel without playing the intro of the animation again. If true, the reload animation will play its outro sequence and complete
- Standard Events:
Example
Here’s an example of a reload action for a shotgun grip being performed at double speed, with the IsReloadComplete
and AmmoAdded
action events implemented. The reload animation will keep on playing until the number of self.bullets
reaches self.properties.maxBullets
local animData = {} animData.playbackSpeed = 2.0 animData.events = { IsReloadComplete = function () Print("Checking if full") return self.bullets == self.properties.maxBullets end, AmmoAdded = function () self.bullets = self.bullets + 1 Print("Added Bullets, current ammo = " .. self.bullets ) end } self:GetEntity():PlayAction("Reload", animData)
Global Events
OnCompleted
– This applies to all actions and will trigger once the animation for the action is no longer playing