Jump to content

Character mod help for Don't Starve Together


Recommended Posts

My goal is to make my character rarely drop items from his hands (Like when it's raining) and get more stats from honey nuggets. Does anyone have the components for this?  I'm not good at coding at all

Link to comment
Share on other sites

add it in

common_postinit(inst)

inst:AddTag("stronggrip")

end

it's tag on wurt, character withc this tag can hold equip still when wet

master_postinit = function(inst)

local food_like = {
        honeynuggets  = true,
    }

inst.components.eater._Eat = inst.components.eater.Eat
    function inst.components.eater:Eat(food)
        local edible = food.components.edible
        if food and edible and self:CanEat(food) then
            if food_like[food.prefab]  then
                inst.components.sanity:DoDelta(50)
                inst.components.hunger:DoDelta(10)
                inst.components.health:DoDelta(10)----change to the extra stats you want
            end
        end
        return inst.components.eater:_Eat(food)
    end

end

----and add this in master_postinit = function(inst)

Link to comment
Share on other sites

On 6/29/2023 at 3:30 AM, Glommer2 said:

add it in

common_postinit(inst)

inst:AddTag("stronggrip")

end

it's tag on wurt, character withc this tag can hold equip still when wet

master_postinit = function(inst)

local food_like = {
        honeynuggets  = true,
    }

inst.components.eater._Eat = inst.components.eater.Eat
    function inst.components.eater:Eat(food)
        local edible = food.components.edible
        if food and edible and self:CanEat(food) then
            if food_like[food.prefab]  then
                inst.components.sanity:DoDelta(50)
                inst.components.hunger:DoDelta(10)
                inst.components.health:DoDelta(10)----change to the extra stats you want
            end
        end
        return inst.components.eater:_Eat(food)
    end

end

----and add this in master_postinit = function(inst)

Thanks! but there is a misunderstanding here, the character is not supposed to not drop items, but to drop (not as often as when wet, but still) And is it possible to implement features from DS Hamlet like Wheeler's dash?

Link to comment
Share on other sites

--this is the official drop wet tool in file: player_common
local function DropWetTool(inst, data)
    --Tool slip.
    if inst.components.moisture:GetSegs() < 4 or inst:HasTag("stronggrip") then
        return
    end

    local tool = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS)
    if tool ~= nil and tool:GetIsWet() and math.random() < easing.inSine(TheWorld.state.wetness, 0, .15, inst.components.moisture:GetMaxMoisture()) then
        local projectile =
            data.weapon ~= nil and
            data.projectile == nil and
            (data.weapon.components.projectile ~= nil or data.weapon.components.complexprojectile ~= nil)

        if projectile then
            local num = data.weapon.components.stackable ~= nil and data.weapon.components.stackable:StackSize() or 1
            if num <= 1 then
                return
            end
            inst.components.inventory:Unequip(EQUIPSLOTS.HANDS, true)
            tool = data.weapon.components.stackable:Get(num - 1)
            tool.Transform:SetPosition(inst.Transform:GetWorldPosition())
            if tool.components.inventoryitem ~= nil then
                tool.components.inventoryitem:OnDropped()
            end
        else
            inst.components.inventory:Unequip(EQUIPSLOTS.HANDS, true)
            inst.components.inventory:DropItem(tool)
        end

        if tool.Physics ~= nil then
            local x, y, z = tool.Transform:GetWorldPosition()
            tool.Physics:Teleport(x, .3, z)

            local angle = (math.random() * 20 - 10) * DEGREES
            if data.target ~= nil and data.target:IsValid() then
                local x1, y1, z1 = inst.Transform:GetWorldPosition()
                x, y, z = data.target.Transform:GetWorldPosition()
                angle = angle + (
                    (x1 == x and z1 == z and math.random() * 2 * PI) or
                    (projectile and math.atan2(z - z1, x - x1)) or
                    math.atan2(z1 - z, x1 - x)
                )
            else
                angle = angle + math.random() * 2 * PI
            end
            local speed = projectile and 2 + math.random() or 3 + math.random() * 2
            tool.Physics:SetVel(math.cos(angle) * speed, 10, math.sin(angle) * speed)
        end
        --Lock out from picking up for a while?
        --V2C: no need, the stategraph goes into busy state
    end
end
--you can AddTag("stronggrip") to your character so that official Event listener won't affact you
--and do some change in your character file like this
local function NewDropWetTool(inst, data)
    --Tool slip.
    --1 step, delete the tag check here
    if inst.components.moisture:GetSegs() < 4 then
        return
    end
    --2 step, add a random num here as your chance
    if math.random(1,100) < 50 then
    local tool = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS)
    if tool ~= nil and tool:GetIsWet() and math.random() < easing.inSine(TheWorld.state.wetness, 0, .15, inst.components.moisture:GetMaxMoisture()) then
        local projectile =
            data.weapon ~= nil and
            data.projectile == nil and
            (data.weapon.components.projectile ~= nil or data.weapon.components.complexprojectile ~= nil)

        if projectile then
            local num = data.weapon.components.stackable ~= nil and data.weapon.components.stackable:StackSize() or 1
            if num <= 1 then
                return
            end
            inst.components.inventory:Unequip(EQUIPSLOTS.HANDS, true)
            tool = data.weapon.components.stackable:Get(num - 1)
            tool.Transform:SetPosition(inst.Transform:GetWorldPosition())
            if tool.components.inventoryitem ~= nil then
                tool.components.inventoryitem:OnDropped()
            end
        else
            inst.components.inventory:Unequip(EQUIPSLOTS.HANDS, true)
            inst.components.inventory:DropItem(tool)
        end

        if tool.Physics ~= nil then
            local x, y, z = tool.Transform:GetWorldPosition()
            tool.Physics:Teleport(x, .3, z)

            local angle = (math.random() * 20 - 10) * DEGREES
            if data.target ~= nil and data.target:IsValid() then
                local x1, y1, z1 = inst.Transform:GetWorldPosition()
                x, y, z = data.target.Transform:GetWorldPosition()
                angle = angle + (
                    (x1 == x and z1 == z and math.random() * 2 * PI) or
                    (projectile and math.atan2(z - z1, x - x1)) or
                    math.atan2(z1 - z, x1 - x)
                )
            else
                angle = angle + math.random() * 2 * PI
            end
            local speed = projectile and 2 + math.random() or 3 + math.random() * 2
            tool.Physics:SetVel(math.cos(angle) * speed, 10, math.sin(angle) * speed)
        end
        --Lock out from picking up for a while?
        --V2C: no need, the stategraph goes into busy state
    end
    end
end

local function OnAttackOther(inst, data)
    if data ~= nil and data.target ~= nil and data.target:HasTag("player") then
        inst.hasAttackedPlayer = true
    end
    if data.weapon then
        NewDropWetTool(inst, data)
    end
end

--and add this two listeners to your character fn
local common_postinit = function(inst)
inst:ListenForEvent("working", NewDropWetTool)
inst:ListenForEvent("onattackother", OnAttackOther)
end

Link to comment
Share on other sites

I think it means you want to move a action from hamlet to dst? if so you can take a look at this https://steamcommunity.com/sharedfiles/filedetails/?id=2399658326

you'll need character action anim (player_actions_roll for wheeler's dodge),and stategraph for wilson and wilson_client,and a inst:AddComponent("reticule") in your character file to activate your mod action

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