Jump to content

Recommended Posts

Hello Don't Starve Together community! New to character modding and not familiar with Lua at all, so I wanted some help here.

So, a bit of backstory. I'm creating a character mod. One of the negative perks of this character is that she's weak to sunlight (think like a vampire), which I tried integrating into the game by making her sanity drain during the daytime, but then realized it actually benefited another one of her perks that multiplies her damage output the lower her sanity is. So, I decided maybe tying it into another one of her core mechanics would work better, that being that she is super hungry all the time, and maybe the heat of the sun would cause her hunger to drain slightly faster.

Thing is, I can't for the life of me figure out how to make her hunger drain faster during the day and slightly less at dusk/night and in caves. Help would be appreciated!

11 hours ago, vitasunshine said:

Hello Don't Starve Together community! New to character modding and not familiar with Lua at all, so I wanted some help here.

So, a bit of backstory. I'm creating a character mod. One of the negative perks of this character is that she's weak to sunlight (think like a vampire), which I tried integrating into the game by making her sanity drain during the daytime, but then realized it actually benefited another one of her perks that multiplies her damage output the lower her sanity is. So, I decided maybe tying it into another one of her core mechanics would work better, that being that she is super hungry all the time, and maybe the heat of the sun would cause her hunger to drain slightly faster.

Thing is, I can't for the life of me figure out how to make her hunger drain faster during the day and slightly less at dusk/night and in caves. Help would be appreciated!

I haven't thoroughly tested this code yet, but it seems like it should work.
 

local function UpdateHungerRate(inst)
    if inst.components.hunger == nil then
        return
    end

    local burn_rate = 1.0
    local is_cave = TheWorld:HasTag("cave")

    if is_cave then
        burn_rate = 1.2
    else
        if TheWorld.state.isday then
            burn_rate = 2.0
        elseif TheWorld.state.isdusk then
            burn_rate = 1.5
        elseif TheWorld.state.isnight then
            burn_rate = 1.2
        end
    end

    inst.components.hunger.burnratemodifiers:SetModifier(inst, burn_rate, "hunger_burn")
end
-- In master_postinit--
inst:WatchWorldState("isday", UpdateHungerRate)
inst:WatchWorldState("isdusk", UpdateHungerRate)
inst:WatchWorldState("isnight", UpdateHungerRate)
UpdateHungerRate(inst)

 

14 hours ago, Haruhi Kawaii said:

I haven't thoroughly tested this code yet, but it seems like it should work.
 

local function UpdateHungerRate(inst)
    if inst.components.hunger == nil then
        return
    end

    local burn_rate = 1.0
    local is_cave = TheWorld:HasTag("cave")

    if is_cave then
        burn_rate = 1.2
    else
        if TheWorld.state.isday then
            burn_rate = 2.0
        elseif TheWorld.state.isdusk then
            burn_rate = 1.5
        elseif TheWorld.state.isnight then
            burn_rate = 1.2
        end
    end

    inst.components.hunger.burnratemodifiers:SetModifier(inst, burn_rate, "hunger_burn")
end
-- In master_postinit--
inst:WatchWorldState("isday", UpdateHungerRate)
inst:WatchWorldState("isdusk", UpdateHungerRate)
inst:WatchWorldState("isnight", UpdateHungerRate)
UpdateHungerRate(inst)

 

After some playtesting, it seems like this works! Thank you so much!

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