Animation Events
Animation Events are flags that are set during an animation, and triggers special logic on the game. Depraved Sense has its own way to simplify the use of them through its AnimEventManager module. Here you will learn how to create very basics Animation Events.
One important thing to keep note of, the animations events are separated into two parts, the Client side, and the Server side.
Client events are only supposed to be used when it comes to user interface, sounds, or anything graphical on the user’s end. There are some exceptions to this rule of course, as zomboid has a weird netcode way of handling things, but for the most part keep Client for graphical logic.
Server events are used when you want to change something data related. Like changing the character’s data, calling functions of objects, and overall just making every logic possible. This is to make sure that things stay in SYNC with all Clients connected to the session.
There are three types of events to register. living, zombie, and character. living is for characters that are ‘alive’ in the game, meaning players, and animals. zombie is for… well, zombies. character is for events that will trigger for every character.
Here’s how you can add your own event.
---First we require the main module so we can add our own events.
local AnimEventManager = require("DepravedSense/AnimEvents/AnimEventManager")
---This is your event name
local event_name = "your_unique_event_name"
---This function will check if the character is a animal, and print on the console.
---@param character IsoPlayer | IsoAnimal
---@param value true | string | number
local function on_character_pleasure(character, value)
local is_animal = character:isAnimal()
print(is_animal)
end
AnimEventManager.add_living_client_event("your_unique_event_name", on_character_pleasure)
This code adds a simple event on the Client side that prints if an character is an animal, with add_living_client_event. Whenever an animation triggers that value, that logic will happen.
These are the current available functions for you to use, and create your events.
AnimEventManager.add_living_client_event
AnimEventManager.add_living_server_event
AnimEventManager.add_zombie_client_event
AnimEventManager.add_zombie_server_event
AnimEventManager.add_character_client_event
AnimEventManager.add_character_server_event
Inserting Events on Kits
We will soon learn about Animation Kits, but before we do, it’s nice to know that both Phases and Roads have core slots mainly for animation events. And to be able to insert our events in them it is needed to know the format we will use. You can use this example as a reference:
---@class DS_AnimEvent
---@field name string
---@field time_trigger number from 0.0 to 1.0
---@field param string | number | boolean | nil
local events = {
{ -- This event list will be played for actor 1
{
name = "EVENT_NAME_1",
-- When the event will be triggered. 50% means it will trigger exactly in
-- the middle of an animation.
time_trigger = 0.5,
-- Optional. In case the animation event uses an extra value.
-- in this case, the number `5` will be put as an argument on the callbacks.
param = 5,
},
{
name = "EVENT_NAME_2",
time_trigger = 0.1,
}
},
{ -- This event list will be played for actor 2
{
name = "EVENT_NAME_1",
time_trigger = 0.666,
param = 47,
}
}
}