Jump to content

Changing max health onequip?


Recommended Posts

I am trying to change the max health of my character based on weather he has the hat on.

local function onequip(inst, owner)        		owner.components.health.maxhealth = 145    end
local function onunequip(inst, owner)        		owner.components.health.maxhealth = 120			    end

This is what I came up with, it works, but the health is not updated until you reload the game. Then I looked at the meat effigy prefab to look for hints on changing maxhealth actively, but came up with nothing.

 

Is there a way I could do this in a way where I wouldn't have to reload the game for the max health to update? 

Link to comment
Share on other sites

Attach the whole modmain.lua, it is hard to tell what's wrong having only 2 functions in the post

I have the health loss/gain in my hat prefab.

 

 

Try pushing an 0-health Dodelta function to the health component, it should update your health...

EDIT: Like this:

inst.components.health:DoDelta(0, true)

 

 

I've never used a Dodelta function before. What does it do, and where/how do I use it?

Link to comment
Share on other sites

local assets={    Asset("ANIM", "anim/wodbhat.zip"),	Asset("IMAGE", "images/inventoryimages/wodbhat.tex"),    Asset("ATLAS", "images/inventoryimages/wodbhat.xml"),}--this is what happens when you equip the hatlocal function onequip(inst, owner)         owner.AnimState:OverrideSymbol("swap_hat", "wodbhat", "swap_hat")        owner.AnimState:Show("HAT")        owner.AnimState:Show("HAT_HAIR")        owner.AnimState:Hide("HAIR_NOHAT")        owner.AnimState:Hide("HAIR")                if owner:HasTag("player") then			owner.AnimState:Hide("HEAD")			owner.AnimState:Show("HEAD_HAIR")		end        		--this tells it to start losing durability when you equip it		if inst.components.fueled then			inst.components.fueled:StartConsuming()        		end				    end--this is what happens when you unequip the hatlocal function onunequip(inst, owner)         owner.AnimState:Hide("HAT")        owner.AnimState:Hide("HAT_HAIR")        owner.AnimState:Show("HAIR_NOHAT")        owner.AnimState:Show("HAIR")		owner.components.health.maxhealth = 20		if owner:HasTag("player") then	        owner.AnimState:Show("HEAD")			owner.AnimState:Hide("HEAD_HAIR")		end        		--this tells it to stop losing durability when you unequip it				    end		--I have no idea why this is called spider_perish but it helps the hat perish! -- Nik Mik here! It's because the top hat and spider hat use the same function to be destroyed when they run out of fuel.    local function spider_perish(inst)        --spider_disable(inst) ain't needed, Fiddoop. That's telling the item to go to another function. E.G if you had the spider_disable_inst and a function with the same name that made the character fart unicorns, the code on this line would tell it to do that function.        inst:Remove()	-- This destroys it.    end	local function fn(Sim)	local inst = CreateEntity()	local trans = inst.entity:AddTransform()	local anim = inst.entity:AddAnimState()    MakeInventoryPhysics(inst)        inst:AddTag("hat")    	--it is important that you use the original hat's prefab name for bank (if you used wodbhat then leave it featherhat)    anim:SetBank("featherhat")		--this is what you put in the build.bin when making the hat's .zip file    anim:SetBuild("wodbhat")		--this is just the animation it plays leave it where it's at unless you use a different hat and run into problems    anim:PlayAnimation("anim")  	    --you want to be able to be examined it right?    inst:AddComponent("inspectable")    	--to be honest I don't know what this does    inst:AddTag("irreplaceable") -- I think it means lureplants can't eat it, or something. Nik Mik.    	--this is so you can carry it in your inventory    inst:AddComponent("inventoryitem")    inst.components.inventoryitem.atlasname = "images/inventoryimages/wodbhat.xml"    	--this adds a sanity boost to your hat! this is half of what top hat gives    inst:AddComponent("dapperness")    inst.components.dapperness.dapperness = TUNING.DAPPERNESS_MED    	--this is so the game knows to put it on your head    inst:AddComponent("equippable")    inst.components.equippable.equipslot = EQUIPSLOTS.HEAD-- You can also do EQUIPSLOTS.BODY or EQUIPSLOTS.HANDS to make it use different slots.    	--this is so the game knows there is a onequip and onunequip function    inst.components.equippable:SetOnEquip( onequip )    inst.components.equippable:SetOnUnequip( onunequip )		    return instendreturn Prefab( "common/inventory/wodbhat", fn, assets) 

Thats my hat prefab.

Link to comment
Share on other sites

Ok, so, first of, I improved your prefab file:

local assets ={    Asset("ANIM",  "anim/wodbhat.zip"),    Asset("IMAGE", "images/inventoryimages/wodbhat.tex"),    Asset("ATLAS", "images/inventoryimages/wodbhat.xml"),}local function onequip(inst, owner)    owner.AnimState:OverrideSymbol("swap_hat", "wodbhat", "swap_hat")    owner.AnimState:Show("HAT")    owner.AnimState:Show("HAT_HAIR")    owner.AnimState:Hide("HAIR_NOHAT")    owner.AnimState:Hide("HAIR")         if owner:HasTag("player") then        owner.AnimState:Hide("HEAD")        owner.AnimState:Show("HEAD_HAIR")    end        if inst.components.fueled then        inst.components.fueled:StartConsuming()           endendlocal function onunequip(inst, owner)    owner.AnimState:Hide("HAT")    owner.AnimState:Hide("HAT_HAIR")    owner.AnimState:Show("HAIR_NOHAT")    owner.AnimState:Show("HAIR")    owner.components.health.maxhealth = 20    owner.components.health:DoDelta(0, true)  -- this updates the health badge     if owner:HasTag("player") then        owner.AnimState:Show("HEAD")        owner.AnimState:Hide("HEAD_HAIR")    end        if inst.components.fueled then        inst.components.fueled:StopConsuming()           endendlocal function on_perish(inst) -- this function should be called as 'SetDepletedFn' function of the fueled component    inst:Remove()endlocal function fn(Sim)    local inst = CreateEntity()    local trans = inst.entity:AddTransform()    local anim = inst.entity:AddAnimState()    MakeInventoryPhysics(inst)        anim:SetBank("featherhat")    anim:SetBuild("wodbhat")    anim:PlayAnimation("anim")         inst:AddTag("hat")    --inst:AddTag("irreplaceable")   -- it makes the item 'indestructible' - it's used only for special character items, like Lucy (Woodie), Lighter (Willow), Codex Umbra (Maxwell), Pile of Baloons (Wes), etc.        inst:AddComponent("inspectable")        inst:AddComponent("inventoryitem")    inst.components.inventoryitem.atlasname = "images/inventoryimages/wodbhat.xml"        inst:AddComponent("dapperness") -- this is for vanilla game dapperness...    inst.components.dapperness.dapperness = TUNING.DAPPERNESS_MED        inst:AddComponent("equippable")    inst.components.equippable.equipslot = EQUIPSLOTS.HEAD    inst.components.equippable.dapperness = TUNING.DAPPERNESS_MED  -- this is for RoG DLC daperness...        inst.components.equippable:SetOnEquip( onequip )    inst.components.equippable:SetOnUnequip( onunequip )    -- the whole prefab is missing "fueled" component, so it's not going to work at all...        return instend return Prefab( "common/inventory/wodbhat", fn, assets)

Second of... It's not a whole prefab file, it's not going to work correctly... Attach a whole file in the attachment, or PM it to me, I will try to help you with this...

Link to comment
Share on other sites

Ok, so, first of, I improved your prefab file:

local assets ={    Asset("ANIM",  "anim/wodbhat.zip"),    Asset("IMAGE", "images/inventoryimages/wodbhat.tex"),    Asset("ATLAS", "images/inventoryimages/wodbhat.xml"),}local function onequip(inst, owner)    owner.AnimState:OverrideSymbol("swap_hat", "wodbhat", "swap_hat")    owner.AnimState:Show("HAT")    owner.AnimState:Show("HAT_HAIR")    owner.AnimState:Hide("HAIR_NOHAT")    owner.AnimState:Hide("HAIR")         if owner:HasTag("player") then        owner.AnimState:Hide("HEAD")        owner.AnimState:Show("HEAD_HAIR")    end        if inst.components.fueled then        inst.components.fueled:StartConsuming()           endendlocal function onunequip(inst, owner)    owner.AnimState:Hide("HAT")    owner.AnimState:Hide("HAT_HAIR")    owner.AnimState:Show("HAIR_NOHAT")    owner.AnimState:Show("HAIR")    owner.components.health.maxhealth = 20    owner.components.health:DoDelta(0, true)  -- this updates the health badge     if owner:HasTag("player") then        owner.AnimState:Show("HEAD")        owner.AnimState:Hide("HEAD_HAIR")    end        if inst.components.fueled then        inst.components.fueled:StopConsuming()           endendlocal function on_perish(inst) -- this function should be called as 'SetDepletedFn' function of the fueled component    inst:Remove()endlocal function fn(Sim)    local inst = CreateEntity()    local trans = inst.entity:AddTransform()    local anim = inst.entity:AddAnimState()    MakeInventoryPhysics(inst)        anim:SetBank("featherhat")    anim:SetBuild("wodbhat")    anim:PlayAnimation("anim")         inst:AddTag("hat")    --inst:AddTag("irreplaceable")   -- it makes the item 'indestructible' - it's used only for special character items, like Lucy (Woodie), Lighter (Willow), Codex Umbra (Maxwell), Pile of Baloons (Wes), etc.        inst:AddComponent("inspectable")        inst:AddComponent("inventoryitem")    inst.components.inventoryitem.atlasname = "images/inventoryimages/wodbhat.xml"        inst:AddComponent("dapperness") -- this is for vanilla game dapperness...    inst.components.dapperness.dapperness = TUNING.DAPPERNESS_MED        inst:AddComponent("equippable")    inst.components.equippable.equipslot = EQUIPSLOTS.HEAD    inst.components.equippable.dapperness = TUNING.DAPPERNESS_MED  -- this is for RoG DLC daperness...        inst.components.equippable:SetOnEquip( onequip )    inst.components.equippable:SetOnUnequip( onunequip )    -- the whole prefab is missing "fueled" component, so it's not going to work at all...        return instend return Prefab( "common/inventory/wodbhat", fn, assets)

Second of... It's not a whole prefab file, it's not going to work correctly... Attach a whole file in the attachment, or PM it to me, I will try to help you with this...

I was trying to make it an infinite use hat.

Link to comment
Share on other sites

but if i have something like this:

local function OnUnequip(inst, owner)         owner.AnimState:Hide("ARM_carry")         owner.AnimState:Show("ARM_normal") 		owner.components.combat.damagemultiplier = 15    end

not health, but damagemultiplier. it doesn't want to update after i unequip an item

Link to comment
Share on other sites

becuse if i will add one more string in function: 

owner.components.sanity:SetMax(300)

- this string will work, but not the damagemultiplier. 

P.S. sorry, can't edit message, don't know how. That's why 2nd post

Link to comment
Share on other sites

It's probably because:

owner.components.sanity:SetMax(300)

... is calling a function called 'SetMax()' inside 'sanity' component, and that function has the logic to modify and update sanity properly...

 

This line:

owner.components.combat.damagemultiplier = 15

... modifies a 'damagemultiplier' variable directly, and that will probalby DO NOT update the damage - it needs to be updated manually...

 

Actually, looking into combat component, it SHOULD work... Hmm, you should make a new thread in modding about this one, because it's been a while since I wrote something in LUA...

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
×
  • Create New...