Project Zomboid

Project Zomboid

CoolBag
Suur Tõll 7 Feb, 2022 @ 7:07am
Permanent cooling in storage cellar
Hello!

In my real life in garage I have the storage cellar. It’s like a fridge all year long.
The only PZ mod that have Storage Cellar is “Def's Long Term Survival [b41]”.

So I slightly modify your code to make Def’s cellars be always cooling. Temperature and aging depends on cellar level: more deeper cellar => more cooling. But if you throw enough IcePacket in any cellar level it will be cooled at max (0.2).

I hope that you will add same or similar possibility to make permanent coolers in next version of your great Cool mod ;)
require "coolbag" Coolbag.OPTIONS.PermCooler = { {"LTSStorageCellar01", 1. , 1. }, {"LTSStorageCellar02", 1. , 1. }, {"LTSStorageCellar03", 0.9, 0.9}, {"LTSStorageCellar04", 0.8, 0.8}, {"LTSStorageCellar05", 0.7, 0.7}, {"LTSStorageCellar06", 0.6, 0.6}, {"LTSStorageCellar07", 0.5, 0.5}, {"LTSStorageCellar08", 0.4, 0.4}, {"LTSStorageCellar09", 0.3, 0.3}, {"LTSStorageCellar10", 0.2, 0.2} } for k,v in pairs(Coolbag.OPTIONS.PermCooler) do Coolbag.addCoolerContainerType(v[1]); end function Coolbag.isCoolingContainer(container) if not container then return false end if not Coolbag.isCoolerContainer(container) then return false end local isCoolerThanBeingCool = false; if Coolbag.OPTIONS.Mode == 2 then--cheatin' mode isCoolerThanBeingCool = true; else--normal mode local containerType = container:getType(); for k,v in pairs(Coolbag.OPTIONS.PermCooler) do if containerType == v[1] then isCoolerThanBeingCool = true end end if isCoolerThanBeingCool == false then local nbIcePocket = container:getNumberOfItem("Base.IcePocket"); if nbIcePocket == 0 then return false end local maxCapacity = container:getCapacity(); local nbIcePocketRequired = math.ceil(maxCapacity/Coolbag.NBKgRefrigeratedPerPocket);--one Pocket per 10kg if Coolbag.OPTIONS.Verbose then print ("Coolbag.isCooling container = "..tostring(container or "nil").." "..container:getType().." "..nbIcePocket.."/"..nbIcePocketRequired.." "..maxCapacity.."/"..Coolbag.NBKgRefrigeratedPerPocket ); end isCoolerThanBeingCool = nbIcePocket >= nbIcePocketRequired;--ICE COLD ! end end Coolbag.updateCoolerContainer(container,isCoolerThanBeingCool);--this is bad "sugar" design. I'll regret it, I know it.--remove cooling property when IcePocket melts. return isCoolerThanBeingCool; end function Coolbag.setCooling(itemContainer, isCooling) local modDataCarrier = itemContainer:getContainingItem();--bag mod data is in ContainingItem if not modDataCarrier then modDataCarrier = itemContainer:getParent();--furniture mod data is in parent end if isCooling then if Coolbag.OPTIONS.Verbose then print ("Coolbag.setCooling from ".. tostring(nil2false(modDataCarrier:getModData().isCooling) and "true" or "false").." to "..tostring(isCooling and "true" or "false") ); end local inPermCooler = false; local CoolerTemperature = 0.2; local CoolerAgeFactor = 0.2; local containerType = itemContainer:getType(); for k,v in pairs(Coolbag.OPTIONS.PermCooler) do if containerType == v[1] then local nbIcePocket = itemContainer:getNumberOfItem("Base.IcePocket"); local maxCapacity = itemContainer:getCapacity(); local nbIcePocketRequired = math.ceil(maxCapacity/Coolbag.NBKgRefrigeratedPerPocket);--one Pocket per 10kg if nbIcePocket < nbIcePocketRequired then inPermCooler = true; CoolerTemperature = v[2]; CoolerAgeFactor = v[3]; end end end if inPermCooler then if Coolbag.OPTIONS.Verbose then print("Set temp/age by perm container"); end else if Coolbag.OPTIONS.Verbose then print("Set temp/age by pocket"); end end itemContainer:setCustomTemperature(CoolerTemperature);--fridge like temprature itemContainer:setAgeFactor(CoolerAgeFactor);--fridge like aging itemContainer:setCookingFactor(0.0);--fridge like cooking if modDataCarrier then modDataCarrier:getModData().isCooling = true; end else if Coolbag.OPTIONS.Verbose then print ("Coolbag.setCooling from ".. tostring(nil2false(modDataCarrier:getModData().isCooling) and "true" or "false").." to "..tostring(isCooling and "true" or "false") ); end itemContainer:setCustomTemperature(1.);--fridge like temprature itemContainer:setAgeFactor(1.0);--fridge like aging itemContainer:setCookingFactor(1.0);--fridge like cooking if modDataCarrier then modDataCarrier:getModData().isCooling = nil; end end --instanceFoodItem:getOutermostContainer().getParent().getSprite().getProperties().Is("IsFridge") end
Last edited by Suur Tõll; 7 Feb, 2022 @ 9:45am
< >
Showing 1-3 of 3 comments
Tchernobill  [developer] 8 Feb, 2022 @ 12:50pm 
Hi Suur Tõll,

1/ Food aging is not related to container temperature nor aging factor.
This is vanilla behaviour, I kept it in that mod to be vanilla friendly by using the same formula as Java food class updateAge() method.
see: Coolbag.computeNewFoodAgeInCoolbag for details
As a consequence, all your cellars are infinite coolers no matter the pockets.

2/ Mod current design does not allow to make changes on itemContainer (temperature, agefactor..) within setCooling.
Why?
setCooling is called (nearly) only when the cooling state changes.
To change this with minimum modification, you could alter Coolbag.computeNewFoodAgeInCoolbag to take into account the container temperature in the aging formula.

3/ Beware performances. (This is just a warning, not a statement that anything you did was bad)
I had to remove functionnalities because of the computational complexity they added and the CPU load this induced.
Mostly, there is a loop on a list of "poped food items" that is running and partially feeding both:
- the food aging modification.
- the pockets freezing / melting.
When you add a loop inside a function called intensively by that loop, you may add substancial CPU load.
It may be the case with isCoolingContainer and any change on computeNewFoodAgeInCoolbag.
Tchernobill  [developer] 8 Feb, 2022 @ 12:59pm 
Also I added an easy mode switch that makes all cooling containers permanent coolers.
I know what you ask is "in between" as it only would relate to some containers and not to all, but I feel like there is an infinity of inbetween and each user would have its own preference so I prefer to not try to make it all. (also I escape work and CPU load hasards that way :steammocking:)

Whatever, thanx for your interest in that mod and its insides.
I put a lot of time in it and while I was already very happy with its relative success, seeing your technical interest adds to it. :steamhappy:
Taligaro 9 Jul, 2022 @ 9:22am 
Any reason why your options are not showing up when I have the ModOptions mod active? I have other mods that use ModOptions and they are showing up.

In the Options menu under the Mods tab I see the ones I use, Eggon's Hotkeys, ExtraSauce Sac, GunFighter Options, QOL Equipment Tab, Rain Wash, Weapon Condition Iducator. Then Expanded Helicopter Events with it's own tab.

But your option dropdown, from looking at your files is two options, is not showing up anywhere in any menu or tab.

Also, I have tried loading just ModManager, ModOptions, and CoolBag. But still no options.
< >
Showing 1-3 of 3 comments
Per page: 1530 50