Jump to content

Making an item a summer AND winter insulator


Recommended Posts

The game seems to only allow an item to be a summer insulator OR a winter insulator, not both. I was thinking the best way to do it would be to have a "listen for event" for the season, but then it would not be active during the end of spring when it is really hot or the beginning when it is cold, the inverse being true for autumn. I was wondering if it would be possible to have it listen for a temperature threshold, at which point it would change between insulation types.

 inst:AddComponent("insulator")    inst.components.insulator:SetInsulation(TUNING.INSULATION_LARGE)    inst.components.insulator:SetSummer()

This is what I found for the heat insulation.

 

 

This is what I found for the cold insulation.

    create_common(inst)    inst.components.equippable:SetOnEquip( onequip_winter )        inst.components.insulator:SetInsulation(TUNING.INSULATION_LARGE)    

I am not sure why the summer insulation has a "set summer"  thing attached but the winter thing has an "onequipe_winter" thing.

I looked into the base game codes for other instances where both tags were used but I found nothing outside of their uses in the puffy vest and floral shirt.

 

 

TL;DR

 

What do these two appendages to the insulation code do?

 

Would it be possible to have a listen for a temperature threshold at which point the insulation type would change?

 

 

 

Link to comment
Share on other sites

It looks like you're looking at the puffy vest and the floral shirt, right? Puffy vest is actually a pretty confusing item because it comes in two flavors: summer and winter. One seems to have higher insulation and one has lower insulation but it's waterproof. This makes it a bit more complicated to follow the code.

"AddComponent" is actually called in both objects. In the puffy vest, it's set in the create_common function. This makes the item in question an insulation object.

trunkvest.lua, line 39

hawaiianshirt.lua, line 45

the "SetInsulation" function is pretty obvious, it sets the item's insulation value. Higher is more insulat-ey. It's also called in both objects.

trunkvest.lua, lines 68 and 88

hawaiianshirt.lua, line 46

"SetSummer" function sets a flag in the insulation item, probably winter will make you cool slower, summer will make you heat slower. There is a similar function "SetWinter", but insulation items are set to winter by default, so the puffy vest doesn't need to call this.

hawaiianshirt.lua, line 47

The "SetOnEquip" registers a callback function that's automatically called when the item is equipped. It doesn't have anything to do with an insulation object, but rather an equipment object. This does things like updating your character to show it's wearing the item, or start consuming the item's fuel. This function is also called in both files.

trunkvest.lua, lines 66 and 86

hawaiianshirt.lua, line 36

For your mod, you will probably want to do a periodic check to see what the temperature is. If the temperature is greater than X (35 is a good average) then call SetSummer(), and if it's less, call SetWinter(). You could also dive deeper into the trunkvest.lua code and figure out when and how the flavors are created and used - that might be helpful.

Link to comment
Share on other sites

inst:AddComponent("insulator")    inst.components.insulator:SetInsulation(TUNING.INSULATION_LARGE)if GetSeasonManager() and GetSeasonManager():GetCurrentTemperature() > 35 then SetSummer()endif GetSeasonManager() and GetSeasonManager():GetCurrentTemperature() < 35 then SetWinter()end

This is basically what I tried. But it says that SetSummer and SetWinter are not declared variables. I think they are global variables, since they are weather related, so I think maybe I have to put something in my modmain.lua?  I tried looking through the base game files but the only time "SetSummer" is found is in the Hawaiian Shirt prefab, I found no results for the SetWinter variable.

 

I'm really not sure what I need to do to fix this. I am still learning lua, and everything I've learned so far has just been from logic and hacking bits of code together to try to form stuff.

Link to comment
Share on other sites

I think they are global variables, since they are weather related, so I think maybe I have to put something in my modmain.lua?

Actually they are not Weather related, they are related to the item's insulation component. You would need to call the functions on the component itself: inst.components.insulator:SetSummer().

For that matter, weather related things are also not global, they work off the SeasonManager, just like how you're accessing the world's temperature from the GetSeasonManager.

I'm curious to see the full code for this item. It may not work like you want it to depending on where you have the seasonal code. If you're running it in a PeriodicTask or as an on-equip function, then it should be fine. Otherwise the item might stay a summer-insulator permanently after you create it, even in the winter. Or vise-versa.

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"),

}

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")

owner.components.health.maxhealth = 20

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

if owner:HasTag("player") then

owner.AnimState:Hide("HEAD")

owner.AnimState:Show("HEAD_HAIR")

end

if inst.components.fueled then

inst.components.fueled:StartConsuming()

end

end

local 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 = 5

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

if owner:HasTag("player") then

owner.AnimState:Show("HEAD")

owner.AnimState:Hide("HEAD_HAIR")

end

end

local function spider_perish(inst)

inst:Remove()

--

end

local function fn(Sim)

local inst = CreateEntity()

local trans = inst.entity:AddTransform()

local anim = inst.entity:AddAnimState()

MakeInventoryPhysics(inst)

inst:AddTag("hat")

anim:SetBank("featherhat")

anim:SetBuild("wodbhat")

anim:PlayAnimation("anim")

inst:AddComponent("inspectable")

inst:AddTag("irreplaceable")

inst:AddComponent("inventoryitem")

inst.components.inventoryitem.atlasname = "images/inventoryimages/wodbhat.xml"

inst:AddComponent("equippable")

inst.components.equippable.equipslot = EQUIPSLOTS.HEAD

inst:AddComponent("insulator")

if GetSeasonManager() and GetSeasonManager():GetCurrentTemperature() > 35 then SetSummer()

end

if GetSeasonManager() and GetSeasonManager():GetCurrentTemperature() < 35 then SetWinter()

end

inst.components.insulator:SetInsulation(TUNING.INSULATION_LARGE)

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")

owner.components.health.maxhealth = 20

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

if owner:HasTag("player") then

owner.AnimState:Hide("HEAD")

owner.AnimState:Show("HEAD_HAIR")

end

if inst.components.fueled then

inst.components.fueled:StartConsuming()

end

end

local 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 = 5

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

if owner:HasTag("player") then

owner.AnimState:Show("HEAD")

owner.AnimState:Hide("HEAD_HAIR")

end

end

local function spider_perish(inst)

inst:Remove()

--

end

local function fn(Sim)

local inst = CreateEntity()

local trans = inst.entity:AddTransform()

local anim = inst.entity:AddAnimState()

MakeInventoryPhysics(inst)

inst:AddTag("hat")

anim:SetBank("featherhat")

anim:SetBuild("wodbhat")

anim:PlayAnimation("anim")

inst:AddComponent("inspectable")

inst:AddTag("irreplaceable")

inst:AddComponent("inventoryitem")

inst.components.inventoryitem.atlasname = "images/inventoryimages/wodbhat.xml"

inst:AddComponent("equippable")

inst.components.equippable.equipslot = EQUIPSLOTS.HEAD

inst:AddComponent("insulator")

if GetSeasonManager() and GetSeasonManager():GetCurrentTemperature() > 35 then SetSummer()

end

if GetSeasonManager() and GetSeasonManager():GetCurrentTemperature() < 35 then SetWinter()

end

inst.components.insulator:SetInsulation(TUNING.INSULATION_LARGE)

inst.components.equippable:SetOnEquip( onequip )

inst.components.equippable:SetOnUnequip( onunequip )

return inst

end

return Prefab( "common/inventory/wodbhat", fn, assets)

Link to comment
Share on other sites

First you should remove the GetSeasonManager lines from the fn function. They're useless there.

I'm not 100% sure about when the fn function is called, but my guess is it's only called once each time the object is instantiated (when it's spawned/crafted), or possibly just once when the script is processed (at mod load). I think it's the 1st scenario, but I'd like someone else to chime in and correct me. In either case, the function will not be updated for an item when the seasons change. It's set once and never changed. There's two possible solutions to this:

First solution is to add the following code into the onequip function:

if GetSeasonManager():GetCurrentTemperature > 35 then    inst.components.insulator:SetSummer()else    inst.components.insulator:SetWinter()end
That will make it so every time the item is equipped, it will check the temperature and switch to winter or summer mode. The drawback of this solution is if the player equips the item in summer, it will turn to summer mode. Then if the player keeps the item worn until winter, it will stay in summer mode until the player un-equips the item and re-equips it.

The second solution is to add the following lines to onequip:

inst.temperatureTask = inst:DoTaskInTime(5, function(inst)    if GetSeasonManager():GetCurrentTemperature > 35 then        inst.components.insulator:SetSummer()    else        inst.components.insulator:SetWinter()    endend)
And add the following lines to onunequip:

inst.temperatureTask:Cancel()
This will set a timer to check the temperature every second when the item is equipped. If it's summer, it will set to summer mode, and if it's winter, it'll switch to winter mode. This will be more automatic and not require the player to un-equip and re-equip the item. However, the drawback is the item will have a timer running all the time in the background when the item is equipped. The '5' argument is the number of seconds between each temperature check. At a fraction of a second, it will check more often but it'll be harder on the player's computer. Larger numbers will check less frequently but if it's too high, then it might not switch to winter mode or summer mode in time. I think 5 seconds is good, since temperature doesn't swing that fast. You can probably even put it up higher but 5 seconds is not that hard on the computer (some things check every .1 second).
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...