Jump to content

Wettness of items and buildings, how to change?


Recommended Posts

Hi,

My aim is, to reduce the speed an item or structure next to a fire is getting wet.

yesterday I spent several hours studying the game code, to find out what exactly triggers the wetness of buildings and items while it rains...
I think one key function is in entityscripts.lua:

function EntityScript:GetIsWet()
    local replica = self.replica.inventoryitem or self.replica.moisture
    if replica ~= nil then
        return replica:IsWet()
    end
    return self:HasTag("wet") or TheWorld.state.iswet
end

So we have two trails here, the replica from inventoryitem and from moisture.
There is also a script called inventoryitemmoisture.lua.

But inventoryitemmoisture and miosture scripts both use a "onwet" function, where I was not able to further follow the trail...in moisture the function is:

local function onwet(self, wet)
    self.inst.replica.moisture:SetIsWet(wet)
end

but in the moisture class, line 58 is written: wet = onwet

I think we must find out what thing is calling this "onwet" function. But in the lua scripts there is nothing that is doing this...And I don't know for what to search now...
In inventoryitemmoisture it is the same problem, but there we have another function:

function InventoryItemMoisture:GetTargetMoisture()
    --If there is no owner, use world moisture
    --If owner is player, use player moisture
    --Otherwise (most likely a container), keep items dry
    local owner = self.inst.components.inventoryitem.owner
    return (owner == nil and (TheWorld.state.israining and TheWorld.state.wetness or 0))
        or (owner.components.moisture ~= nil and owner.components.moisture:GetMoisture())
        or 0
end

it seems that this means all items from a player will get the same wetness as the one from the character itself? I don't think this is what I experienced ingame. My items can be wet even if I'm already dry...

Link to comment
Share on other sites

I found out in iteminventorymoisture it automatically updates every ~0.4 seconds the wetness of items.
All items change their wetness slowly to the state of world wetness if they have no owner. And slowly to the wetness state of the owner, if they have one.

This class has two interesting values:
self.wetnessResistance  and  self.dryingResistance
by default they are 1

Now I would like to change these values with a mod. But how to change those variables? I only learned how to change function in components of the player. If I tried the following, but it is never called (maybe because it only checks the player char an not the items it should check...)

AddComponentPostInit("InventoryItemMoisture", function(self) 
    self.wetnessResistance =2
    self.inst.components.inventoryitemmoisture.wetnessResistance = 2
    local _UpdateMoisture = self.UpdateMoisture 
    self.UpdateMoisture = function(self)     
       print("UpdateM in mod")  -- is never printed and the wetnessResistance change is also not active...
       return _UpdateMoisture(self)
    end
end)

 

Edited by Serpens
Link to comment
Share on other sites

The wetness for items is solved, my code is now:

-- items get the wetness of the player. this mod decreases the speed the items adjust to the wetness of player if player is more wet. and increase this speed if player is more dry.., if in range of heat.
AddComponentPostInit("inventoryitemmoisture", function(self,inst) 
    if GetModConfigData("hot_dry_fire") or GetModConfigData("hot_dry_nature") then
        local heaterPower = (self.inst.components.temperature ~= nil and self.inst.components.temperature.externalheaterpower or 0) * GetModConfigData("hot_dry_fire") 
        local NatureTemp = GLOBAL.TheWorld.state.temperature * GetModConfigData("hot_dry_nature")
        local rate = heaterPower -- 0 to 150 ? -- at least 115 near a big firepit fire
            + math.max(0,NatureTemp-30) -- 0 to 60 ? - 30 because a temp of 15°C should not help drying 
        local multi = (80 + math.clamp(rate, 0, 200)) / 80 -- between 1 and ~ 3.5.  at a big firepit and 20°C it is 2.6875
        if multi > 1.01 then -- if less, no need to reduce...
            inst.components.inventoryitemmoisture.wetnessResistance = inst.components.inventoryitemmoisture.wetnessResistance * multi -- default is 1
            inst.components.inventoryitemmoisture.dryingResistance = inst.components.inventoryitemmoisture.dryingResistance * multi -- default is 1
        end
    end
end)

 

But the wetness of other things in the world is still a problem. I found out that in the function

function EntityScript:GetIsWet()
    local replica = self.replica.inventoryitem or self.replica.moisture
    if replica ~= nil then
        return replica:IsWet()
    end
    return self:HasTag("wet") or TheWorld.state.iswet
end

things like trees have replica==nil, so their wetness is always the wetness of the world. If world wetness is > 35, everything will be "wet" and if it is < 15 it will be dry again.
If I want to change this for things near a fire, I have to mod the GetIsWet function, but I don't know how:
http://forums.kleientertainment.com/topic/69205-possible-to-mod-entityscriptlua-function/

 

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
 Share

×
  • Create New...