Play animations with workspots
Learn how to play an animation on an entity through clever gimmicks in Redscript.
This is an advanced tutorial that requires you to understand the basics of wolvenkit
Credits
First of all, let's give credits to people out there:
Cyberscript and Smoke Everywhere authors donk7413 and Eli, who originally found out how to play animation through workspots. All credits to them in that regard.
psiberx for his numerous hints and advices, as always.
How to ?
It started from a talk with @Eli and @donk7413 the authors of Cyberscript and Smoke Everywhere mods.
When asked details about how they managed to have V smokes a cigarette anywhere in-game, they mentioned having merged all .workspot
files in a gigantic file for convenience (namely Cyberscript Core Animation Archive), so that Cyberscript can play any animation in-game on V or any NPC.
At first it didn't ring a bell, but then @psiberx mentioned about modders "abusing" .workspot
by spawning an invisible .ent
to have the target being animated.
The trick is actually to spawn an invisible device (.ent
) right onto your entity, which then allows to trigger animation(s).
WolvenKit
So it happens that we need a .ent
file whose components
contains a workWorkspotResourceComponent
which references a .workspot
by name
and DepotPath
.
In turn, .workspot
file contains a list of worksSequence
s containing workAnimClip
which are the animations to play with idleName
and animName
.
Of course the .ent
must be made invisible and contain a set of specific properties, and this is where all hard work was already made by Cyberscript people.
💡 Generally speaking if you need to play a ton of animations I would recommend you to use Cyberscript directly, since it already does everything for you and also comes up with a ton of useful more features to build a mod with ease.
On the other hand, if like me you only want to play 1 or 2 animations at most, then it's probably a lot of overhead and you can keep reading.
What I personally did was to reuse Cyberscript archive .ent
stripped of components
that I don't need, and .workspot
with only the animations that I'm interested into.
To do the same, you will need to download the Cyberscript Core Animation Archive, install it in your mod folder so that Wolvenkit can find it, and locate the workspot_anim.ent
file in the following directory structure:
You can then use wolvenkit and your file explorer to move the workspot_anim.ent
in the location of your choice inside your mod. Then you can strip it of every components that isn't aworkWorkspotResourceComponent
using wolvenkit.
Then you will need to locate an interesting .workspot
file inside the base/workspot
of the game and place it in the location of your choice inside the archive folder of the mod you are creating.
Redscript
Once the previous files are ready, we need something able to spawn an entity in Redscript (once again if your preference goes to Lua, I'd recommend you to use Cyberscript directly).
This is exactly what Codeware offers with DynamicEntitySystem
: see "Entities" in its wiki!
Here's a short example which will get us going:
(You will need to replace the paths to the .ent
and .workspot
files with the paths to your files )
Adding the script to your mod
to add this script to your mod, you will need to create the following structure in the ressources
folder of your mod:
Clearing misconceptions
.ent
can be anything, not just a "living entity". it can be a cigarette, the act of smoking.. it can really be "whatever".it contains
components
with e.g.workspotMapper
,entSlot
, etcit also contains obviously a
workWorkspotResourceComponent
with points out to the.workspot
.
.workspot
gets triggered throughout.ent
: you don't spawn a workspot and play it on a target, you spawn an entity which references the workspot and plays the workspot through the entity (which in turn play the animation(s), and you can "jump" from one animation to another in the same workspot).
Last updated