Jump to content

Help with custom character coding.

Recommended Posts

Hey everybody, I'm a bit new to coding and modding, the don't starve mods I've been working on happen to be the first of any form of the previously mentioned attempted. So far I've been ripping through a bunch of the codes of other mods to try and figure things out to make some patchwork monstrosity of a lua file and so far it's been going well.


Unfortunately for the life of me I can't seem to figure out anything regarding the ability to make someone able to chop trees and have a built in shovel the same way the werebeaver would. Is anybody able to assist me in some way?


I apologize for my English, It's not my first language.

Link to comment
Share on other sites

Klei went through a lot of trouble to bring to life Woodie. With that being said...

Basically what we want to do is a custom Dig and Chop action, identical in functionality but with a different animation than its already-implemented actions. So, we just need to make a custom action, associate it to a component so it shows up on the tree/bush we want to interact with, and add a stategraph to our action so it plays a nice animation:

-- Our custom chop action.AddAction("SUPERCHOP", "Chop", function(act)    if act.target.components.workable and act.target.components.workable.action == GLOBAL.ACTIONS.CHOP then        local numworks = 1        act.target.components.workable:WorkedBy(act.doer, numworks)    end    return trueend)-- Add it to trees.	function SetupSuperchopAction(inst, doer, actions)	if doer and doer.prefab == "wolfgang" and inst.prefab == "evergreen" then        table.insert(actions,GLOBAL.ACTIONS.SUPERCHOP)    endend-- Associate it with a dummy component. For some reason trying to associate it with workable makes our custom stategraph action handler play the default chop animation.AddComponentAction("SCENE", "dummy", SetupSuperchopAction)-- Add an animation to our action. Instead "attack" we should add a state called "superchop" to have it play our animation.local superchop_ah = GLOBAL.ActionHandler( GLOBAL.ACTIONS.SUPERCHOP, "attack" )AddStategraphActionHandler("wilson", superchop_ah)-- TODO: Add an action handler to wilson_client.-- Add the dummy component to a tree, so our custom superchop action shows up.AddPrefabPostInit("evergreen", function(inst)    inst:AddComponent("dummy")end)

What we end up with is a wolfgang who is able to cut trees down by punching them. This same procedure applies to the Dig action.


Check out the sample mod "Soulmates" by PeterA to understand better how Actions/ActionHandlers/ComponentActions work and the api examples to implement a custom State.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...