Jump to content

Changing Charakters Max HP by killing enemys


Recommended Posts

well, i wanted to creat a character wich get 1 maxhp for killing an enemy but i guess...

	local function stack(inst)
		inst.components.health:SetMaxHealth(inst.components.health.maxhealth + 1)
	end

but i guess, there is the problem, if i kill an enemy with, lets say, 50HP and my maxHP is 100, than my maxHP will set to 101 but my current HP too

how can i change my MaxHP value without changing my current HP

 

I was also doing this but "currenthealth" is not existing

local function stack(inst)
		x = currenthealth
		inst.components.health:SetMaxHealth(inst.components.health.maxhealth + 1)
		inst.components.health:SetVal(x)
	end

 

Edited by Hugostar33
Link to comment
Share on other sites

currenthealth is a variable in the health component, the same way the functions are accessed you can access it as well.

local function stack(inst)
		local x = inst.components.health.currenthealth
		inst.components.health:SetMaxHealth(inst.components.health.maxhealth + 1)
		inst.components.health:SetVal(x)
	end

Alternatively could do it similar to how wolfgang does it, percentage wise.

local function stack(inst)
    local health_percent = inst.components.health:GetPercent()
    inst.components.health:SetMaxHealth(inst.components.health.maxhealth + 1)
    inst.components.health:SetPercent(health_percent, true)
end

Hope it helps,

Cheers

Iron_Hunter

 

Edited by IronHunter
Typo
Link to comment
Share on other sites

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
 Share

×
  • Create New...