Jump to content

Recommended Posts

This is what I have so far...

 

local function OnGetItemFromPlayer(inst, giver, item)
    
    --I eat food
    if item.components.edible then
        --meat makes us friends (unless I'm a guard)
        if item.components.edible.foodtype == "MEAT" or item.components.edible.foodtype == "HORRIBLE" then
            if inst.components.combat.target and inst.components.combat.target == giver then
                inst.components.combat:SetTarget(nil)
            elseif giver.components.leader and not inst:HasTag("guard") then
inst.SoundEmitter:PlaySound("dontstarve/common/makeFriend")
giver.components.leader:AddFollower(inst)
                inst.components.follower:AddLoyaltyTime(item.components.edible:GetHunger() * TUNING.PIG_LOYALTY_PER_HUNGER)
            end
        end
        if inst.components.sleeper:IsAsleep() then
            inst.components.sleeper:WakeUp()
        end
    end
 
I guess this is what I should change, but I'm not sure how.

All you have to do is this in your modmain.lua file:

 

TUNING.PIG_LOYALTY_MAXTIME = TUNING.TOTAL_DAY_TIME * 10000TUNING.PIG_LOYALTY_PER_HUNGER = TUNING.PIG_LOYALTY_MAXTIME
That'll make the loyalty last for 10,000 days. There's no easy way to make it truly infinite, but 10,000 days is probably good enough. Edited by squeek
  • Like 1

Untested, but this should work:

local saved_onwere_fn = nillocal function RemoveWerebeast(inst)    if inst.components.werebeast then        if not saved_onwere_fn then            saved_onwere_fn = inst.components.werebeast.onsetwerefn        end        inst:RemoveComponent("werebeast")    endendlocal function AddWerebeast(inst)    if not inst.components.werebeast then        inst:AddComponent("werebeast")        inst.components.werebeast:SetOnWereFn(saved_onwere_fn)        inst.components.werebeast:SetTriggerLimit(4)    endendAddPrefabPostInit("pigman", function(inst)    inst:ListenForEvent("startfollowing", RemoveWerebeast)    inst:ListenForEvent("stopfollowing", AddWerebeast)end)
Edited by squeek

This will sooner or later?

Example:

local function OnGetItemFromPlayer(inst, giver, item)
    
    --I eat food
    if item.components.edible then
        --meat makes us friends (unless I'm a guard)
        if item.components.edible.foodtype == "MEAT" or item.components.edible.foodtype == "HORRIBLE" then
            if inst.components.combat.target and inst.components.combat.target == giver then
                inst.components.combat:SetTarget(nil)
            elseif giver.components.leader and not inst:HasTag("guard") then
inst.SoundEmitter:PlaySound("dontstarve/common/makeFriend")
giver.components.leader:AddFollower(inst)
                inst.components.follower:AddLoyaltyTime(item.components.edible:GetHunger() * TUNING.PIG_LOYALTY_PER_HUNGER)
                TUNING.PIG_LOYALTY_MAXTIME = TUNING.TOTAL_DAY_TIME * 10000
               TUNING.PIG_LOYALTY_PER_HUNGER = TUNING.PIG_LOYALTY_MAXTIME
            end
        end
        if inst.components.sleeper:IsAsleep() then
            inst.components.sleeper:WakeUp()
        end
    end
 
local saved_onwere_fn = nil
 
local function RemoveWerebeast(inst)
    if inst.components.werebeast then
        if not saved_onwere_fn then
            saved_onwere_fn = inst.components.werebeast.onsetwerefn
        end
        inst:RemoveComponent("werebeast")
    end
end
 
local function AddWerebeast(inst)
    if not inst.components.werebeast then
        inst:AddComponent("werebeast")
        inst.components.werebeast:SetOnWereFn(saved_onwere_fn)
        inst.components.werebeast:SetTriggerLimit(4)
    end
end
 
AddPrefabPostInit("pigman", function(inst)
    inst:ListenForEvent("startfollowing", RemoveWerebeast)
    inst:ListenForEvent("stopfollowing", AddWerebeast)
end)

 

Or like this:

 
local saved_onwere_fn = nil
 
local function RemoveWerebeast(inst)
    if inst.components.werebeast then
        if not saved_onwere_fn then
            saved_onwere_fn = inst.components.werebeast.onsetwerefn
        end
        inst:RemoveComponent("werebeast")
    end
end
 
local function AddWerebeast(inst)
    if not inst.components.werebeast then
        inst:AddComponent("werebeast")
        inst.components.werebeast:SetOnWereFn(saved_onwere_fn)
        inst.components.werebeast:SetTriggerLimit(4)
    end
end
 
AddPrefabPostInit("pigman", function(inst)
    inst:ListenForEvent("startfollowing", RemoveWerebeast)
    inst:ListenForEvent("stopfollowing", AddWerebeast)
end)
 
local function OnGetItemFromPlayer(inst, giver, item)
    
    --I eat food
    if item.components.edible then
        --meat makes us friends (unless I'm a guard)
        if item.components.edible.foodtype == "MEAT" or item.components.edible.foodtype == "HORRIBLE" then
            if inst.components.combat.target and inst.components.combat.target == giver then
                inst.components.combat:SetTarget(nil)
            elseif giver.components.leader and not inst:HasTag("guard") then
inst.SoundEmitter:PlaySound("dontstarve/common/makeFriend")
giver.components.leader:AddFollower(inst)
                inst.components.follower:AddLoyaltyTime(item.components.edible:GetHunger() * TUNING.PIG_LOYALTY_PER_HUNGER)
                TUNING.PIG_LOYALTY_MAXTIME = TUNING.TOTAL_DAY_TIME * 10000
               TUNING.PIG_LOYALTY_PER_HUNGER = TUNING.PIG_LOYALTY_MAXTIME
            end
        end
        if inst.components.sleeper:IsAsleep() then
            inst.components.sleeper:WakeUp()
        end
    end
 
Thanks for your help.

No, put the code in your modmain.lua, do not modify pigman.lua.

You should have a modmain.lua (dont_starve/mods/yourmodname/modmain.lua) that looks like this:

TUNING.PIG_LOYALTY_MAXTIME = TUNING.TOTAL_DAY_TIME * 10000TUNING.PIG_LOYALTY_PER_HUNGER = TUNING.PIG_LOYALTY_MAXTIMElocal saved_onwere_fn = nil local function RemoveWerebeast(inst)    if inst.components.werebeast then        if not saved_onwere_fn then            saved_onwere_fn = inst.components.werebeast.onsetwerefn        end        inst:RemoveComponent("werebeast")    endend local function AddWerebeast(inst)    if not inst.components.werebeast then        inst:AddComponent("werebeast")        inst.components.werebeast:SetOnWereFn(saved_onwere_fn)        inst.components.werebeast:SetTriggerLimit(4)    endend AddPrefabPostInit("pigman", function(inst)    inst:ListenForEvent("startfollowing", RemoveWerebeast)    inst:ListenForEvent("stopfollowing", AddWerebeast)end)

No problem. Turns out removing the werebeast component doesn't work because it doesn't remove the event listeners. This will work (and it's actually a better solution):

local WereBeast = GLOBAL.require "components/werebeast"local WereBeast_SetWere_base = WereBeast.SetWerefunction WereBeast:SetWere(time)    -- only call the base function if we do not have a leader    local hasleader = self.inst and self.inst.components.follower and self.inst.components.follower.leader ~= nil    if not hasleader then        WereBeast_SetWere_base(self, time)    endend
Your modmain.lua should look like this:

TUNING.PIG_LOYALTY_MAXTIME = TUNING.TOTAL_DAY_TIME * 10000TUNING.PIG_LOYALTY_PER_HUNGER = TUNING.PIG_LOYALTY_MAXTIMElocal WereBeast = GLOBAL.require "components/werebeast"local WereBeast_SetWere_base = WereBeast.SetWerefunction WereBeast:SetWere(time)    -- only call the base function if we do not have a leader    local hasleader = self.inst and self.inst.components.follower and self.inst.components.follower.leader ~= nil    if not hasleader then        WereBeast_SetWere_base(self, time)    endend

@squeek help me!!!

I need help with the max time friendship of the RabbitMan, Spiders (With Webber), and Catcoons.

I tough is the same before but dosnt work:

 

TUNING.RABBIT_CARROT_LOYALTY = TUNING.TOTAL_DAY_TIME * 10000

 

TUNING.CATCOON_LOYALTY_MAXTIME = TUNING.TOTAL_DAY_TIME * 10000
 
TUNING.SPIDER_LOYALTY_MAXTIME = TUNING.TOTAL_DAY_TIME * 10000
TUNING.SPIDER_LOYALTY_PER_HUNGER = TUNING.SPIDER_LOYALTY_MAXTIME

because you have to code their "loyalty". they are not pigs.

What i have to use then?

In DS and RoG with Webber you can make friends of the spiders and the rabits and catcoons with each other character, this means they have loyalty but i really dont now.

 

What i need, help me.

oh yes they have on RoG, but its limited to webber

local function ShouldAcceptItem(inst, item, giver)    if giver.prefab ~= "webber" then        return false    end

and according to this code

            local loyaltyTime = item.components.edible:GetHunger() * TUNING.SPIDER_LOYALTY_PER_HUNGER            inst.components.follower:AddLoyaltyTime(loyaltyTime)

you just need to make TUNING.SPIDER_LOYALTY_PER_HUNGER really huge

 

well there a way to change food accepting to other character or to all

 GLOBAL.TUNING.SPIDER_LOYALTY_PER_HUNGER = 10000 local function MyShouldAcceptItem(inst, item, giver)    if inst.components.sleeper:IsAsleep() then        return false    end        if inst.components.eater:CanEat(item) then        return true    endend local function TweakSpider(inst)    if inst and inst.components and inst.components.trader then        inst.components.trader:SetAcceptTest(MyShouldAcceptItem)    endend AddPrefabPostInit("spider", TweakSpider)

add this to modmain.lua in your mod and any player character will be able to be friend with spiders

Edited by iWitch

i didnt played in RoG yet, lol, but catcoons have some limitations on food type

 

    if item:HasTag("cattoy") or item:HasTag("catfood") or item:HasTag("cattoyairborne") then

 

and there other variable to keep their loyality:

 

        inst.components.follower:AddLoyaltyTime(TUNING.CATCOON_LOYALTY_PER_ITEM)

 

so you have to make TUNING.CATCOON_LOYALTY_PER_ITEM big, not TUNING.CATCOON_LOYALTY_MAXTIME

rabbits doesnt have loyality thingy, but bunnymans do

                inst.components.follower:AddLoyaltyTime(TUNING.RABBIT_CARROT_LOYALTY)

But i am not sure if you able to use them all in one time, you have to check retargetfn/onnewtarget/onattacked of this prefabs and their brains to be sure that they dont attack each other, but i am too lazy to do it.

 

For example if you have 1 spider loyal to you and other which is not,they share targets with other spiders. So if non-loyal spider get attacked with your loyal bunnyman, your loyal spider probably will attack bunnyman too.

 

Same thing with bunnymans.

Edited by iWitch

oh yes they have on RoG, but its limited to webber

local function ShouldAcceptItem(inst, item, giver)    if giver.prefab ~= "webber" then        return false    end

and according to this code

            local loyaltyTime = item.components.edible:GetHunger() * TUNING.SPIDER_LOYALTY_PER_HUNGER            inst.components.follower:AddLoyaltyTime(loyaltyTime)

you just need to make TUNING.SPIDER_LOYALTY_PER_HUNGER really huge

 

well there a way to change food accepting to other character or to all

 GLOBAL.TUNING.SPIDER_LOYALTY_PER_HUNGER = 10000 local function MyShouldAcceptItem(inst, item, giver)    if inst.components.sleeper:IsAsleep() then        return false    end        if inst.components.eater:CanEat(item) then        return true    endend local function TweakSpider(inst)    if inst and inst.components and inst.components.trader then        inst.components.trader:SetAcceptTest(MyShouldAcceptItem)    endend AddPrefabPostInit("spider", TweakSpider)

add this to modmain.lua in your mod and any player character will be able to be friend with spiders

Tanks, i just proveit this for now and work fine but i dont understand how make them loyal for ever.

Tanks for your help im going to keep trying for make this work.

Obviously for making them true_loyal_forever you have to change "follower" component

 

scripts/followerforever.lua

Follower = require "components/follower" function Follower:GetLoyaltyPercent()    return 1 -- 100% loyality, if someone checksend function Follower:LongUpdate(dt)end function Follower:AddLoyaltyTime(time)self.targettime = 10000 --just in case if someone checking this outside Follower componentend return Follower

modmain.lua:

tmpFollower = require "followerforever"

this changes is dangerous in long term and probably its require some limitation with calling old functions.

But atm i dont see any problem.

Edited by iWitch

Obviously for making them true_loyal_forever you have to change "follower" component

 

scripts/followerforever.lua

Follower = require "components/follower" function Follower:GetLoyaltyPercent()    return 1 -- 100% loyality, if someone checksend function Follower:LongUpdate(dt)end function Follower:AddLoyaltyTime(time)self.targettime = 10000 --just in case if someone checking this outside Follower componentend return Follower

modmain.lua:

tmpFollower = require "followerforever"

this changes is dangerous in long term and probably its require some limitation with calling old functions.

But atm i dont see any problem.

This Work with every creature?

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...