Jump to content

[TEMPLATE] Custom follower (with Tutorial)


Do you find it useful ?  

31 members have voted

  1. 1. So, do you ?

    • Yes, thanks a lot
      25
    • Nope, end yourself with beefalo belt
      1
    • Dunno, but don't use this beefalo belt
      5


Recommended Posts

On 1/15/2021 at 2:24 AM, Yakuzashi said:

Alright, it was really strange, I have fixed it but dunno how. I have made new exported folder and icons (everything is based on the old art), probably something went south during conversion.

Wow, it works!!! Thanks for helping:)
And... I know modding is not a simple thing... but can I have another question about the follower?
I want to change follower as a ghost(like Abigail). But I can't find a solution...
You don't have to respond to this if you don't want to. You already helped me a lot:)

Link to comment
Share on other sites

Quote

...\Steam\steamapps\common\Don't Starve Together\data\databundles

...scripts.zip
Unpack it and then open sub-folder "prefabs". Then file called "abigail.lua" should contain every essential thing.

Try to swap this section inside creature.lua

Quote

    inst.AnimState:SetBank("ghost")
    inst.AnimState:SetBuild("ghost_abigail_build")

It might require some tweaking to match the stategraph and all the animation stuff. I am short on time, so I will leave it this way. Cheers!

Link to comment
Share on other sites

Hello I just wanted to add to this thread for people who were having trouble like I was having followers continue following after disconnecting without an eyebone item. this code is pulled from abigail and wendy

just replace any mention of creature with the name of your creature file name and player with the name of your player file name

 

inside the player.lua add the following functions

Quote

local function OnDespawn(inst)
    if inst.creature ~= nil then
        inst.creature.components.lootdropper:SetLoot(nil) --removes the loot so that you can kill the creature on log out
        inst.creature.components.health:SetInvincible(true)
        inst.creature:PushEvent("death") -- inst.creature.Remove might work here if you don't want to use the lootdropper
        --in case the state graph got interrupted somehow, just force
        --removal after the dissipate animation should've finished
        inst.creature:DoTaskInTime(25 * FRAMES, inst.creature.Remove)
    end
end

local function OnSave(inst, data)
    if inst.creature ~= nil then
        data.creature = inst.creature:GetSaveRecord()
    end
end

-- When loading or spawning the character

local function OnLoad(inst, data)
    if data ~= nil and data.creature ~= nil and inst.creature == nil then
        local creature = SpawnSaveRecord(data.creature)
        if creature ~= nil then
            if inst.migrationpets ~= nil then
                table.insert(inst.migrationpets, creature)
            end
            creature:LinkToPlayer(inst)
        end
    end
end

inside the player.lua master postnit add the following somewhere near the bottom

Quote

inst.creature = nil

inst.OnDespawn = OnDespawn
inst.OnSave = OnSave
inst.OnLoad = OnLoad

inside the creature.lua add the following functions

Quote

local LOOT = {"rocks",} --add whatever you want


local function unlink(inst)
    inst._playerlink.creature = nil
end

local function linktoplayer(inst, player)
    inst.components.follower:SetLeader(player) --wasn't sure if set leader or add follower was better so I just added both
    --inst.components.lootdropper:SetLoot(LOOT) --this was causing my loot to double but it's how abilgail was reseting her loot
    inst.persists = false
    inst._playerlink = player
    player.creature = inst
    player.components.leader:AddFollower(inst) --abigail uses this function instead of SetLeader but I was having trouble with it
    player:ListenForEvent("onremove", unlink, inst)
end

 

inside the main function of creature.lua add the following

Quote

inst._playerlink = nil

inst.OnSave = OnSave
inst.OnLoad = OnLoad

inst.LinkToPlayer = linktoplayer

 

that's all I remember for now. hope this helps somebody

  • Thanks 2
Link to comment
Share on other sites

Thank you for posting this template, I'm rather new to this so it helps a lot!

I've run into an error when trying to use it and was hoping you might be able to help.

I was trying to add the follower to my character mod, but when I finished transferring and renaming things the new mod would cause the game to say "the mod is out of date" and then crash.

the link below should have the crash log, the working zip[before adding the mod], and the broken follower zip [after attempting to add the mod]

(I had to do the drive link because the files were too large)

https://drive.google.com/drive/folders/1uommEF5yiMaVY-RzEIVfonEDU4f2J2ts?usp=sharing

Edited by Remnince
Link to comment
Share on other sites

(I got help from a translator.)

Hi, I really need some help.

I changed the anchor to a different name in your mod,

and the zip file appeared correctly in the anim folder.

But I couldn't make that item.

My character just says, "I can't do that."

When I didn't just change the name of the anchor.lua file,

Then I could make the item,

but I couldn't make a real anchor instead.

Can you help me? Please T-T

1_JERRY.zip

Edited by kokoekwjd
Link to comment
Share on other sites

On 11/8/2019 at 12:29 AM, Yakuzashi said:

Introduction

Hello everyone. I hadn't seen any tutorial dedicated to this topic. At the start I need to state that I am pretty lame in everything associated with modding, so don't expect sophisticated solutions. This tutorial is simple yet effective, I have to agree that it could be better but as I have said, I am just simple man. I have used my old projects to explain you the scheme of your custom follower.


Template is based on this:

Main Part

To make functional follower you need to introduce the follower's:

- main script [creature.lua], the corpus of you follower

- anchor [anchor.lua], I have called it this way, because it attaches and provides easy summoning of the creature to your DST world

- brain [creaturebrain.lua], yep, that's the brain, every action you require from your creature belongs to it

- stategraph [SGcreature.lua], this file gives your creature ability to perform any visible action, because it's connected with animations and their realizations

 

Locations

Main Folder -> scripts -> prefabs -> [creature.lua]

Main Folder -> scripts -> prefabs -> [anchor.lua]

Main Folder -> scripts -> brains -> [creaturebrain.lua]

Main Folder -> scripts -> stategraphs -> [SGcreature.lua]

 

How to make mine template yours ? That's simple! Follow me this way!

At the start, change my names [name.lua] into yours.

 

[taern.lua]

That should be your character's name.

into

local common_postinit = function(inst) 

goes

inst:AddTag("summonerally")

Add this tag to prevent summoned creature from attacking your character and vice versa.

and

local master_postinit = function(inst)

goes

inst:AddComponent("reader")

It will let you read books, which is crucial for this method of summoning follower.

 

[creature.lua]

Change name 'creature' into yours follower's name. Using Ctrl+F in Notepad++ as shown in ESCT tutorial by Dragon Wolf Leo.

That's your follower's appearance [Main Folder -> exported -> creature]

You can call it what you want to, but it must match [name in exported] and all other references in whole mod to work properly.

 

[anchor.lua]

Change name 'anchor' into your summoning item.

 

[creaturebrain.lua]

I am not sure if changing CreatureBrain name will affect anything but just to be sure you can try.

function CreatureBrain:OnStart()
    local root = PriorityNode(
    {
		
        WhileNode(function() return IsNearLeader(self.inst, KEEP_WORKING_DIST) end, "Leader In Range",
            PriorityNode({                
                IfNode(function() return self.inst.prefab == "creature" end, "Is Duelist",
                    PriorityNode({
                        WhileNode(function() return self.inst.components.combat:GetCooldown() > .5 and ShouldKite(self.inst.components.combat.target, self.inst) end, "Dodge",
                            RunAway(self.inst, { fn = ShouldKite, tags = { "_combat", "_health" }, notags = { "INLIMBO" } }, KITING_DIST, STOP_KITING_DIST)),
                        ChaseAndAttack(self.inst),
                }, .25)),
                IfNode(function() return self.inst.prefab == "creature" end, "Keep Chopping",
                    DoAction(self.inst, function() return FindEntityToWorkAction(self.inst, ACTIONS.CHOP) end)),
                IfNode(function() return self.inst.prefab == "creature" end, "Keep Mining",
                    DoAction(self.inst, function() return FindEntityToWorkAction(self.inst, ACTIONS.MINE) end)),
                IfNode(function() return self.inst.prefab == "creature" end, "Keep Digging",
                    DoAction(self.inst, function() return FindEntityToWorkAction(self.inst, ACTIONS.DIG, DIG_TAGS) end)),
        }, .25)),

        Follow(self.inst, GetLeader, MIN_FOLLOW_DIST, TARGET_FOLLOW_DIST, MAX_FOLLOW_DIST),

        WhileNode(function() return GetLeader(self.inst) ~= nil end, "Has Leader",
            FaceEntity(self.inst, GetFaceTargetFn, KeepFaceTargetFn)),
    }, .25)

    self.bt = BT(self.inst, root)
end

Those lines inside of this chunk must match your prefab's name. If it won't match your follower is not going to perform those actions (fighting,mining,chopping,digging)

ex.  'Creature' =/= 'creature' and your follower will not dig out objects in this case.

 

[SGcreature.lua]

Change name 'creature' into yours follower's name. If you want your creature to be non-humanoid you can play with stategraph to match your animation's frames, but I don't know how to achieve rewarding results.

 

[modmain.lua]

PrefabFiles = {
	"taern",
	"taern_none",	
	------------
	"creature",
}

Change name 'creature' into yours follower's name one more. Add this:

Assets = {	
	Asset("ATLAS", "images/inventoryimages/anchor.xml"),
	Asset("IMAGE", "images/inventoryimages/anchor.tex"),

	Asset("ANIM", "anim/creature.zip"),
}

This will make your item [anchor] avaible to craft and use. Just remember about CAPITALS.

GLOBAL.STRINGS.NAMES.ANCHOR = "Anchor"
GLOBAL.STRINGS.RECIPE_DESC.ANCHOR = "Allows you to summon your custom creature into this world."
GLOBAL.STRINGS.CHARACTERS.GENERIC.DESCRIBE.ANCHOR = "Is this a Ouija board ?"

local anchor = Ingredient( "anchor", 1 )
anchor.atlas = "images/inventoryimages/anchor.xml"
local anchor = AddRecipe("anchor", { Ingredient("feather_crow", 2), Ingredient(GLOBAL.CHARACTER_INGREDIENT.SANITY, 20), Ingredient("goldnugget", 4)}, RECIPETABS.WAR, TECH.NONE, nil, nil, nil, nil, nil, "images/inventoryimages/anchor.xml")

You will need to create additional:

- [Main Folder -> exported -> anchor] for your item if you want to see it in game.

- [Main Folder -> images -> inventoryimages] and place your 64x64 icon of item TEX and XML. Change names in XML too.

 

Appendix
So everything beyond 'vanilla' tutorial is added by me to make your life easier. If you have created your first custom character you won't have problems with distinguishing extraordinary files connected with custom follower. I have attached my template just few lines under this block of text.

Have fun with your digital friend

 

P.S. I know my english is not perfect, but I think it's pretty understandable. Well if not just write a comment below and I will try to help you the best I can

 

Download the template here   ----->    Taern - Follower Tutorial.zip

hello, so, how do i fix that my creature do actions without i do it first?

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
 Share

×
  • Create New...