Jump to content

Need help with custom perk: Increased follower time.


whatsherface

Recommended Posts

Hi there! Thank's for taking a look at my problem. A little background: I'm fairly new to modding. (I've messed around in some of minecraft's code, so I know the bare minimum of actual coding) Don't starve is a new challenge for me. That being said I've created a new character, modified their stats and whatnot. Now I want to add several perks. One being: runs incredibly fast. I've taken care of that. 

Now for the second perk: I want to make it so the followers with them have a longer loyalty time.

inst.components.follower:AddLoyaltyTime(240)

Now with my basic lack of understanding I know this is the basic loyalty time of half a day.  I tried just putting this line in the characters prefab file under

inst.components.locomotor.walkspeed = (6)
inst.components.locomotor.runspeed = (10)

But that didn't work and gave me a Warning 

Untitled.png

 

TLDR: Trying to increase loyalty time of all followers under a specific character.

Am I on the right track, or completely wrong? I would be so grateful to get a little (or a lot) of help. Thank you!

Link to comment
Share on other sites

9 hours ago, whatsherface said:

Hi there! Thank's for taking a look at my problem. A little background: I'm fairly new to modding. (I've messed around in some of minecraft's code, so I know the bare minimum of actual coding) Don't starve is a new challenge for me. That being said I've created a new character, modified their stats and whatnot. Now I want to add several perks. One being: runs incredibly fast. I've taken care of that. 

Now for the second perk: I want to make it so the followers with them have a longer loyalty time.


inst.components.follower:AddLoyaltyTime(240)

Now with my basic lack of understanding I know this is the basic loyalty time of half a day.  I tried just putting this line in the characters prefab file under

inst.components.locomotor.walkspeed = (6)
inst.components.locomotor.runspeed = (10)

 

TLDR: Trying to increase loyalty time of all followers under a specific character.

That's because "inst" is a generic variable used as a replacement for whatever object you're handling at the time. So in your example in "inst.components.follower" inst refers to the follower object which possess a follower component. Whereas inst in your character sam.lua refers to your character object e.g. "sam". Also if you think it through, it is logical that sam has no follower component since "he is not a follower" ;)

I know Mobbstar probably answered your question already in less words that I did but I thought you might be confused by those "inst" everywhere. Anyone knows what "inst" stands for btw ?

Link to comment
Share on other sites

34 minutes ago, whismerhill said:

Anyone knows what "inst" stands for btw ?

"instance", it is an instance of a "prefab" - pre-fabricated. "entity" refers to widget entities too, but sometimes the difference between entity and instance are rather obscure, as these words basically mean the same thing.

Link to comment
Share on other sites

Quote

That's because "inst" is a generic variable used as a replacement for whatever object you're handling at the time. So in your example in "inst.components.follower" inst refers to the follower object which possess a follower component. Whereas inst in your character sam.lua refers to your character object e.g. "sam". Also if you think it through, it is logical that sam has no follower component since "he is not a follower" ;)

I know Mobbstar probably answered your question already in less words that I did but I thought you might be confused by those "inst" everywhere. Anyone knows what "inst" stands for btw ?

That makes a lot of sense. Thank's for pointing that out. ^^

 

Quote

The "Follower" component is what the follower has, the player has the "leader" component. Woodie has a small leader boost in DST too, I think, so check data\scripts\prefabs\woodie.lua out!

I took a look through the woodie.lua where you specified and I'm having trouble finding anything about follower loyalty time. I read through it all and did a few ctrl Fs just for good measure. Am I missing something? 

I feel like this answer is glaringly obvious, sorry.. ;-;

Link to comment
Share on other sites

13 minutes ago, Mobbstar said:

It's not at all, actually. The devs decided to use a rather indescriptive tag:

    inst:AddTag("polite")

Okay so I found that and put it below my local common_postinit = function(inst) like it was in the woodie.lua.

Now to change what I suppose would be the "level of politeness" ie: Loyalty time, Would I do something in the Master_postinit?

Link to comment
Share on other sites

37 minutes ago, whatsherface said:

Okay so I found that and put it below my local common_postinit = function(inst) like it was in the woodie.lua.

Now to change what I suppose would be the "level of politeness" ie: Loyalty time, Would I do something in the Master_postinit?

uhm... that's given by the game. You'd have to edit one or more of the "Follower" components' functions to do that (which is entirely possible, of course, but not always 100% mod compatible)

You would have to overwrite the "receive item" function for every befriendable thing. That is difficult. Instead, you could add a bit of custom code to the recruitment function (in modmain.lua):

AddComponentPostInit("follower", function(self)
    local _AddLoyalityTime = self.AddLoyaltyTime
    function self:AddLoyaltyTime(time, ...)
        if self.leader and self.leader:HasTag("superpolite") and GetTime() > 0 then
            time = time * 1.2 -- TUNE HERE ( you can also add absolute values instead of multiplying)
        end
        _AddLoyalityTime(self, time, ...)
    end
end
Link to comment
Share on other sites

Alright so I added: 

inst:AddTag("superpolite"

To my Sam.lua and the code your provided to the modmain.lua like this:

local require = GLOBAL.require
local STRINGS = GLOBAL.STRINGS

AddComponentPostInit("follower", function(self)
    local _AddLoyalityTime = self.AddLoyaltyTime
    function self:AddLoyaltyTime(time, ...)
        if self.leader and self.leader:HasTag("superpolite") and GetTime() > 0 then
            time = time * 2 -- TUNE HERE ( you can also add absolute values instead of multiplying)
        end
        _AddLoyalityTime(self, time, ...)
    end
end
)

I got

 Untitled.png

What did I do wrong?

  •  
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...