Jump to content

Recommended Posts

New and kinda confused with how to do level system got most of my other code right but when I try changing parts of the upgrade system it fails to work

--Health, sanity boost (doesn't work yet)
local function applyupgrades(inst)
        
    local max_upgrades = 10
    local upgrades = math.min(inst.level, max_upgrades)

    inst.components.health.maxhealth = math.ceil (150 + upgrades * 20) --350
    inst.components.sanity.max = math.ceil (50 + upgrades * 15) --200
	
    local health_percent = inst.components.health:GetPercent()
    local sanity_percent = inst.components.sanity:GetPercent()

    inst.components.health:SetPercent(health_percent)
    inst.components.sanity:SetPercent(sanity_percent)
end

--Mandrake leveling
local function onpreload(inst, data)
	if data then
		if data.level then
			inst.level = data.level
			applyupgrades(inst)
			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

local function onsave(inst, data)
	data.level = inst.level
end

local function oneat(inst,food)
    if food and food.components.edible then
        if food.prefab == "mandrake" then
            inst.level = inst.level + 1
	        applyupgrades(inst)
        end
		if food.prefab == "cooked_mandrake" then
		    inst.level = inst.level + 1
			applyupgrades(inst)
		end
	end
end

 

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