Jump to content

Character Transformation Build Problems

Recommended Posts

I'm working on a character with a lot of Wolfgang-based code. For some reason, the transformations are in reverse - mighty when low hunger, weak when full. I also tied health to hunger and made sure that worked out.


I can jury-rig a solution by changing the sprites around, but I was wondering if there's a reason behind this besides me being pretty tired from working on this for a few hours.Turns out just copying the Wolfgang lua file doesn't work, and I learned which pieces of code are useful from the repeated crashes!


local easing = require("easing")local MakePlayerCharacter = require "prefabs/player_common"local assets = {        Asset( "ANIM", "anim/wex.zip" ),        Asset( "ANIM", "anim/ghost_wex_build.zip" ),	Asset( "ANIM", "anim/wex_wimpy.zip" ),	Asset( "ANIM", "anim/wex_mighty.zip" ),}local function applymightyness(inst)	local percent = inst.components.hunger:GetPercent()		local damage_mult = 1.25	local hunger_rate = 1	local health_max = 140	local speed = 1.3		if inst.strength == "mighty" then		local mighty_start = (200/250)			local mighty_percent = math.max(0, (percent - mighty_start) / (1 - mighty_start))		damage_mult = 1.8		health_max = easing.linear(mighty_percent, 140, 200 - 140, 1)			hunger_rate = 1.1		elseif inst.strength == "wimpy" then		local wimpy_start = (100/250)			local wimpy_percent = math.min(1, percent/wimpy_start )		damage_mult = 1		health_max = 100		hunger_rate = 0.8	end	inst.components.hunger:SetRate(hunger_rate*TUNING.WILSON_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)    if inst.strength == "wimpy" then	inst.AnimState:SetBuild("wex_wimpy")endlocal function becomenormal(inst)    if inst.strength == "normal" then	inst.AnimState:SetBuild("wex")endlocal function becomemighty(inst)    if inst.strength == "mighty" then	inst.AnimState:SetBuild("wex_mighty")endlocal function onhungerchange(inst, data)    if inst.strength == "mighty" then        if inst.components.hunger.current < 195 then            if inst.components.hunger.current < 95 then                becomewimpy(inst, true)            else                becomenormal(inst)            end        end    elseif inst.strength == "wimpy" then        if inst.components.hunger.current > 100 then            if inst.components.hunger.current > 200 then                becomemighty(inst, true)            else                becomenormal(inst)            end        end	elseif inst.components.hunger.current > 200 then        becomemighty(inst)    elseif inst.components.hunger.current < 95 then        becomewimpy(inst)    end	applymightyness(inst)end-- This initializes for the host onlylocal master_postinit = function(inst)	-- choose which sounds this character will play	inst.soundsname = "willow"	-- Stats		inst:AddComponent("reader")	inst.components.health:SetMaxHealth(140)	inst.components.hunger:SetMax(250)	inst.components.sanity:SetMax(250)	inst.components.temperature.inherentinsulation = 40	inst.components.builder.ancient_bonus = 4		inst.components.locomotor.walkspeed = (1.3 * TUNING.WILSON_WALK_SPEED)	inst.components.locomotor.runspeed = (1.3 * TUNING.WILSON_RUN_SPEED)			inst:ListenForEvent("hungerdelta", onhungerchange)endreturn MakePlayerCharacter("wex", prefabs, assets, common_postinit, master_postinit, start_inv)

Link to comment
Share on other sites

local function becomemighty(inst)     if inst.strength == "mighty" then     inst.AnimState:SetBuild("wex_mighty") end   local function onhungerchange(inst, data)       if inst.strength == "mighty" then         if inst.components.hunger.current < 195 then             if inst.components.hunger.current < 95 then                 becomewimpy(inst, true)             else                 becomenormal(inst)             end         end     elseif inst.strength == "wimpy" then         if inst.components.hunger.current > 100 then             if inst.components.hunger.current > 200 then                 becomemighty(inst, true)             else                 becomenormal(inst)             end         end     elseif inst.components.hunger.current > 200 then         becomemighty(inst)     elseif inst.components.hunger.current < 95 then         becomewimpy(inst)     end       applymightyness(inst) end



Your mightyness ends when your hunger is below 195 and it starts when it is below 95. Your wimpyness ends when your hunger is above 100 and starts when it is below 200. See the problem? :-)





  elseif inst.components.hunger.current > 200 then         becomemighty(inst)     elseif inst.components.hunger.current < 95 then

The first elseif value should be the same as

            if inst.components.hunger.current < 95 then

Here's how my similiar character works (for better understanding) :


    if inst.strength == "mighty" then        if inst.components.sanity.current < 115 then -- Determines when mightyness ends            if silent and inst.components.sanity.current > 120 then -- Determines when mightyness starts                becomemighty(inst, true)            else                becomenormal(inst, silent)            end        end    elseif inst.strength == "wimpy" then        if inst.components.sanity.current > 55 then -- Determines when wimpyness ends            if silent and inst.components.sanity.current < 50 then -- Determines when wimpyness starts                becomewimpy(inst, true)            else                becomenormal(inst, silent)            end        endelseif inst.components.sanity.current > 120 then        becomemighty(inst, silent)    elseif inst.components.sanity.current < 50 then        becomewimpy(inst, silent)    end
Edited by Thibooms
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

  • Create New...