DestroyerofNorth Posted August 3, 2015 Share Posted August 3, 2015 I want that my character lvl after "eating" electrical doodad how do i make this? and how to define how much health, sanity and hunger get increased? Link to comment https://forums.kleientertainment.com/forums/topic/56765-hcaracter-with-lvl-system/ Share on other sites More sharing options...
DDNW Posted August 7, 2015 Share Posted August 7, 2015 look on this problem in wx file. //steamapss/common/don`t starve Togehter/data/scripts/prefabs/wx78 there you have it all made Link to comment https://forums.kleientertainment.com/forums/topic/56765-hcaracter-with-lvl-system/#findComment-660883 Share on other sites More sharing options...
DestroyerofNorth Posted August 8, 2015 Author Share Posted August 8, 2015 do i need to replace something or only copy the text? Link to comment https://forums.kleientertainment.com/forums/topic/56765-hcaracter-with-lvl-system/#findComment-661179 Share on other sites More sharing options...
StarmanUltra Posted August 8, 2015 Share Posted August 8, 2015 (edited) It's more complicated than just copying some of WX-78's code. Electrical Doodads will also need to be made edible by your character. For testing purposes, start off with levelling via berries or something, then just make your character start with a pile of them. so basically in character.lua: local start_inv = {"berries","berries","berries","berries","berries",}local function upgrade(inst, food) local health_percent = inst.components.health:GetPercent() local hp = inst.components.health.maxhealth if inst.components.eater and food.prefab == "berries" then if inst.components.health.maxhealth <= 200 then inst.components.health.maxhealth = math.ceil(hp + 10) inst.components.health:SetPercent(health_percent) endend Then in master_postinit add:inst.components.eater:SetOnEatFn(upgrade)That should get you started! EDIT: turns out adding doodads as edible isn't terribly hard. In modmain.lua: function SetEat(prefab,health,hunger,sanity,tip)AddPrefabPostInit(prefab,function(inst)if not inst.components.edible theninst:AddComponent("edible")endinst.components.edible.healthvalue = healthinst.components.edible.hungervalue = hungerinst.components.edible.sanityvalue = sanityif tip theninst.components.edible.foodtype = tipendend)endSetEat("transistor",0,1,0,FOODTYPE.GENERIC)The problem, then, is that everybody can eat them... Edited August 8, 2015 by StarmanUltra Link to comment https://forums.kleientertainment.com/forums/topic/56765-hcaracter-with-lvl-system/#findComment-661310 Share on other sites More sharing options...
DestroyerofNorth Posted August 8, 2015 Author Share Posted August 8, 2015 ok but thx Link to comment https://forums.kleientertainment.com/forums/topic/56765-hcaracter-with-lvl-system/#findComment-661337 Share on other sites More sharing options...
DarkXero Posted August 8, 2015 Share Posted August 8, 2015 -- hunger, health, sanity-- based on level, WX gets new stats-- level is limited by 15local function applyupgrades(inst) -- max level is 15 local max_upgrades = 15 -- if level is higher than max, then level equals max inst.level = math.min(inst.level, max_upgrades) -- save percents because new max stats will keep current values local hunger_percent = inst.components.hunger:GetPercent() local health_percent = inst.components.health:GetPercent() local sanity_percent = inst.components.sanity:GetPercent() -- adjust max stats 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) -- restore old percents inst.components.hunger:SetPercent(hunger_percent) inst.components.health:SetPercent(health_percent) inst.components.sanity:SetPercent(sanity_percent) -- example: from 50 / 100 to 100 / 200 -- NOT: from 50 / 100 to 50 / 200; this is why we save percentend-- when eatinglocal function oneat(inst, food) -- if food is gears if food and food.components.edible and food.components.edible.foodtype == FOODTYPE.GEARS then -- raise level by one inst.level = inst.level + 1 -- adjust stats applyupgrades(inst) endend-- we preload values so level gets restoredlocal function onpreload(inst, data) -- if there's data, and a level saved if data ~= nil and data.level ~= nil then -- our level is the level saved inst.level = data.level -- we apply upgrades to the level saved applyupgrades(inst) -- re-set these from the save data, because of load-order clipping issues if data.health and data.health.health then inst.components.health:SetCurrentHealth(data.health.health) end if data.hunger and data.hunger.hunger then inst.components.hunger.current = data.hunger.hunger end if data.sanity and data.sanity.current then inst.components.sanity.current = data.sanity.current end inst.components.health:DoDelta(0) inst.components.hunger:DoDelta(0) inst.components.sanity:DoDelta(0) endend-- we save the level valuelocal function onsave(inst, data) data.level = inst.level > 0 and inst.level or nilend-- function ran in the host when the prefab is generated-- even if it's new in the server or reloading after logging offlocal function master_postinit(inst) -- we start at 0, if we had a level saved, we cover that in preload inst.level = 0 -- we can eat gears inst.components.eater:SetCanEatGears() -- we apply our level up function when eating inst.components.eater:SetOnEatFn(oneat) -- we set up basic values (upgrades for level 0) applyupgrades(inst) -- we have to save the level inst.OnSave = onsave -- we have to load the level inst.OnPreLoad = onpreloadendWX-78's level system. Link to comment https://forums.kleientertainment.com/forums/topic/56765-hcaracter-with-lvl-system/#findComment-661365 Share on other sites More sharing options...
DestroyerofNorth Posted August 8, 2015 Author Share Posted August 8, 2015 thx but i think that dont help me much Link to comment https://forums.kleientertainment.com/forums/topic/56765-hcaracter-with-lvl-system/#findComment-661384 Share on other sites More sharing options...
Maris Posted August 9, 2015 Share Posted August 9, 2015 thx but i think that dont help me much You have to read and understand the code if you want it to help you. Link to comment https://forums.kleientertainment.com/forums/topic/56765-hcaracter-with-lvl-system/#findComment-661474 Share on other sites More sharing options...
DestroyerofNorth Posted August 9, 2015 Author Share Posted August 9, 2015 I think i don't understand it. Link to comment https://forums.kleientertainment.com/forums/topic/56765-hcaracter-with-lvl-system/#findComment-661517 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