Jump to content

[help] can't make my perks apply


Recommended Posts

Hi there,

So i've been trying to make my charcter for don't starve, the art is working fine, the basic tunings are working, but i don't know how to make the special abilities work.

Here is what i wanted:

increase damage, speed, sanity loss and hunger rate when on low hunger

decrease damage, speed, sanity loss and hunger rate when on high hunger

make the character poop when hitting max hunger (maybe add a timer between each poop).

So, here is the code i came up with (based on what i found in other mods and the game files):

Quote


local MakePlayerCharacter = require "prefabs/player_common"


local assets = {

        Asset( "ANIM", "anim/player_basic.zip" ),
        Asset( "ANIM", "anim/player_idles_shiver.zip" ),
        Asset( "ANIM", "anim/player_actions.zip" ),
        Asset( "ANIM", "anim/player_actions_axe.zip" ),
        Asset( "ANIM", "anim/player_actions_pickaxe.zip" ),
        Asset( "ANIM", "anim/player_actions_shovel.zip" ),
        Asset( "ANIM", "anim/player_actions_blowdart.zip" ),
        Asset( "ANIM", "anim/player_actions_eat.zip" ),
        Asset( "ANIM", "anim/player_actions_item.zip" ),
        Asset( "ANIM", "anim/player_actions_uniqueitem.zip" ),
        Asset( "ANIM", "anim/player_actions_bugnet.zip" ),
        Asset( "ANIM", "anim/player_actions_fishing.zip" ),
        Asset( "ANIM", "anim/player_actions_boomerang.zip" ),
        Asset( "ANIM", "anim/player_bush_hat.zip" ),
        Asset( "ANIM", "anim/player_attacks.zip" ),
        Asset( "ANIM", "anim/player_idles.zip" ),
        Asset( "ANIM", "anim/player_rebirth.zip" ),
        Asset( "ANIM", "anim/player_jump.zip" ),
        Asset( "ANIM", "anim/player_amulet_resurrect.zip" ),
        Asset( "ANIM", "anim/player_teleport.zip" ),
        Asset( "ANIM", "anim/wilson_fx.zip" ),
        Asset( "ANIM", "anim/player_one_man_band.zip" ),
        Asset( "ANIM", "anim/shadow_hands.zip" ),
        Asset( "SOUND", "sound/sfx.fsb" ),
        Asset( "SOUND", "sound/wilson.fsb" ),
        Asset( "ANIM", "anim/beard.zip" ),

        Asset( "ANIM", "anim/wugul.zip" ),
}
local prefabs = {
    "poop"
}
local start_inv = {
    -- Custom starting items
}

    

local fn = function(inst)
    
    -- choose which sounds this character will play
    inst.soundsname = "wolfgang"

    -- Minimap icon
    inst.MiniMapEntity:SetIcon( "wugul.tex" )
    
    -- Stats    
    inst.components.health:SetMaxHealth(200)
    inst.components.hunger:SetMax(180)
    inst.components.sanity:SetMax(150)
    
    -- Damage multiplier (optional)
    inst.components.combat.damagemultiplier = 1
    
    -- Hunger rate (optional)
    inst.components.hunger.hungerrate = 1 * TUNING.WILSON_HUNGER_RATE
    
    -- Movement speed (optional)
end

-- poops when hit max hunger
local function poopfn(inst, food)
    if food and inst.components.hunger.current == 300 then
        local poo = SpawnPrefab("poop")
        poo.Transform:SetPosition(inst.Transform:GetWorldPosition())
        
    end
end

-- hunger stuff
local function onhungerchange(inst, data)
    -- weaker and slower when hunger high
    if inst.components.hunger.current > 120 then
            
            inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 0.8)
            inst.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE * 0.5)
            inst.components.combat.damagemultiplier = 0.8
                    
    
    -- stronger and faster when hunger low        
    elseif inst.components.hunger.current < 60 then
        
            inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 1.5)
            inst.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE * 1.25)
            inst.components.combat.damagemultiplier = 2
    end
end
            
        

return MakePlayerCharacter("wugul", prefabs, assets, fn, start_inv)

 

The game runs without crashing, but no special effect are applied.

If anyone can tell me what is wrong i'd appreciate it a lot !

Thanks guys.

 

Link to comment
Share on other sites

Well the reason it doesn't work is because all the functions you put activate the moment the character spawns in and pretty much become dormant throughout your play-through and that's not what you want. So you want a function that periodically checks your hunger stat so heres the code:

local MakePlayerCharacter = require "prefabs/player_common"


local assets = {

        Asset( "ANIM", "anim/player_basic.zip" ),
        Asset( "ANIM", "anim/player_idles_shiver.zip" ),
        Asset( "ANIM", "anim/player_actions.zip" ),
        Asset( "ANIM", "anim/player_actions_axe.zip" ),
        Asset( "ANIM", "anim/player_actions_pickaxe.zip" ),
        Asset( "ANIM", "anim/player_actions_shovel.zip" ),
        Asset( "ANIM", "anim/player_actions_blowdart.zip" ),
        Asset( "ANIM", "anim/player_actions_eat.zip" ),
        Asset( "ANIM", "anim/player_actions_item.zip" ),
        Asset( "ANIM", "anim/player_actions_uniqueitem.zip" ),
        Asset( "ANIM", "anim/player_actions_bugnet.zip" ),
        Asset( "ANIM", "anim/player_actions_fishing.zip" ),
        Asset( "ANIM", "anim/player_actions_boomerang.zip" ),
        Asset( "ANIM", "anim/player_bush_hat.zip" ),
        Asset( "ANIM", "anim/player_attacks.zip" ),
        Asset( "ANIM", "anim/player_idles.zip" ),
        Asset( "ANIM", "anim/player_rebirth.zip" ),
        Asset( "ANIM", "anim/player_jump.zip" ),
        Asset( "ANIM", "anim/player_amulet_resurrect.zip" ),
        Asset( "ANIM", "anim/player_teleport.zip" ),
        Asset( "ANIM", "anim/wilson_fx.zip" ),
        Asset( "ANIM", "anim/player_one_man_band.zip" ),
        Asset( "ANIM", "anim/shadow_hands.zip" ),
        Asset( "SOUND", "sound/sfx.fsb" ),
        Asset( "SOUND", "sound/wilson.fsb" ),
        Asset( "ANIM", "anim/beard.zip" ),

        Asset( "ANIM", "anim/wugul.zip" ),
}
local prefabs = {
    "poop"
}
local start_inv = {
    -- Custom starting items
}

    

local function onhungerchange (inst) ----what about inbetween? you could be stuck on high speed or slow speed if you exploit it
    if (inst.components.hunger:GetPercent() > .8) then  ----for greater 80% hunger
    inst.components.locomotor.walkspeed = 3.2
    inst.components.locomotor.runspeed = 3
    inst.components.combat.damagemultiplier = 0.8
    
    elseif (inst.components.hunger:GetPercent() < .4) then ----for less than 40% hunger
    inst.components.locomotor.walkspeed = 6
    inst.components.locomotor.runspeed = 7.5
    inst.components.combat.damagemultiplier = 2
end
end


local function poopfn(inst, food)
    if food and inst.components.hunger:GetPercent() == 1 then ---100% hunger but timing is tricky since the counter doesn't stop at all
        local poo = SpawnPrefab("poop")
        poo.Transform:SetPosition(inst.Transform:GetWorldPosition())
        
    end
end

local fn = function(inst)
    
    -- choose which sounds this character will play
    inst.soundsname = "wolfgang"

    -- Minimap icon
    inst.MiniMapEntity:SetIcon( "wugul.tex" )
    
    -- Stats    
    inst.components.health:SetMaxHealth(200)
    inst.components.hunger:SetMax(180)
    inst.components.sanity:SetMax(150)
inst:DoPeriodicTask(4, poopfn, nil, inst) ----every four seconds check for full hunger and poop but you lose one hunger per 6 seconds
inst:DoPeriodicTask(.5, onhungerchange, nil, inst) ---check your hunger every half second and apply the buffs and debuffs


end
            
        

return MakePlayerCharacter("wugul", prefabs, assets, fn, start_inv)

Few last notes your poop function was checking for 300 hunger which isn't possible as you set it to max 180, and you'll have to set a condition for inbetween 40 and 80 percent as if you hit 40% you can stay below 80% and keep the speed boost indefinitely or be stuck on slow avoiding the 40%.

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