Jump to content

Recommended Posts

Hey there!

I have a perk for one of my older characters that I wanted to revisit for a quick fix, but it seems like my programming skills hit another brick wall with logical thinking.

I have three different consumables, and they're supposed to work like a coinflip when they're consumed: either double the consumer's corresponding stat (one consumables for each stat), or do absolutely nothing. It do works well with Sanity and Hunger, but it just never triggers for Health.

Here's the Health version:

Spoiler

local function DoubleOrNothing(inst,eater)
    if eater then
        local success = math.random() < 0.5
        if success then
            if eater.components.health then
                local old_max = eater.components.health.currenthealth
                eater.components.health.currenthealth = old_max * 2
            end
        end
    end
end

inst.components.edible:SetOnEatenFn(DoubleOrNothing)

and the Hunger Version:

Spoiler

 

local function DoubleONothing(inst,eater)
    if eater then
        local success = math.random() < 0.5
        if success then
            if eater.components.hunger then
                local old_max = eater.components.hunger.current
                eater.components.hunger.current = old_max * 2
            end
        end
    end
end

inst.components.edible:SetOnEatenFn(DoubleONothing)

 

The solution is probably something truly trivial, but I just can't find it.

Thanks in advance!

I originally tested it with the stat values set to zero like this:

Spoiler

    inst:AddComponent("edible")
    inst.components.edible.healthvalue = 0
    inst.components.edible.hungervalue = 0
    inst.components.edible.sanityvalue = 0
    inst.components.edible:SetOnEatenFn(DoubleOrNothing)

That way it didn't work at all, but once I removed the value lines above the SetOnEaten trigger, it do triggers the event, but without them, it also have a constant Hunger and Health value of 10, what I don't really want.

What's the next step in this case?

It's me! The Article Necromancer!

I just can 't find the solution to the problem. I added the item's lua file and the whole character's package to whom the item belongs to.

If somebody's able to identify the problem, I can thank it with a heart reaction.

luck_health.lua magicienne4.rar

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