Jump to content

Recommended Posts

Hi, new to all this modding stuff.

 

I'm nearly finished my first mod but I wanted to add this feature to it. I'm trying to make a character that upgrades with living logs.

 

I've searched a lot of threads on how other people tried to apply upgrades to their characters and I haven't gotten much luck trying to get mine working.

 

I noticed that all the wood objects have a edible tag under wood. So I tried adding wood to my character's diet but then my character would refuse to eat regular food.

 

 

 

Any input would be much appreciated! Also! Is there another way to test a mod without booting up the game every time? I have been doing a lot of trial and error recently.

Taking apart existing code in the game might help.

 

WX78 upgrades using gears, so maybe you can try using their code from wx78.lua and modifying it to use living logs.

 

This seems to be most of the code important to WX78's updgrades:

local function applyupgrades(inst)    local max_upgrades = 15    inst.level = math.min(inst.level, max_upgrades)    local hunger_percent = inst.components.hunger:GetPercent()    local health_percent = inst.components.health:GetPercent()    local sanity_percent = inst.components.sanity:GetPercent()    inst.components.hunger.max = math.ceil(TUNING.WX78_MIN_HUNGER + inst.level * (TUNING.WX78_MAX_HUNGER - TUNING.WX78_MIN_HUNGER) / max_upgrades)    inst.components.health.maxhealth = math.ceil(TUNING.WX78_MIN_HEALTH + inst.level * (TUNING.WX78_MAX_HEALTH - TUNING.WX78_MIN_HEALTH) / max_upgrades)    inst.components.sanity.max = math.ceil(TUNING.WX78_MIN_SANITY + inst.level * (TUNING.WX78_MAX_SANITY - TUNING.WX78_MIN_SANITY) / max_upgrades)    inst.components.hunger:SetPercent(hunger_percent)    inst.components.health:SetPercent(health_percent)    inst.components.sanity:SetPercent(sanity_percent)endlocal function oneat(inst, food)        if food and food.components.edible and food.components.edible.foodtype == FOODTYPE.GEARS then        --give an upgrade!        inst.level = inst.level + 1        applyupgrades(inst)         inst.SoundEmitter:PlaySound("dontstarve/characters/wx78/levelup")    endendlocal function master_postinit(inst)    inst.level = 0    inst.components.eater.ignoresspoilage = true    inst.components.eater:SetCanEatGears()    inst.components.eater:SetOnEatFn(oneat)    applyupgrades(inst)end

I'm not sure I can help much with this part. The inst.components.eater bit reads like a filepath, so the function will be in scripts>components>eater.lua. The code in this file is 

function Eater:SetCanEatGears()    table.insert(self.preferseating, FOODTYPE.GEARS)    table.insert(self.caneat, FOODTYPE.GEARS)    self.inst:AddTag(FOODTYPE.GEARS.."_eater")end

And there is no equivalent function for living logs. You couldn't substitute FOODTYPE.GEARS for FOODTYPE.LIVINGLOGS as living logs, although they have the "edible" component, do not have their own specific foodtype like gears do:

    inst:AddComponent("edible")    inst.components.edible.foodtype = FOODTYPE.GEARS    inst.components.edible.healthvalue = TUNING.HEALING_HUGE    inst.components.edible.hungervalue = TUNING.CALORIES_HUGE    inst.components.edible.sanityvalue = TUNING.SANITY_HUGE

The only way I can immediately think of is to add a foodtype to living logs, but I don't know how you would do this without overriding livinglogs.lua.

@ThimblyNail

Add wood to foodprefs and ablefoods table.

table.insert(inst.components.eater.foodprefs, "WOOD")table.insert(inst.components.eater.ablefoods, "WOOD")

-

Check the food when eating.

local function OnEat(inst, food)	if food and food.prefab == "livinglog" then		-- Ate living log	endendinst.components.eater:SetOnEatFn(OnEat)
Edited by Blueberrys

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