Jump to content

help with coding perks + such!


Recommended Posts

hi! i'm finally pursuing my long-standing dream of making a DST mod, but i'm not sure what code to use for certain attributes of the character. if i could get any help, it'd be appreciated! here's what i need help with coding:
- loses 5 sanity every time he kills an animal (not a monster)

- can eat spoiled/stale food and monster meat with no drawbacks

I'm not sure if this is a possibility either, but the ability to befriend hounds (akin to what Webber can do with spiders) would be cool. If anyone knows anything about that, it'd be a lot of help! Thank you!!!

Link to comment
Share on other sites

for the monstermeat and spoiled food it's probably 

inst.components.eater.strongstomach = true
inst.components.eater.ignoresspoilage = true

i don't have time to figure out the other ones right now but quickly glancing at how webber does it, there is this on the spider.lua

local function ShouldAcceptItem(inst, item, giver)
    return giver:HasTag("spiderwhisperer") and inst.components.eater:CanEat(item)
end

local function OnGetItemFromPlayer(inst, giver, item)
    if inst.components.eater:CanEat(item) then  
        inst.sg:GoToState("eat", true)

        local playedfriendsfx = false
        if inst.components.combat.target == giver then
            inst.components.combat:SetTarget(nil)
        elseif giver.components.leader ~= nil and
            inst.components.follower ~= nil then
            giver:PushEvent("makefriend")
            playedfriendsfx = true
            giver.components.leader:AddFollower(inst)
            inst.components.follower:AddLoyaltyTime(item.components.edible:GetHunger() * TUNING.SPIDER_LOYALTY_PER_HUNGER)
        end

        if giver.components.leader ~= nil then
            local spiders = GetOtherSpiders(inst)
            local maxSpiders = 3

            for i, v in ipairs(spiders) do
                if maxSpiders <= 0 then
                    break
                end

                if v.components.combat.target == giver then
                    v.components.combat:SetTarget(nil)
                elseif giver.components.leader ~= nil and
                    v.components.follower ~= nil and
                    v.components.follower.leader == nil then
                    if not playedfriendsfx then
                        giver:PushEvent("makefriend")
                        playedfriendsfx = true
                    end
                    giver.components.leader:AddFollower(v)
                    v.components.follower:AddLoyaltyTime(item.components.edible:GetHunger() * TUNING.SPIDER_LOYALTY_PER_HUNGER)
                end
                maxSpiders = maxSpiders - 1

                if v.components.sleeper:IsAsleep() then
                    v.components.sleeper:WakeUp()
                end
            end
        end
    end
end

                                 
     inst:AddComponent("trader")
    inst.components.trader:SetAcceptTest(ShouldAcceptItem)
    inst.components.trader.onaccept = OnGetItemFromPlayer

 

Edited by Wolf_EX
Link to comment
Share on other sites

8 hours ago, pompomworm said:

- loses 5 sanity every time he kills an animal (not a monster)

My character has a similar perk, it's how i do it :


local function onkilled(inst, data)
if data.victim:HasTag("animal") then
 inst.components.sanity:DoDelta(-TUNING.SANITY_SMALL)
 end
end

Add this line in the master postinit :

    inst:ListenForEvent("killed", onkilled)

 

Just set the value for sanity to your taste (i don't remember what value is SANITY_SMALL but i think it's around 5)

Edited by Lumina
Link to comment
Share on other sites

On 7/20/2018 at 1:35 AM, Wolf_EX said:

for the monstermeat and spoiled food it's probably 


inst.components.eater.strongstomach = true
inst.components.eater.ignoresspoilage = true

i don't have time to figure out the other ones right now but quickly glancing at how webber does it, there is this on the spider.lua


local function ShouldAcceptItem(inst, item, giver)
    return giver:HasTag("spiderwhisperer") and inst.components.eater:CanEat(item)
end

local function OnGetItemFromPlayer(inst, giver, item)
    if inst.components.eater:CanEat(item) then  
        inst.sg:GoToState("eat", true)

        local playedfriendsfx = false
        if inst.components.combat.target == giver then
            inst.components.combat:SetTarget(nil)
        elseif giver.components.leader ~= nil and
            inst.components.follower ~= nil then
            giver:PushEvent("makefriend")
            playedfriendsfx = true
            giver.components.leader:AddFollower(inst)
            inst.components.follower:AddLoyaltyTime(item.components.edible:GetHunger() * TUNING.SPIDER_LOYALTY_PER_HUNGER)
        end

        if giver.components.leader ~= nil then
            local spiders = GetOtherSpiders(inst)
            local maxSpiders = 3

            for i, v in ipairs(spiders) do
                if maxSpiders <= 0 then
                    break
                end

                if v.components.combat.target == giver then
                    v.components.combat:SetTarget(nil)
                elseif giver.components.leader ~= nil and
                    v.components.follower ~= nil and
                    v.components.follower.leader == nil then
                    if not playedfriendsfx then
                        giver:PushEvent("makefriend")
                        playedfriendsfx = true
                    end
                    giver.components.leader:AddFollower(v)
                    v.components.follower:AddLoyaltyTime(item.components.edible:GetHunger() * TUNING.SPIDER_LOYALTY_PER_HUNGER)
                end
                maxSpiders = maxSpiders - 1

                if v.components.sleeper:IsAsleep() then
                    v.components.sleeper:WakeUp()
                end
            end
        end
    end
end

                                 
     inst:AddComponent("trader")
    inst.components.trader:SetAcceptTest(ShouldAcceptItem)
    inst.components.trader.onaccept = OnGetItemFromPlayer

 

 

On 7/20/2018 at 1:47 AM, Lumina said:

My character has a similar perk, it's how i do it :



local function onkilled(inst, data)
if data.victim:HasTag("animal") then
 inst.components.sanity:DoDelta(-TUNING.SANITY_SMALL)
 end
end

Add this line in the master postinit :


    inst:ListenForEvent("killed", onkilled)

 

Just set the value for sanity to your taste (i don't remember what value is SANITY_SMALL but i think it's around 5)

thank you both so much! this is super helpful stuff!!! sorry for the late reply (i dont check klei forums often), but i really appreciate your help a ton! thank you!

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