ThimblyNail Posted June 9, 2015 Share Posted June 9, 2015 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. Link to comment https://forums.kleientertainment.com/forums/topic/55009-character-upgrading-please-help/ Share on other sites More sharing options...
Virtualistik Posted June 9, 2015 Share Posted June 9, 2015 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 Link to comment https://forums.kleientertainment.com/forums/topic/55009-character-upgrading-please-help/#findComment-645482 Share on other sites More sharing options...
ThimblyNail Posted June 9, 2015 Author Share Posted June 9, 2015 I've been skimming through WX78's code and I was wondering inst.components.eater:SetCanEatGears() I couldn't find this anywhere else on that script. Could I change this to living logs? would that work? Link to comment https://forums.kleientertainment.com/forums/topic/55009-character-upgrading-please-help/#findComment-645622 Share on other sites More sharing options...
Virtualistik Posted June 9, 2015 Share Posted June 9, 2015 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")endAnd 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_HUGEThe 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. Link to comment https://forums.kleientertainment.com/forums/topic/55009-character-upgrading-please-help/#findComment-645629 Share on other sites More sharing options...
Blueberrys Posted June 9, 2015 Share Posted June 9, 2015 (edited) @ThimblyNailAdd 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 June 9, 2015 by Blueberrys Link to comment https://forums.kleientertainment.com/forums/topic/55009-character-upgrading-please-help/#findComment-645639 Share on other sites More sharing options...
ThimblyNail Posted June 10, 2015 Author Share Posted June 10, 2015 @Blueberrys Would this go under my character.lua script or my mainmod.lua? Link to comment https://forums.kleientertainment.com/forums/topic/55009-character-upgrading-please-help/#findComment-645693 Share on other sites More sharing options...
Blueberrys Posted June 10, 2015 Share Posted June 10, 2015 @ThimblyNail character.lua script, inside the fn function. Link to comment https://forums.kleientertainment.com/forums/topic/55009-character-upgrading-please-help/#findComment-645698 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now