Jump to content

Recommended Posts

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

Oh oops e.e

local 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 = 30
local 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) --300
inst.components.health.maxhealth = math.ceil (100 + upgrades + 10) --250
inst.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 then
inst.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" then
if food and food.components.edible and food.components.edible.foodtype=="VEGGIE" then
 
--give an upgrade!
inst.level = inst.level + 1
applyupgrades(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)
end
end
 
local function onpreload(inst, data)
if data then
if data.level then
inst.level = data.level
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.currenthealth = 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)
end
end
 
end
-- This initializes for both clients and the host
local common_postinit = function(inst) 
-- Minimap icon
inst.MiniMapEntity:SetIcon( "esctemplate.tex" )
end
 
-- This initializes for the host only
local master_postinit = function(inst)
inst.level = 0
inst.components.eater:SetOnEatFn(oneat)
applyupgrades(inst)
-- choose which sounds this character will play
inst.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)

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

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

 

@Kzisor

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

 

@Crestonia

The 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 = 190

Now 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) = 1650

You can make the formula anyway you want as long as you have an idea of how you want health to be incremented.

 

@Forum Moderator

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

@Kzisor

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

@Ubiquitous

and using this 

-- will add 50 hp per upgrade
-- upgrades = 1
max_health = math.ceil(150 + (upgrades * 50))
-- 150 + (1 * 50) = 200
 
-- upgrades = 2
max_health = math.ceil(150 + (upgrades * 50))
-- 150 + (2 * 50) = 250
.
.
.
-- upgrades = 30
max_health = math.ceil(150 + (upgrades * 50))
-- 150 + (30 * 50) = 1650
Made my game crash. e.e

"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+10
If 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.

@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 by Kzisor

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