Crestonia Posted January 22, 2015 Share Posted January 22, 2015 I'm trying to configure the max HP Sanity and Hunger my character has. But it keeps going up 1 per level, I want it to go up by 2 or 5. Does anyone know how to do that?(If anyone knows, please post somewhere in prefab, I'm kindof clueless when it comes to scripting.) Link to comment https://forums.kleientertainment.com/forums/topic/49564-levels-are-confusing/ Share on other sites More sharing options...
Kzisor Posted January 22, 2015 Share Posted January 22, 2015 @Crestonia, upload your character.lua file so that others may take a look at your code to determine where it would be more efficient to help you. Link to comment https://forums.kleientertainment.com/forums/topic/49564-levels-are-confusing/#findComment-604842 Share on other sites More sharing options...
Crestonia Posted January 22, 2015 Author Share Posted January 22, 2015 Oh oops e.elocal 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/esctemplate.zip" ), Asset( "ANIM", "anim/ghost_esctemplate_build.zip" ),}local prefabs = {}local start_inv = {-- Custom starting items} local function applyupgrades(inst) local max_upgrades = 30local upgrades = 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 (150 + upgrades + 10) --300inst.components.health.maxhealth = math.ceil (100 + upgrades + 10) --250inst.components.sanity.max = math.ceil (90 + upgrades + 10) --240 inst.components.health:StartRegen(10, 11 - upgrades / 10) --1-5 inst.components.talker:Say("Level : ".. (inst.level)) if inst.level >29 theninst.components.talker:Say("Level : Max!")end inst.components.hunger:SetPercent(hunger_percent)inst.components.health:SetPercent(health_percent)inst.components.sanity:SetPercent(sanity_percent) end local function oneat(inst, food) --if food and food.components.edible and food.components.edible.foodtype == "HELLO" thenif food and food.components.edible and food.components.edible.foodtype=="VEGGIE" then --give an upgrade!inst.level = inst.level + 1applyupgrades(inst) inst.SoundEmitter:PlaySound("dontstarve/characters/wx78/levelup")--inst.HUD.controls.status.heart:PulseGreen()--inst.HUD.controls.status.stomach:PulseGreen()--inst.HUD.controls.status.brain:PulseGreen() --inst.HUD.controls.status.brain:ScaleTo(1.3,1,.7)--inst.HUD.controls.status.heart:ScaleTo(5,5,5)--inst.HUD.controls.status.stomach:ScaleTo(1.3,1,.7)endend local function onpreload(inst, data)if data thenif data.level theninst.level = data.levelapplyupgrades(inst)--re-set these from the save data, because of load-order clipping issuesif data.health and data.health.health then inst.components.health.currenthealth = data.health.health endif data.hunger and data.hunger.hunger then inst.components.hunger.current = data.hunger.hunger endif data.sanity and data.sanity.current then inst.components.sanity.current = data.sanity.current endinst.components.health:DoDelta(0)inst.components.hunger:DoDelta(0)inst.components.sanity:DoDelta(0)endend end-- This initializes for both clients and the hostlocal common_postinit = function(inst) -- Minimap iconinst.MiniMapEntity:SetIcon( "esctemplate.tex" )end -- This initializes for the host onlylocal master_postinit = function(inst)inst.level = 0inst.components.eater:SetOnEatFn(oneat)applyupgrades(inst)-- choose which sounds this character will playinst.soundsname = "willow"-- Stats inst.components.health:SetMaxHealth(100)inst.components.hunger:SetMax(150)inst.components.sanity:SetMax(90)end return MakePlayerCharacter("esctemplate", prefabs, assets, common_postinit, master_postinit, start_inv) Link to comment https://forums.kleientertainment.com/forums/topic/49564-levels-are-confusing/#findComment-604845 Share on other sites More sharing options...
Kzisor Posted January 22, 2015 Share Posted January 22, 2015 @Crestonia, this is where you would change it in your code. inst.components.hunger.max = math.ceil (150 + upgrades + 10) --300inst.components.health.maxhealth = math.ceil (100 + upgrades + 10) --250inst.components.sanity.max = math.ceil (90 + upgrades + 10) --240 math.ceil (x)Returns the smallest integer larger than or equal to x. Reference: http://www.lua.org/manual/5.1/manual.html# I'm not quite sure how you get 250 when you have 100 + upgrades + 10; it should be 1300 with a max upgrades of 30. Alternatively you might want to remove 'upgrades' from the equation as every time you upgrade you will receive more health. This isn't necessarily what you want to achieve with the number of upgrades set to 30 (30 x 30) at maximum upgrades you should receive 900 total health, not including any additional health. If we add the additional health (10 x 30) at maximum updates you should receive 300 total health. If we were to add those together it would be 1200 total health from upgrades, plus the starting health of 100. Alternatively you should try using:inst.components.health:SetMaxHealth(100 + upgrades + 10)inst.components.hunger:SetMax(150 + upgrades + 10 )inst.components.sanity:SetMax(90 + upgrades + 10) Instead of the following:inst.components.hunger.max = math.ceil (150 + upgrades + 10) --300inst.components.health.maxhealth = math.ceil (100 + upgrades + 10) --250inst.components.sanity.max = math.ceil (90 + upgrades + 10) --240 Try using an equation like the following which will give you a static health increase.-- This equation will add 50 health each level up.MATH_HEALTH = MAX_HEALTH + (MAX_HEALTH / UPGRADES) There is probably a better equation for doing something like this, but I don't want to get into advanced math in order to test a function. The more advanced your math the finer tuning you will be able to make the amount of health you get back. Link to comment https://forums.kleientertainment.com/forums/topic/49564-levels-are-confusing/#findComment-604854 Share on other sites More sharing options...
Ubiquitous Posted January 22, 2015 Share Posted January 22, 2015 @Crestonia, this is where you would change it in your code. inst.components.hunger.max = math.ceil (150 + upgrades + 10) --300inst.components.health.maxhealth = math.ceil (100 + upgrades + 10) --250inst.components.sanity.max = math.ceil (90 + upgrades + 10) --240 math.ceil (x)Returns the smallest integer larger than or equal to x. Reference: http://www.lua.org/manual/5.1/manual.html# I'm not quite sure how you get 250 when you have 100 + upgrades + 10; it should be 1300 with a max upgrades of 30. Alternatively you might want to remove 'upgrades' from the equation as every time you upgrade you will receive more health. This isn't necessarily what you want to achieve with the number of upgrades set to 30 (30 x 30) at maximum upgrades you should receive 900 total health, not including any additional health. If we add the additional health (10 x 30) at maximum updates you should receive 300 total health. If we were to add those together it would be 1200 total health from upgrades, plus the starting health of 100. Alternatively you should try using:inst.components.health:SetMaxHealth(100 + upgrades + 10)inst.components.hunger:SetMax(150 + upgrades + 10 )inst.components.sanity:SetMax(90 + upgrades + 10) Instead of the following:inst.components.hunger.max = math.ceil (150 + upgrades + 10) --300inst.components.health.maxhealth = math.ceil (100 + upgrades + 10) --250inst.components.sanity.max = math.ceil (90 + upgrades + 10) --240 Try using an equation like the following which will give you a static health increase.-- This equation will add 50 health each level up.MATH_HEALTH = MAX_HEALTH + (MAX_HEALTH / UPGRADES) There is probably a better equation for doing something like this, but I don't want to get into advanced math in order to test a function. The more advanced your math the finer tuning you will be able to make the amount of health you get back. @KzisorWhere are you getting the number 1300 from? Having the variable upgrades in his equation isn't an issue either since he has a static value set for the minimum value. @CrestoniaThe issue you are having is how you have your equation setup. This is essentially what you are telling it right now.-- upgrades = 1max_health = math.ceil(150 + upgrades + 10)-- 150 + 1 + 10 = 161 -- upgrades = 2max_health = math.ceil(150 + upgrades + 10)-- 150 + 2 + 10 = 162...-- upgrades = 30max_health = math.ceil(150 + upgrades + 10)-- 150 + 30 + 10 = 190Now I am not sure how you want to setup your health increase but lets say it is a static 50 hp/level as Kzisor had mentioned. Since you have a static base value you could simply multiply to the upgrades value.-- will add 50 hp per upgrade-- upgrades = 1max_health = math.ceil(150 + (upgrades * 50))-- 150 + (1 * 50) = 200 -- upgrades = 2max_health = math.ceil(150 + (upgrades * 50))-- 150 + (2 * 50) = 250...-- upgrades = 30max_health = math.ceil(150 + (upgrades * 50))-- 150 + (30 * 50) = 1650You can make the formula anyway you want as long as you have an idea of how you want health to be incremented. @Forum ModeratorThis is second time I try to preview a post I reply to and the tags seem to be broken in preview mode. I am not sure if final post will retain the broken tags but I apologize to anyone who has to see it without code blocks working. Link to comment https://forums.kleientertainment.com/forums/topic/49564-levels-are-confusing/#findComment-604879 Share on other sites More sharing options...
Kzisor Posted January 22, 2015 Share Posted January 22, 2015 @Ubiquitous, Yeah I see where I made the mistake in thinking it was using the maximum health value. I was looking at several things at once when I was replying to this (specifically wx78's code) and I got them mixed up. Link to comment https://forums.kleientertainment.com/forums/topic/49564-levels-are-confusing/#findComment-604888 Share on other sites More sharing options...
Crestonia Posted January 23, 2015 Author Share Posted January 23, 2015 @KzisorI tried to use the inst.components.health:SetMaxHealth(100 + upgrades + 10)inst.components.hunger:SetMax(150 + upgrades + 10 )inst.components.sanity:SetMax(90 + upgrades + 10) But all of them kept going up by just one.@Ubiquitousand using this -- will add 50 hp per upgrade-- upgrades = 1max_health = math.ceil(150 + (upgrades * 50))-- 150 + (1 * 50) = 200 -- upgrades = 2max_health = math.ceil(150 + (upgrades * 50))-- 150 + (2 * 50) = 250...-- upgrades = 30max_health = math.ceil(150 + (upgrades * 50))-- 150 + (30 * 50) = 1650Made my game crash. e.e Link to comment https://forums.kleientertainment.com/forums/topic/49564-levels-are-confusing/#findComment-605217 Share on other sites More sharing options...
SenL Posted January 23, 2015 Share Posted January 23, 2015 "inst.components.sanity:SetMax(90 + upgrades + 10) But all of them kept going up by just one." It's correct because if upgrades=1, then it's 90+1+10If upgrades=2, then it's 90+2+10 Crash? But what is "max_health"?Check the log. Also post the lua - that'll help us see issues. Link to comment https://forums.kleientertainment.com/forums/topic/49564-levels-are-confusing/#findComment-605235 Share on other sites More sharing options...
Kzisor Posted January 23, 2015 Share Posted January 23, 2015 (edited) @Crestonia, the reason why it's only increasing by 1 is because your equation is only telling it to increase by 1. 90+upgrades+10 is effectively 100+upgrades You need a more advanced equation if you are wanting to have it increase by more. Instead of a static number of 90 you need the equation to have the maxhealth value in it's place. inst.components.health:SetMaxHealth(inst.components.health.maxhealth + upgrades + 10) Edited January 23, 2015 by Kzisor Link to comment https://forums.kleientertainment.com/forums/topic/49564-levels-are-confusing/#findComment-605253 Share on other sites More sharing options...
Crestonia Posted January 23, 2015 Author Share Posted January 23, 2015 Thanks for all the help guys, It's fixed now ^ ^ Link to comment https://forums.kleientertainment.com/forums/topic/49564-levels-are-confusing/#findComment-605314 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