Credit goes to the Bigby Wolf mod for the health threshold activator; however, there are other options available to you.
I will preface this by saying I'm not a very good coder; most of this was discovered by asking for help or digging through the game files. With that said, here we go. It will also be needlessly prolix.
What we'll be achieving here is having you make your character become any other mob in the game via a transformation that can be triggered by health, the full moon, or by eating an item. For custom-made mobs, I don't know. The principles probably remain the same. For creatures without any action handlers in their stategraphs, I don't know. This is an amateur hour tutorial. I simply don't have the knowledge as of yet as I have not needed it.
Firstly, you'll need to post the following code in your character's prefab file:
local function BecomeYour_Custom_Character(inst)
inst.your_custom_werewolf = false
local function BecomeYour_Custom_Werewolf(inst)
inst.your_custom_werewolf = true
inst.AnimState:SetBank("your_custom_werewolf's_anim_bank") ----- You can find the bank of whatever creature you are using in its prefab.
inst.AnimState:SetBuild("your_custom_werewolf's_anim_build") ---- You can find the animation for x's _build in your creature's prefab.
inst:SetStateGraph("SGyour_custom_werewolf") ------- See stategraph below
So, let us take a look at becoming a Bunnyman to see an example of this.
local function BecomeRabbitman(inst)
inst.wererabbit = false
local function Become_Wererabbit(inst)
inst.wererabbit = true
Now we need to make sure the game knows when to start this transformation.
inst:ListenForEvent("nighttime", function(global, data) if GetClock():GetMoonPhase() == "full" and not inst.your_custom_werewolf then becomeyour_custom_werewolf(inst) end end, GetWorld())
inst:ListenForEvent("daytime", function(global, data) if GetClock():IsDay() and inst.your_custom_werewolf then becomeyour_custom_character(inst) end end, GetWorld())
inst:ListenForEvent("oneat", function(inst, data)
if data.food.prefab == "whatever_you_want" and not inst.your_custom_werewolf then
becomeyour_custom_werewolf(inst) --- turn into your werewolf when you eat a carrot or something
elseif data.food.prefab == "whatever_you_want" and inst.your_custom_werewolf then
becomeyour_custom_character(inst) --- turn back into your character when you eat another one
You are going to need to find whatever creature you are using's stategraph (located in the game's data folders). You will need to replicate it and rename it, then create your own stategraph folder in your mod character's scripts folder and put your new renamed stategraph in there.
So the path will be YourMod/scripts/stategraphs/SGyour_custom_werewolf
The stategraph will need some editing. On a basic level, such as turning into a bunnyman or pig, you will need to remove any instance of the term 'follower' from the stategraph (more often than not by just getting rid of the entire line it is contained in). This will prevent crashes if you equip an item such as a hat.
For most creatures, such as the Deerclops, death will cause a crash. I don't know why because I'm an untalented hack, but I removed the following line from the Deerclops and it stopped crashing:
You can also add in actions (you can find a list of actions in the game's data folder under 'actions.lua'). For instance, you may want to add in the action PICK and PICKUP using one of the creature's existing animations to avoid any crashes when you attempt to pick things up. Here is an example of making a bunnyman able to pick objects such as grass and flowers:
local actionhandlers =
ActionHandler(ACTIONS.PICKUP, "pickup"), ----- The bunnyman can already pick up items
ActionHandler(ACTIONS.PICK, "pickup"), ---------- So we added in the PICK action using the bunnyman's "pickup" animation
Here is a demonstration using the Bunnyman.
Bunnyman's stategraph before we use it:
There is a little bit more you can do with the transformation. Just as with your custom character, you can customise the werecreature:
There is a lot more, but those are just some examples. Don't forget to revert anything you do in the transformation to the werewolf in the transformation back to your character.
And that should be all.
Good luck, everyone! I hope this helps.