Jump to content

Recommended Posts

For just a specific character, or for everyone?

Here's some code that I use for my character that gets bonuses from eating rotten stuff:

local function foodbonus(inst, food)
  if inst.components.eater and food.prefab == "rottenegg" then
    inst.components.sanity:DoDelta(1)
    inst.components.health:DoDelta(2)
    inst.components.hunger:DoDelta(20)
  end
   if inst.components.eater and food.prefab == "spoiled_food" then
    inst.components.sanity:DoDelta(1)
    inst.components.health:DoDelta(2)
    inst.components.hunger:DoDelta(20)
  end
  if inst.components.eater and food.prefab == "wetgoop" then
    inst.components.sanity:DoDelta(0)
    inst.components.health:DoDelta(0)
    inst.components.hunger:DoDelta(10)
  end
end

this part is in master_postinit:

inst.components.eater:SetOnEatFn(foodbonus)

 

If you want to just change it for everyone, you should be able to use this:

AddPrefabPostInit("powcake", function(inst)
    inst.components.edible.healthvalue = 10
	inst.components.edible.sanityvalue = 0
    inst.components.edible.hungervalue = 0
end)

 

both of them are in the [character].lua. That line is under "local master_postinit = function(inst)". so, here is what mine looks like, with the relevant bits in bold:

 


local MakePlayerCharacter = require "prefabs/player_common"


local assets = {
    Asset("SCRIPT", "scripts/prefabs/player_common.lua"),
}
local prefabs = {}

-- Custom starting items
local start_inv = {
"carrot"
}

-- When the character is revived from human
local function onbecamehuman(inst)
    -- Set speed when reviving from ghost (optional)
    inst.components.locomotor:SetExternalSpeedMultiplier(inst, "wroach_speed_mod", 1)
end

local function onbecameghost(inst)
    -- Remove speed modifier when becoming a ghost
   inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "wroach_speed_mod")
end

-- When loading or spawning the character
local function onload(inst)
    inst:ListenForEvent("ms_respawnedfromghost", onbecamehuman)
    inst:ListenForEvent("ms_becameghost", onbecameghost)

    if inst:HasTag("playerghost") then
        onbecameghost(inst)
    else
        onbecamehuman(inst)
    end
end


-- This initializes for both the server and client. Tags can be added here.
local common_postinit = function(inst) 
    -- Minimap icon
    inst.MiniMapEntity:SetIcon( "wroach.tex" )
end

-- misc food bonuses
local function foodbonus(inst, food)
  if inst.components.eater and food.prefab == "rottenegg" then
    inst.components.sanity:DoDelta(1)
    inst.components.health:DoDelta(2)
    inst.components.hunger:DoDelta(20)
  end
   if inst.components.eater and food.prefab == "spoiled_food" then
    inst.components.sanity:DoDelta(1)
    inst.components.health:DoDelta(2)
    inst.components.hunger:DoDelta(20)
  end
  if inst.components.eater and food.prefab == "wetgoop" then
    inst.components.sanity:DoDelta(0)
    inst.components.health:DoDelta(0)
    inst.components.hunger:DoDelta(10)
  end
end

-- This initializes for the server only. Components are added here.
local master_postinit = function(inst)
    --Diet
    local everything = {
        FOODTYPE.GENERIC, 
        FOODTYPE.MEAT, 
        FOODTYPE.WOOD, 
        FOODTYPE.VEGGIE, 
        --FOODTYPE.ELEMENTAL, 
        --FOODTYPE.GEARS,
        FOODTYPE.HORRIBLE, 
        FOODTYPE.INSECT, 
        FOODTYPE.SEEDS, 
        FOODTYPE.RAW, 
        --FOODTYPE.BURNT, 
        FOODTYPE.ROUGHAGE,
        FOODTYPE.TRASH, --custom foodtype
    }
    inst.components.eater:SetDiet(everything)
    inst.components.eater.ignoresspoilage = true
    
    inst.components.eater:SetOnEatFn(foodbonus) -- for misc food bonuses
    
    inst.components.sanity.custom_rate_fn = function(inst)
        local light_delta = 0
        if TheWorld.state.isday then
            light_delta = TUNING.SANITY_NIGHT_MID
        end
        return light_delta
    end
    inst.components.sanity.night_drain_mult = 0
    
    -- choose which sounds this character will play
    inst.soundsname = "wroach"
    
    -- Uncomment if "wathgrithr"(Wigfrid) or "webber" voice is used
    -- inst.talker_path_override = "dontstarve_DLC001/characters/"
    
    -- Stats    
    inst.components.health:SetMaxHealth(140)
    inst.components.hunger:SetMax(300)
    inst.components.sanity:SetMax(150)
    
    inst:WatchWorldState("temperature", function()    inst.components.locomotor.runspeed = TUNING.WILSON_RUN_SPEED * math.min(math.max(0.75 + 0.5 * inst.components.temperature.current / 70, 0.75), 1.25)end, TheWorld)
    
    -- Damage multiplier (optional)
    inst.components.combat.damagemultiplier = 1
    
    -- Hunger rate (optional)
    --inst.components.hunger.hungerrate = 1 * TUNING.WILSON_HUNGER_RATE
    
    -- Speed and hunger rate adjust with temperature
    inst:WatchWorldState("temperature", function()
        inst.components.locomotor.runspeed = TUNING.WILSON_RUN_SPEED * math.min(math.max(0.75 + 0.5 * inst.components.temperature.current / 70, 0.75), 1.25)
        inst.components.hunger.hungerrate = TUNING.WILSON_HUNGER_RATE * math.min(math.max(0.75 + 0.5 * inst.components.temperature.current / 70, 0.75), 1.25)
    end, TheWorld)
    
    inst.OnLoad = onload
    inst.OnNewSpawn = onload
    
    -- Extra damage from spiders
    inst:ListenForEvent("attacked", function(inst, data)
        if data.attacker.prefab == "spider" then
            local extradamage = data.damage * 2
            inst.components.health:DoDelta(-extradamage)
        end
    end)
    
end

return MakePlayerCharacter("wroach", prefabs, assets, common_postinit, master_postinit, start_inv)
 

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