Jump to content

Recommended Posts

Hellooooo there!

I've noticed that Wolfgang's character has an inst.strength assigned for his mightiness. My question is: How can I assign another type of "stat" to him now that he used inst.strength?

Also, I'm very willing to learn so please do redirect me to any inst guides that is relevant. 

Thank you very much!! Have a great day!!!

Link to comment
https://forums.kleientertainment.com/forums/topic/53330-help-inststrength-types/
Share on other sites

What kind of stat are you looking for?

 

inst.strength is just a variable assigned on creation for wolfgang to store his status, so when applymightiness gets called on a hunger value change (the hungerdelta event gets pushed on the hungry entity when hunger changes, and wolfgang has a listener), depending on inst.strength, wolfgang will acquire new stats.

 

You can add all the variables you want to Wolfgang:

AddPrefabPostInit("wolfgang", function(inst)	inst.force = 1	inst.muscle = "Hello World"	inst.cheap = {1, 3, "Finland"}end)

Thank you for trying to help!!

 

Well actually I'm trying to combine a regen ability found in Patriarachnid's Regeneration Mutant character mod and I'm not sure how to combine it. So far, I've got this which gives me a entitiyscript.lua line 204 stack overflow error (with lines below the first error log saying something about setmaxhealth)

 

EDIT: I've now modified the code but Wolfgang seems to be stuck at changing mighty forms. If he loses a lot of hunger, he keeps change to wimpy....again and again. Lol Updated code below:

 

local easing = require("easing")local MakePlayerCharacter = require("prefabs/player_common")local assets ={    Asset("ANIM", "anim/wolfgang.zip"),    Asset("ANIM", "anim/wolfgang_skinny.zip"),    Asset("ANIM", "anim/wolfgang_mighty.zip"),    Asset("ANIM", "anim/player_wolfgang.zip"),    Asset("SOUND", "sound/wolfgang.fsb"),    Asset("ANIM", "anim/ghost_wolfgang_build.zip"), }-- Newly Added local function common_postinit(inst)     -- Enables Book Crafting (Still needs reader to enable book using)    inst:AddTag("bookbuilder")endlocal function applymightiness(inst)    local percent = inst.components.hunger:GetPercent()    local damage_mult = TUNING.WOLFGANG_ATTACKMULT_NORMAL    local hunger_rate = TUNING.WOLFGANG_HUNGER_RATE_MULT_NORMAL    local regen_hunger_rate = 1.5*TUNING.WILSON_HUNGER_RATE  -- Multiple for regen hunger rate    local health_max = TUNING.WOLFGANG_HEALTH_NORMAL    local scale = 1.25 --Previously 1    local mighty_scale = 1.75 --Previously 1.25    local wimpy_scale = 1 --Previously .9    if inst.strength == "mightyminregen" then        local mighty_start = (TUNING.WOLFGANG_START_MIGHTY_THRESH/TUNING.WOLFGANG_HUNGER)           local mighty_percent = math.max(0, (percent - mighty_start) / (1 - mighty_start))        damage_mult = easing.linear(mighty_percent, TUNING.WOLFGANG_ATTACKMULT_MIGHTY_MIN, TUNING.WOLFGANG_ATTACKMULT_MIGHTY_MAX - TUNING.WOLFGANG_ATTACKMULT_MIGHTY_MIN, 1)        health_max = easing.linear(mighty_percent, TUNING.WOLFGANG_HEALTH_NORMAL, TUNING.WOLFGANG_HEALTH_MIGHTY - TUNING.WOLFGANG_HEALTH_NORMAL, 1)         hunger_rate = easing.linear(mighty_percent, TUNING.WOLFGANG_HUNGER_RATE_MULT_NORMAL, TUNING.WOLFGANG_HUNGER_RATE_MULT_MIGHTY - TUNING.WOLFGANG_HUNGER_RATE_MULT_NORMAL, 1)          regen_hunger_rate = 1*regen_hunger_rate        scale = easing.linear(mighty_percent, 1, mighty_scale - 1, 1)           inst.components.health:StartRegen(0.5, 1)        inst.components.sanity.dapperness = (0)        local Temperature = Class(function(self, inst)        self.inherentinsulation = 0        end)    elseif inst.strength == "mightymedregen" then        local mighty_start = (TUNING.WOLFGANG_START_MIGHTY_THRESH/TUNING.WOLFGANG_HUNGER)           local mighty_percent = math.max(0, (percent - mighty_start) / (1 - mighty_start))        damage_mult = easing.linear(mighty_percent, TUNING.WOLFGANG_ATTACKMULT_MIGHTY_MIN, TUNING.WOLFGANG_ATTACKMULT_MIGHTY_MAX - TUNING.WOLFGANG_ATTACKMULT_MIGHTY_MIN, 1)        health_max = easing.linear(mighty_percent, TUNING.WOLFGANG_HEALTH_NORMAL, TUNING.WOLFGANG_HEALTH_MIGHTY - TUNING.WOLFGANG_HEALTH_NORMAL, 1)         hunger_rate = easing.linear(mighty_percent, TUNING.WOLFGANG_HUNGER_RATE_MULT_NORMAL, TUNING.WOLFGANG_HUNGER_RATE_MULT_MIGHTY - TUNING.WOLFGANG_HUNGER_RATE_MULT_NORMAL, 1)          regen_hunger_rate = 2*regen_hunger_rate        scale = easing.linear(mighty_percent, 1, mighty_scale - 1, 1)           inst.components.health:StartRegen(1, 1)         inst.components.sanity.dapperness = (0)        local Temperature = Class(function(self, inst)        self.inherentinsulation = TUNING.INSULATION_TINY        end)    elseif inst.strength == "mightymoreregen" then        local mighty_start = (TUNING.WOLFGANG_START_MIGHTY_THRESH/TUNING.WOLFGANG_HUNGER)           local mighty_percent = math.max(0, (percent - mighty_start) / (1 - mighty_start))        damage_mult = easing.linear(mighty_percent, TUNING.WOLFGANG_ATTACKMULT_MIGHTY_MIN, TUNING.WOLFGANG_ATTACKMULT_MIGHTY_MAX - TUNING.WOLFGANG_ATTACKMULT_MIGHTY_MIN, 1)        health_max = easing.linear(mighty_percent, TUNING.WOLFGANG_HEALTH_NORMAL, TUNING.WOLFGANG_HEALTH_MIGHTY - TUNING.WOLFGANG_HEALTH_NORMAL, 1)         hunger_rate = easing.linear(mighty_percent, TUNING.WOLFGANG_HUNGER_RATE_MULT_NORMAL, TUNING.WOLFGANG_HUNGER_RATE_MULT_MIGHTY - TUNING.WOLFGANG_HUNGER_RATE_MULT_NORMAL, 1)          regen_hunger_rate = 3*regen_hunger_rate        scale = easing.linear(mighty_percent, 1, mighty_scale - 1, 1)           inst.components.health:StartRegen(2.5, 1)        inst.components.sanity.dapperness = (-TUNING.DAPPERNESS_MED)        local Temperature = Class(function(self, inst)        self.inherentinsulation = TUNING.INSULATION_MED        end)    elseif inst.strength == "mightymaxregen" then        local mighty_start = (TUNING.WOLFGANG_START_MIGHTY_THRESH/TUNING.WOLFGANG_HUNGER)           local mighty_percent = math.max(0, (percent - mighty_start) / (1 - mighty_start))        damage_mult = easing.linear(mighty_percent, TUNING.WOLFGANG_ATTACKMULT_MIGHTY_MIN, TUNING.WOLFGANG_ATTACKMULT_MIGHTY_MAX - TUNING.WOLFGANG_ATTACKMULT_MIGHTY_MIN, 1)        health_max = easing.linear(mighty_percent, TUNING.WOLFGANG_HEALTH_NORMAL, TUNING.WOLFGANG_HEALTH_MIGHTY - TUNING.WOLFGANG_HEALTH_NORMAL, 1)         hunger_rate = easing.linear(mighty_percent, TUNING.WOLFGANG_HUNGER_RATE_MULT_NORMAL, TUNING.WOLFGANG_HUNGER_RATE_MULT_MIGHTY - TUNING.WOLFGANG_HUNGER_RATE_MULT_NORMAL, 1)          regen_hunger_rate = 4*regen_hunger_rate        scale = easing.linear(mighty_percent, 1, mighty_scale - 1, 1)           inst.components.health:StartRegen(5, 1)        inst.components.sanity.dapperness = (-TUNING.DAPPERNESS_HUGE)        local Temperature = Class(function(self, inst)        self.inherentinsulation = TUNING.INSULATION_LARGE        end)    elseif inst.strength == "normalminregen" then        damage_mult = TUNING.WOLFGANG_ATTACKMULT_NORMAL        health_max = TUNING.WOLFGANG_HEALTH_NORMAL        hunger_rate = TUNING.WOLFGANG_HUNGER_RATE_MULT_NORMAL        regen_hunger_rate = 1*regen_hunger_rate        scale = 1.25 --Previously 1        inst.components.health:StartRegen(0.5, 1)        inst.components.sanity.dapperness = (0)        local Temperature = Class(function(self, inst)        self.inherentinsulation = 0        end)    elseif inst.strength == "normalmedregen" then        damage_mult = TUNING.WOLFGANG_ATTACKMULT_NORMAL        health_max = TUNING.WOLFGANG_HEALTH_NORMAL        hunger_rate = TUNING.WOLFGANG_HUNGER_RATE_MULT_NORMAL        regen_hunger_rate = 2*regen_hunger_rate        scale = 1.25        inst.components.health:StartRegen(1, 1)         inst.components.sanity.dapperness = (0)        local Temperature = Class(function(self, inst)        self.inherentinsulation = TUNING.INSULATION_TINY        end)    elseif inst.strength == "normalmoreregen" then        damage_mult = TUNING.WOLFGANG_ATTACKMULT_NORMAL        health_max = TUNING.WOLFGANG_HEALTH_NORMAL        hunger_rate = TUNING.WOLFGANG_HUNGER_RATE_MULT_NORMAL        regen_hunger_rate = 3*regen_hunger_rate        scale = 1.25         inst.components.health:StartRegen(2.5, 1)        inst.components.sanity.dapperness = (-TUNING.DAPPERNESS_MED)        local Temperature = Class(function(self, inst)        self.inherentinsulation = TUNING.INSULATION_MED        end)    elseif inst.strength == "normalmaxregen" then        damage_mult = TUNING.WOLFGANG_ATTACKMULT_NORMAL        health_max = TUNING.WOLFGANG_HEALTH_NORMAL        hunger_rate = TUNING.WOLFGANG_HUNGER_RATE_MULT_NORMAL        regen_hunger_rate = 4*regen_hunger_rate        scale = 1.25        inst.components.health:StartRegen(5, 1)        inst.components.sanity.dapperness = (-TUNING.DAPPERNESS_HUGE)        local Temperature = Class(function(self, inst)        self.inherentinsulation = TUNING.INSULATION_LARGE        end)    elseif inst.strength == "wimpyminregen" then        local wimpy_start = (TUNING.WOLFGANG_START_WIMPY_THRESH/TUNING.WOLFGANG_HUNGER)         local wimpy_percent = math.min(1, percent/wimpy_start )        damage_mult = easing.linear(wimpy_percent, TUNING.WOLFGANG_ATTACKMULT_WIMPY_MIN, TUNING.WOLFGANG_ATTACKMULT_WIMPY_MAX - TUNING.WOLFGANG_ATTACKMULT_WIMPY_MIN, 1)        health_max = easing.linear(wimpy_percent, TUNING.WOLFGANG_HEALTH_WIMPY, TUNING.WOLFGANG_HEALTH_NORMAL - TUNING.WOLFGANG_HEALTH_WIMPY, 1)            hunger_rate = easing.linear(wimpy_percent, TUNING.WOLFGANG_HUNGER_RATE_MULT_WIMPY, TUNING.WOLFGANG_HUNGER_RATE_MULT_NORMAL - TUNING.WOLFGANG_HUNGER_RATE_MULT_WIMPY, 1)         regen_hunger_rate = 1*regen_hunger_rate        scale = easing.linear(wimpy_percent, wimpy_scale, 1 - wimpy_scale, 1)           inst.components.health:StartRegen(0.5, 1)        inst.components.sanity.dapperness = (0)        local Temperature = Class(function(self, inst)        self.inherentinsulation = 0        end)    elseif inst.strength == "wimpymedregen" then        local wimpy_start = (TUNING.WOLFGANG_START_WIMPY_THRESH/TUNING.WOLFGANG_HUNGER)         local wimpy_percent = math.min(1, percent/wimpy_start )        damage_mult = easing.linear(wimpy_percent, TUNING.WOLFGANG_ATTACKMULT_WIMPY_MIN, TUNING.WOLFGANG_ATTACKMULT_WIMPY_MAX - TUNING.WOLFGANG_ATTACKMULT_WIMPY_MIN, 1)        health_max = easing.linear(wimpy_percent, TUNING.WOLFGANG_HEALTH_WIMPY, TUNING.WOLFGANG_HEALTH_NORMAL - TUNING.WOLFGANG_HEALTH_WIMPY, 1)            hunger_rate = easing.linear(wimpy_percent, TUNING.WOLFGANG_HUNGER_RATE_MULT_WIMPY, TUNING.WOLFGANG_HUNGER_RATE_MULT_NORMAL - TUNING.WOLFGANG_HUNGER_RATE_MULT_WIMPY, 1)         regen_hunger_rate = 2*regen_hunger_rate        scale = easing.linear(wimpy_percent, wimpy_scale, 1 - wimpy_scale, 1)           inst.components.health:StartRegen(1, 1)         inst.components.sanity.dapperness = (0)        local Temperature = Class(function(self, inst)        self.inherentinsulation = TUNING.INSULATION_TINY        end)    elseif inst.strength == "wimpymoreregen" then        local wimpy_start = (TUNING.WOLFGANG_START_WIMPY_THRESH/TUNING.WOLFGANG_HUNGER)         local wimpy_percent = math.min(1, percent/wimpy_start )        damage_mult = easing.linear(wimpy_percent, TUNING.WOLFGANG_ATTACKMULT_WIMPY_MIN, TUNING.WOLFGANG_ATTACKMULT_WIMPY_MAX - TUNING.WOLFGANG_ATTACKMULT_WIMPY_MIN, 1)        health_max = easing.linear(wimpy_percent, TUNING.WOLFGANG_HEALTH_WIMPY, TUNING.WOLFGANG_HEALTH_NORMAL - TUNING.WOLFGANG_HEALTH_WIMPY, 1)            hunger_rate = easing.linear(wimpy_percent, TUNING.WOLFGANG_HUNGER_RATE_MULT_WIMPY, TUNING.WOLFGANG_HUNGER_RATE_MULT_NORMAL - TUNING.WOLFGANG_HUNGER_RATE_MULT_WIMPY, 1)         regen_hunger_rate = 3*regen_hunger_rate        scale = easing.linear(wimpy_percent, wimpy_scale, 1 - wimpy_scale, 1)           inst.components.health:StartRegen(2.5, 1)        inst.components.sanity.dapperness = (-TUNING.DAPPERNESS_MED)        local Temperature = Class(function(self, inst)        self.inherentinsulation = TUNING.INSULATION_MED        end)    elseif inst.strength == "wimpymaxregen" then        local wimpy_start = (TUNING.WOLFGANG_START_WIMPY_THRESH/TUNING.WOLFGANG_HUNGER)         local wimpy_percent = math.min(1, percent/wimpy_start )        damage_mult = easing.linear(wimpy_percent, TUNING.WOLFGANG_ATTACKMULT_WIMPY_MIN, TUNING.WOLFGANG_ATTACKMULT_WIMPY_MAX - TUNING.WOLFGANG_ATTACKMULT_WIMPY_MIN, 1)        health_max = easing.linear(wimpy_percent, TUNING.WOLFGANG_HEALTH_WIMPY, TUNING.WOLFGANG_HEALTH_NORMAL - TUNING.WOLFGANG_HEALTH_WIMPY, 1)            hunger_rate = easing.linear(wimpy_percent, TUNING.WOLFGANG_HUNGER_RATE_MULT_WIMPY, TUNING.WOLFGANG_HUNGER_RATE_MULT_NORMAL - TUNING.WOLFGANG_HUNGER_RATE_MULT_WIMPY, 1)         regen_hunger_rate = 4*regen_hunger_rate        scale = easing.linear(wimpy_percent, wimpy_scale, 1 - wimpy_scale, 1)           inst.components.health:StartRegen(5, 1)        inst.components.sanity.dapperness = (-TUNING.DAPPERNESS_HUGE)        local Temperature = Class(function(self, inst)        self.inherentinsulation = TUNING.INSULATION_LARGE        end)    end        inst:ApplyScale("mightiness", scale)    inst.components.hunger:SetRate(hunger_rate*TUNING.WILSON_HUNGER_RATE + regen_hunger_rate)    inst.components.combat.damagemultiplier = damage_mult    local health_percent = inst.components.health:GetPercent()    inst.components.health:SetMaxHealth(health_max)    inst.components.health:SetPercent(health_percent, true)endlocal function becomewimpy(inst, silent)    if inst.strength == "wimpyminregen" or inst.strength == "wimpymedregen" or inst.strength == "wimpymoreregen" or inst.strength == "wimpymaxregen" then        return    end    inst.AnimState:SetBuild("wolfgang_skinny")    if not silent then        inst.sg:PushEvent("powerdown")        inst.components.talker:Say(GetString(inst, "ANNOUNCE_NORMALTOWIMPY"))        inst.SoundEmitter:PlaySound("dontstarve/characters/wolfgang/shrink_medtosml")    end    inst.talksoundoverride = "dontstarve/characters/wolfgang/talk_small_LP"    inst.hurtsoundoverride = "dontstarve/characters/wolfgang/hurt_small"    if inst.strength == "normalminregen" then         inst.strength = "wimpyminregen"    elseif inst.strength == "normalmedregen" then         inst.strength = "wimpymedregen"    elseif inst.strength == "normalmoreregen" then         inst.strength = "wimpymoreregen"    elseif inst.strength == "normalmaxregen" then         inst.strength = "wimpymaxregen"    elseif inst.strength == "mightyminregen" then         inst.strength = "wimpyminregen"    elseif inst.strength == "mightymedregen" then         inst.strength = "wimpymedregen"    elseif inst.strength == "mightymoreregen" then         inst.strength = "wimpymoreregen"    elseif inst.strength == "mightymaxregen" then         inst.strength = "wimpymaxregen"    endendlocal function becomenormal(inst, silent)    if inst.strength == "normalminregen" or inst.strength == "normalmedregen" or inst.strength == "normalmoreregen" or inst.strength == "normalmaxregen" then        return    end    inst.AnimState:SetBuild("wolfgang")    if not silent then        if inst.strength == "mightyminregen" or inst.strength == "mightymedregen" or inst.strength == "mightymoreregen" or inst.strength == "mightymaxregen" then            inst.components.talker:Say(GetString(inst, "ANNOUNCE_MIGHTYTONORMAL"))            inst.sg:PushEvent("powerdown")            inst.SoundEmitter:PlaySound("dontstarve/characters/wolfgang/shrink_lrgtomed")        elseif inst.strength == "wimpyminregen" or inst.strength == "wimpymedregen" or inst.strength == "wimpymoreregen" or inst.strength == "wimpymaxregen" then            inst.components.talker:Say(GetString(inst, "ANNOUNCE_WIMPYTONORMAL"))            inst.sg:PushEvent("powerup")            inst.SoundEmitter:PlaySound("dontstarve/characters/wolfgang/grow_smtomed")        end    end    inst.talksoundoverride = nil    inst.hurtsoundoverride = nil    if inst.strength == "wimpyminregen" then         inst.strength = "normalminregen"    elseif inst.strength == "wimpymedregen" then         inst.strength = "normalmedregen"    elseif inst.strength == "wimpymoreregen" then         inst.strength = "normalmoreregen"    elseif inst.strength == "wimpymmaxregen" then         inst.strength = "normalmaxregen"    elseif inst.strength == "mightyminregen" then         inst.strength = "normalminregen"    elseif inst.strength == "mightymedregen" then         inst.strength = "normalmedregen"    elseif inst.strength == "mightymoreregen" then         inst.strength = "normalmoreregen"    elseif inst.strength == "mightymaxregen" then         inst.strength = "normalmaxregen"    endendlocal function becomemighty(inst, silent)    if inst.strength == "mightyminregen" or inst.strength == "mightymedregen" or inst.strength == "mightymoreregen" or inst.strength == "mightymaxregen" then        return    end    inst.AnimState:SetBuild("wolfgang_mighty")    if not silent then        inst.components.talker:Say(GetString(inst, "ANNOUNCE_NORMALTOMIGHTY"))        inst.sg:PushEvent("powerup")        inst.SoundEmitter:PlaySound("dontstarve/characters/wolfgang/grow_medtolrg")    end    inst.talksoundoverride = "dontstarve/characters/wolfgang/talk_large_LP"    inst.hurtsoundoverride = "dontstarve/characters/wolfgang/hurt_large"    if inst.strength == "normalminregen" then        inst.strength = "mightyminregen"    elseif inst.strength == "normalmedregen" then        inst.strength = "mightymedregen"    elseif inst.strength == "normalmoreregen" then        inst.strength = "mightymoreregen"    elseif inst.strength == "normalmaxregen" then        inst.strength = "mightymaxregen"    elseif inst.strength == "wimpyminregen" then        inst.strength = "mightyminregen"    elseif inst.strength == "wimpymedregen" then        inst.strength = "mightymedregen"    elseif inst.strength == "wimpymoreregen" then        inst.strength = "mightymoreregen"    elseif inst.strength == "wimpymaxregen" then        inst.strength = "mightymaxregen"    endendlocal function onhungerchange(inst, data, forcesilent)    if inst.sg:HasStateTag("nomorph") or        inst:HasTag("playerghost") or        inst.components.health:IsDead() then        return    end    local silent = inst.sg:HasStateTag("silentmorph") or not inst.entity:IsVisible() or forcesilent    if inst.strength == "mightyminregen" or inst.strength == "mightymedregen" or inst.strength == "mightymoreregen" or inst.strength == "mightymaxregen" then        if inst.components.hunger.current < TUNING.WOLFGANG_END_MIGHTY_THRESH then            if silent and inst.components.hunger.current < TUNING.WOLFGANG_START_WIMPY_THRESH then                becomewimpy(inst, true)            else                becomenormal(inst, silent)            end        end    elseif inst.strength == "wimpyminregen" or inst.strength == "wimpymedregen" or inst.strength == "wimpymoreregen" or inst.strength == "wimpymaxregen" then        if inst.components.hunger.current > TUNING.WOLFGANG_END_WIMPY_THRESH then            if silent and inst.components.hunger.current > TUNING.WOLFGANG_START_MIGHTY_THRESH then                becomemighty(inst, true)            else                becomenormal(inst, silent)            end        end    elseif inst.components.hunger.current > TUNING.WOLFGANG_START_MIGHTY_THRESH then        becomemighty(inst, silent)    elseif inst.components.hunger.current < TUNING.WOLFGANG_START_WIMPY_THRESH then        becomewimpy(inst, silent)    end    applymightiness(inst)end-- Heather's Regeneration function Part 1/2-- local function updatestats(inst)    --     if inst.healing == "minregen" then--         inst.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE * 1.5)--         inst.components.health:StartRegen(0.5, 1)--         inst.components.sanity.dapperness = (0)--         local Temperature = Class(function(self, inst)--         self.inherentinsulation = 0--         end)--     elseif inst.healing == "medregen" then--         inst.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE * 3)--         inst.components.health:StartRegen(1, 1) --         inst.components.sanity.dapperness = (0)--         local Temperature = Class(function(self, inst)--         self.inherentinsulation = TUNING.INSULATION_TINY--         end)            --     elseif inst.healing == "moreregen" then--         inst.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE * 4.5)--         inst.components.health:StartRegen(2.5, 1)--         inst.components.sanity.dapperness = (-TUNING.DAPPERNESS_MED)--         local Temperature = Class(function(self, inst)--         self.inherentinsulation = TUNING.INSULATION_MED--         end)            --     elseif inst.healing == "maxregen" then--         inst.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE * 6)--         inst.components.health:StartRegen(5, 1)--         inst.components.sanity.dapperness = (-TUNING.DAPPERNESS_HUGE)--         local Temperature = Class(function(self, inst)--         self.inherentinsulation = TUNING.INSULATION_LARGE--         end)--     end                 -- end--Heather's Regeneration function Part 2/2local function onhealthchange(inst, data)    if  inst.components.health:GetPercent() > 0.75 then        if inst.strength == "mightymedregen" then            inst.strength = "mightyminregen"            inst.components.talker:Say("Ahh, I'm finally recovering.")        elseif inst.strength == "mightyminregen" then            return        else            inst.strength = "mightyminregen"        end    elseif  inst.components.health:GetPercent() > 0.75 then        if inst.strength == "normalmedregen" then            inst.strength = "normalminregen"            inst.components.talker:Say("Ahh, I'm finally recovering.")        elseif inst.strength == "normalminregen" then            return        else            inst.strength = "normalminregen"        end    elseif  inst.components.health:GetPercent() > 0.75 then        if inst.strength == "wimpymedregen" then            inst.strength = "wimpyminregen"            inst.components.talker:Say("Ahh, I'm finally recovering.")        elseif inst.strength == "wimpyminregen" then            return        else            inst.strength = "wimpyminregen"        end    elseif inst.strength == "mightyminregen" then        if  inst.components.health:GetPercent() <= 0.75 then            inst.strength = "mightymedregen"            inst.components.talker:Say("Time to get serious.")        end            elseif inst.strength == "normalminregen" then        if  inst.components.health:GetPercent() <= 0.75 then            inst.strength = "normalmedregen"            inst.components.talker:Say("Time to get serious.")        end            elseif inst.strength == "wimpyminregen" then        if  inst.components.health:GetPercent() <= 0.75 then            inst.strength = "wimpymedregen"            inst.components.talker:Say("Time to get serious.")        end            elseif inst.strength == "mightymedregen" then        if  inst.components.health:GetPercent() <= 0.5 then            inst.strength = "mightymoreregen"            inst.components.talker:Say("RAWRRRRR!!")        end        elseif inst.strength == "normalmedregen" then        if  inst.components.health:GetPercent() <= 0.5 then            inst.strength = "normalmoreregen"            inst.components.talker:Say("RAWRRRRR!!")        end        elseif inst.strength == "wimpymedregen" then        if  inst.components.health:GetPercent() <= 0.5 then            inst.strength = "wimpymoreregen"            inst.components.talker:Say("RAWRRRRR!!")        end        elseif inst.strength == "mightymaxregen" then        if  inst.components.health:GetPercent() >= 0.25 then            inst.strength = "mightymoreregen"            inst.components.talker:Say("Argh, come on healing factor.")        end             elseif inst.strength == "normalmaxregen" then        if  inst.components.health:GetPercent() >= 0.25 then            inst.strength = "normalmoreregen"            inst.components.talker:Say("Argh, come on healing factor.")        end             elseif inst.strength == "wimpymaxregen" then        if  inst.components.health:GetPercent() >= 0.25 then            inst.strength = "wimpymoreregen"            inst.components.talker:Say("Argh, come on healing factor.")        end             elseif inst.strength == "mightymoreregen" then        if  inst.components.health:GetPercent() >= 0.5 then            inst.strength = "mightymedregen"            inst.components.talker:Say("Almost there, you little healing factor.")            elseif inst.strength == "normalmoreregen" then        if  inst.components.health:GetPercent() >= 0.5 then            inst.strength = "normalmedregen"            inst.components.talker:Say("Almost there, you little healing factor.")            elseif inst.strength == "wimpymoreregen" then        if  inst.components.health:GetPercent() >= 0.5 then            inst.strength = "wimpymedregen"            inst.components.talker:Say("Almost there, you little healing factor.")                elseif inst.components.health:GetPercent() < 0.25 then            inst.strength = "mightymaxregen"            inst.components.talker:Say("*Huff Huff*")        end         elseif inst.components.health:GetPercent() < 0.25 then            inst.strength = "normalmaxregen"            inst.components.talker:Say("*Huff Huff*")        end         elseif inst.components.health:GetPercent() < 0.25 then            inst.strength = "wimpymaxregen"            inst.components.talker:Say("*Huff Huff*")        end             end            applymightiness(inst) --Previously updatestats(inst)endlocal function onnewstate(inst)    if inst._wasnomorph ~= inst.sg:HasStateTag("nomorph") then        inst._wasnomorph = not inst._wasnomorph        if not inst._wasnomorph then            onhungerchange(inst)            onhealthchange(inst)        end    endendlocal function onbecamehuman(inst)    if inst._wasnomorph == nil then        inst.strength = "normalminregen"        inst._wasnomorph = inst.sg:HasStateTag("nomorph")        inst.talksoundoverride = nil        inst.hurtsoundoverride = nil        inst:ListenForEvent("hungerdelta", onhungerchange)        inst:ListenForEvent("healthdelta", onhealthchange)        inst:ListenForEvent("newstate", onnewstate)        onhungerchange(inst, nil, true)        onhealthchange(inst, nil, true)    endendlocal function onbecameghost(inst)    if inst._wasnomorph ~= nil then        inst.strength = "normalminregen"        inst._wasnomorph = nil        inst.talksoundoverride = nil        inst.hurtsoundoverride = nil        inst:RemoveEventCallback("healthdelta", onhealthchange)        inst:RemoveEventCallback("hungerdelta", onhungerchange)        inst:RemoveEventCallback("newstate", onnewstate)    endendlocal function onload(inst)    inst:ListenForEvent("ms_respawnedfromghost", onbecamehuman)    inst:ListenForEvent("ms_becameghost", onbecameghost)    if inst:HasTag("playerghost") then        onbecameghost(inst)    else        onbecamehuman(inst)    endendlocal function master_init(inst)    -- Enables Book Crafting (Still needs reader to enable book using)    inst:AddTag("bookbuilder")    --Can read Books    inst:AddComponent("reader")    inst.strength = "normalminregen"    inst._wasnomorph = nil    inst.talksoundoverride = nil    inst.hurtsoundoverride = nil    inst.components.health:StartRegen(1, 2)    inst.components.hunger:SetKillRate(3)    inst.components.hunger:SetMax(TUNING.WOLFGANG_HUNGER)    inst.components.hunger.current = TUNING.WOLFGANG_START_HUNGER    inst.components.sanity.night_drain_mult = 1.1    inst.components.sanity.neg_aura_mult = 1.1    local handle = inst.sg.sg.actionhandlers[ACTIONS.PICK]        handle.deststate = function(inst) return "doshortaction"    end    --Below two not needed since onnewstate is always checking for this    -- inst:ListenForEvent("healthdelta", onhealthchange)    -- inst:ListenForEvent("hungerdelta", onhungerchange)        inst.OnLoad = onload    inst.OnNewSpawn = onloadendreturn MakePlayerCharacter("wolfgang", nil, assets, nil, master_init)

Not sure how to fix the error. Any suggestions? Also, I'm guessing I'm doing some bad coding here and there or maybe everywhere but do please provide some solution along with your dissents. 

 

Thank You!!!!

Edited by Gigadroid

Well, I didnt really change your code (was I supposed to uncomment the green lines?).

I edited some little things, and then added

PrefabFiles = { "wolfgang" } in the modmain.

Then I put the wolfgang.lua in *your mod name*/scripts/prefabs

 

In general, when you are going to edit an already existing prefab, you use AddPrefabPostInit. But given how many changes you are going to do, we may as well overwrite the wolfgang prefab, like you are doing. Another option would be to make a different character.

 

What are you trying to do to Wolfgang?

What differences do you want to have between normal Wolfgang and your Wolfgang?

I noticed the code is similar to Wolfgang's, with small changes all across the board.

But I would like to hear it in natural language.

wolfgang.lua

Edited by DarkXero

Oh yeah I was supposed to put the wolfgang.lua into mod but I don't know how to call the original wolfgang.lua to mod it so I just replaced it. LOL 

Okay I tried your file and I'm back to square one. LOL Whenever Wolfgang gets hit to below 151/200 health the game will freeze with this error (sorry for picture, I don't know where to find log.txt HAHAHAHA shame on me)

 

 

post-414360-0-00170400-1430327820_thumb.

@Gigadroid, your log can be found in MyDocuments/Klei/DoNotStarveTogether.

 

What are you trying to do to Wolfgang?

What differences do you want to have between normal Wolfgang and your Wolfgang?

I noticed the code is similar to Wolfgang's, with small changes all across the board.

I would like to hear it in natural language.

 

We can split your strength into two variables, strength and regen, to reduce this code behemoth.

But I want to know what your intentions are here.

Alright I would like to implement Heather's regeneration abilities to Wolfgang. It relies on Health percent to affect Hunger rate to provide regeneration.

Thatnks for letting me know of the log.txt!!!

How would I go around introducing a new variable? I noticed you said I could introduce a new inst. anytime through AddPrefabsPostInit but how exactly do I for example add in inst.regen for different health percentages affecting hunger rate?

Thank you so much man! You've been suuuuper helpful so far!

@Gigadroid, use this in your modmain, simple health regen code:

-- When the health event gets pushed, a data table is passed-- that data table has newpercent, the new health percent value, we will use itlocal function onhealthchange(inst, data)	if data then		-- We evaluate if we have to change the heal factor, if we do, then we change it and push a message		-- if not, we do nothing		if (inst.healingfactor ~= 0) and (data.newpercent > 0.75) then			inst.healingfactor = 0			inst.components.talker:Say("Ahh, I feel great.")			-- We cancel the task if there's nothing to heal			if inst.healtask then				inst.healtask:Cancel()				inst.healtask = nil			end		elseif (inst.healingfactor ~= 0.1) and (0.5 < data.newpercent) and (data.newpercent <= 0.75) then			inst.healingfactor = 0.1			inst.components.talker:Say("That tickles.")		elseif (inst.healingfactor ~= 0.2) and (0.25 < data.newpercent) and (data.newpercent <= 0.5) then			inst.healingfactor = 0.2			inst.components.talker:Say("I can feel the pain.")		elseif (inst.healingfactor ~= 0.5) and (0 <= data.newpercent) and (data.newpercent <= 0.25) then			inst.healingfactor = 0.5			inst.components.talker:Say("IT HURTS!")		end	end	-- If there's no healing task, and we need one, we create one	if (not inst.healtask) and (inst.healingfactor ~= 0) then		-- We heal a inst.healingfactor quantity every 1 second		inst.healtask = inst:DoPeriodicTask(1, function()			inst.components.health:DoDelta(inst.healingfactor, true, "Healing factor")		end)	endend-- We cancel the healing task because ghosts have no healthlocal function onbecameghost(inst)	if inst.healtask then		inst.healtask:Cancel()		inst.healtask = nil	endend-- We add a healingfactor variable to the wolfgang prefab-- We add a function that acts on a health delta event (when your health changes)-- We add a function that acts when you die and become a ghostAddPrefabPostInit("wolfgang", function(inst)	inst.healingfactor = 0	inst:ListenForEvent("healthdelta", onhealthchange)	inst:ListenForEvent("ms_becameghost", onbecameghost)end)

Interesting. Testing it right after I ask this question. Thanks!!

 

If that is the case, why is it that heather.lua (attached below) does not require this method of regen? 

 

EDIT: Or its modmain.lua as well for that matter.

heather.lua

modmain.lua

Edited by Gigadroid

@Gigadroid, heather uses the startregen function of health, which is another way what I'm doing.

StartRegen uses (amount, period, interruptcurrentregen) as parameters (number, interval between health tick, this regen stacks with previous ones).

 

Instead of restoring an X fixed amount, I just go restoring as I see fit.

 

You use listeners, you make tasks, you do changes to your character.

 

You can make anything as you see fit, there are no static fixed ways.

@DarkXero Oh cool! But I'm still wondering how I did wrong. Don't get me wrong I really appreciate your help but I prefer to be spoonfed less, though that requires people reading my wall of code. D:

 

For example, in this context, how is it that I use the same function as Heather on Wolfgang but the regen method now fails?

 

Also, I just tested it and it appears that since it is a periodic task instead of a startregen, wolfgang keeps saying It tickles or Ahh, it feels great every time he heals by the inst.healingfactor amount. Perhaps startregen would be more appropriate in this context? How would that be possible?

Edited by Gigadroid

@Gigadroid, Wolfgang will only speak "That tickles" when the healing factor changes back to 0.1 from another different healing factor. What can happen, I guess, is that Wolfgang's max health goes up/down with his hunger, and that affects the percentage on the go. However I think unlikely it would cause a perma message appear.

 

Again, you can't just copypaste a function and believe it will do what its name says, with assumptions as how it will work. Function have requirements, and will produce results.

 

StartRegen has three parameters:

amount, period, interrupt.

If interrupt is true or nil (in this case), a new Regen will take the place of the other.

 

So, your hunger values change very quickly, mightiness gets applied repeatedly, and before enough time passes to regen that tiny little bit amount of health you passed, the task gets canceled. This is why Wolfgang's regen is failing.

 

I don't want to spoonfeed you, I'm more than happy to point out errors and exceptions. But you can't expect people to read your gigantic code stuff and help you when you don't even know what you are doing with certainty. Help yourself, and people will help you. So, I decided it would be better if we could extract from the heather code how the regen basically worked. On health changes, there is a function called that initiates a health regen task. Heather uses StartRegen, I decided to make another one, a more clear one.

 

Not only to build the character step by step, but to DEBUG step by step. I can't pinpoint how that line 204 stack overflow error happens because of how bloated the code is, I only know SetMaxHealth is involved, and it only happens in applymightiness. The solution would be to separate mightiness from regen, to see more easily why this happens.

Edited by DarkXero

@DarkXero OMG YES you're right it worked! Separating applymightiness and regen worked! I don't know why it's an error but it is. Alright now for the final challenge:

Whenever there is regen, there should be increased hunger. Combine this with Wolfgang's mighty hunger rate, I wish to get a might regen hunger rate. 

For example, looking at the code below:

 

local function applymightiness(inst)    local percent = inst.components.hunger:GetPercent()     local damage_mult = TUNING.WOLFGANG_ATTACKMULT_NORMAL    local hunger_rate = TUNING.WOLFGANG_HUNGER_RATE_MULT_NORMAL    local regen_hunger_rate = 1.5*TUNING.WILSON_HUNGER_RATE  -- Multiple for regen hunger rate    local health_max = TUNING.WOLFGANG_HEALTH_NORMAL    local scale = 1.25 --Previously 1     local mighty_scale = 1.75 --Previously 1.25    local wimpy_scale = 1 --Previously .9     if inst.strength == "mighty" then        local mighty_start = (TUNING.WOLFGANG_START_MIGHTY_THRESH/TUNING.WOLFGANG_HUNGER)           local mighty_percent = math.max(0, (percent - mighty_start) / (1 - mighty_start))        damage_mult = easing.linear(mighty_percent, TUNING.WOLFGANG_ATTACKMULT_MIGHTY_MIN, TUNING.WOLFGANG_ATTACKMULT_MIGHTY_MAX - TUNING.WOLFGANG_ATTACKMULT_MIGHTY_MIN, 1)        health_max = easing.linear(mighty_percent, TUNING.WOLFGANG_HEALTH_NORMAL, TUNING.WOLFGANG_HEALTH_MIGHTY - TUNING.WOLFGANG_HEALTH_NORMAL, 1)         hunger_rate = easing.linear(mighty_percent, TUNING.WOLFGANG_HUNGER_RATE_MULT_NORMAL, TUNING.WOLFGANG_HUNGER_RATE_MULT_MIGHTY - TUNING.WOLFGANG_HUNGER_RATE_MULT_NORMAL, 1)          scale = easing.linear(mighty_percent, 1, mighty_scale - 1, 1)       elseif inst.strength == "wimpy" then        local wimpy_start = (TUNING.WOLFGANG_START_WIMPY_THRESH/TUNING.WOLFGANG_HUNGER)         local wimpy_percent = math.min(1, percent/wimpy_start )        damage_mult = easing.linear(wimpy_percent, TUNING.WOLFGANG_ATTACKMULT_WIMPY_MIN, TUNING.WOLFGANG_ATTACKMULT_WIMPY_MAX - TUNING.WOLFGANG_ATTACKMULT_WIMPY_MIN, 1)        health_max = easing.linear(wimpy_percent, TUNING.WOLFGANG_HEALTH_WIMPY, TUNING.WOLFGANG_HEALTH_NORMAL - TUNING.WOLFGANG_HEALTH_WIMPY, 1)            hunger_rate = easing.linear(wimpy_percent, TUNING.WOLFGANG_HUNGER_RATE_MULT_WIMPY, TUNING.WOLFGANG_HUNGER_RATE_MULT_NORMAL - TUNING.WOLFGANG_HUNGER_RATE_MULT_WIMPY, 1)         scale = easing.linear(wimpy_percent, wimpy_scale, 1 - wimpy_scale, 1)       end         inst:ApplyScale("mightiness", scale)    inst.components.hunger:SetRate(hunger_rate*TUNING.WILSON_HUNGER_RATE + regen_hunger_rate)    inst.components.combat.damagemultiplier = damage_mult     local health_percent = inst.components.health:GetPercent()    inst.components.health:SetMaxHealth(health_max)    inst.components.health:SetPercent(health_percent, true)end

I wish to ask that if I have another function outside and below the code above, what would hunger_rate be?

 

How does local work? And the hunger_rate formula in applymightiness only stays in applymightiness?

If I have another function that is something like:

 

local function updatestats(inst)         if inst.regen == "minregen" then        inst.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE * 0 + TUNING.WILSON_HUNGER_RATE*hunger_rate)        inst.components.health:StartRegen(0.5, 1)        inst.components.sanity.dapperness = (0)        local Temperature = Class(function(self, inst)        self.inherentinsulation = 0        end)    endend

Which hunger_rate would it use? 


THANK YOU SO FAR!!!

Edited by Gigadroid

@Gigadroid,

if you use SetRate for hunger outside applymightiness, you want it to stack with the current hunger rate (from mightiness).

You can use:

local old = inst.components.hunger.hungerrateinst.components.hunger.hungerrate = old * 1.5

You just have to remember to do it once per regen, and to divide when exiting regen, to avoid that stacking on itself repeatedly.

 

The local keyword restricts the scope of a variable to the function it's inside.

 

The hunger_rate formula stays in applymightiness.

 

That last function would crash because hunger_rate is undefined, returning nil, and you can't use arithmetic on a nil value.

 

If you want your health regen to affect your hunger rate, then a reasonable choice is to bring regen inside applymightiness.

BUT, AND HEAR ME HERE, don't put it inside a mighty, normal or wimpy if.

 

But it down, before the SetRate, and then make another modifier that gets affected by the regen functions, and insert it in the parenthesis of SetRate.

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