Jump to content

How do I make a custom book that makes local rain / melts snow?


Recommended Posts

Hi guys, I want my Wanda character to be able to craft a scroll that forces precipitation locally (increasing farm yields and causing mushrooms to start growing again), and causes snow to melt (making continued farming possible during Winter).  Please help?  Cheers, Rusty

Edited by RustyNayle
Link to comment
Share on other sites

@RustyNayle, local rain is possible, however, it will require a good amount of effort in order for you to get it to work correctly. You will basically have to recreate the entire way weather works in order to have localized weather conditions.

 

I'd think "simply" making a prefab that spawns rain fx around it (or for the players around it) and causes nearby things to become wet (which is a mechanic I to this day do not understand) is sufficient. Of course, this prefab would have to disappear when real precip starts.

Link to comment
Share on other sites

I'd think "simply" making a prefab that spawns rain fx around it (or for the players around it) and causes nearby things to become wet (which is a mechanic I to this day do not understand) is sufficient.

 

The problem is with how things 'become' wet. It's so intertwined with the weather mechanics that creating said prefab is essentially creating a completely new weather system.

Link to comment
Share on other sites

Damn, I just wrote a whole bunch of stuff but I think Klei auto signed me out or something, so I lost it all!

 

Anyways, just quickly, I spent some time looking at the lines of code for global rain book of Charlie the Gardener (417049595), ability to fertilise during winter by Walter the Botanist (422744946), and Wren the Stormcaller (417238901) looking for some lines of code.

 

 

Charlie's charliebooks.lua :

 

function rainfn(inst, reader)
    local pt = Vector3(reader.Transform:GetWorldPosition())
 
    reader.components.sanity:DoDelta(-TUNING.SANITY_LARGE)
 
    local range = 90
    local ents = TheSim:FindEntities(pt.x, pt.y, pt.z, range)
    for k, v in pairs(ents) do
if v.components.burnable then
v.components.burnable:Extinguish()
end
end
TheWorld:PushEvent("ms_forceprecipitation")
    return true
end
 
function growfn(inst, reader)
    local pt = Vector3(reader.Transform:GetWorldPosition())
 
    reader.components.sanity:DoDelta(-TUNING.SANITY_LARGE)
 
    local range = 30
    local ents = TheSim:FindEntities(pt.x, pt.y, pt.z, range)
    for k, v in pairs(ents) do
        if v.components.pickable ~= nil then
            v.components.pickable:FinishGrowing()
        end
 
        if v.components.crop ~= nil then
            v.components.crop:DoGrow(TUNING.TOTAL_DAY_TIME * 3)
        end
        
        if v.components.growable ~= nil and v:HasTag("tree") and not v:HasTag("stump") then
            v.components.growable:DoGrowth()
        end
    end
    return true
end
 
 
Walter's modmain.lua :
 
AddComponentPostInit("crop", function(self)
    local old = self.Fertilize
    function self:Fertilize(fertilizer)
        local pt = self.inst:GetPosition()
        local ents = GLOBAL.TheSim:FindEntities(pt.x, pt.y, pt.z, 5, {"player", "greenthumb"}, {"playerghost"})
        if #ents > 0 then
            self.growthpercent = self.growthpercent + fertilizer.components.fertilizer.fertilizervalue * self.rate
            self.inst.AnimState:SetPercent("grow", self.growthpercent)
            if self.growthpercent >=1 then
                self.inst.AnimState:PlayAnimation("grow_pst")
                self:Mature()
                self.task:Cancel()
                self.task = nil
            end
            if (fertilizer.components.stackable ~= nil) then
                fertilizer.components.stackable:Get(1):Remove()
            end
            return true
        else
            return old(self, fertilizer)
        end
    end
end)
 
 
weather.lua from the C:\Program Files (x86)\Steam\steamapps\common\Don't Starve Together\data\scripts\components\ has 981 lines of code, I was trying to extract some of the code terminology such as wetness, moisture, pollen, snow.tex, mud.tex, puddles, etc

 

Anyway, I've wasted enough time typing this twice, I'll have to come back and look at this later.

Link to comment
Share on other sites

Gosh, it looks like there's others such as moisture.lua to look through as well...  I don't know if raising the local temperature is necessary as well as the rain to melt snow / make farms yieldable again in Winter.

 

Anyway, rather than actually simulating local rain over time, there could be one big instantaneous downpour effect that does something similar to Wickerbottom's Applied Agriculture (and Charlie's rainbook, which has similar effects included) with some of the following effects:

 

Pickables (grass, twigs, etc) finish growing

Farms and berry bushes mature (or have their day number tuned, which is what Wicker's book does?)

Mushrooms re-grow

Non-stump trees grow

 

As well as,

 

Characters and other prefabs in the area increase wetness

Snow melts

Puddles (mud) form

Firepit, camp fire and torch durability reduces (i.e. burn out)

Chance of lightning or frog rain

 

Here's the code from Wickerbottom's books.lua in the DST prefabs directory,

 

function growfn(inst, reader)
    local pt = Vector3(reader.Transform:GetWorldPosition())
 
    reader.components.sanity:DoDelta(-TUNING.SANITY_LARGE)
 
    local range = 30
    local ents = TheSim:FindEntities(pt.x, pt.y, pt.z, range)
    for k, v in pairs(ents) do
        if v.components.pickable ~= nil then
            v.components.pickable:FinishGrowing()
        end
 
        if v.components.crop ~= nil then
            v.components.crop:DoGrow(TUNING.TOTAL_DAY_TIME * 3, true)
        end
        
        if v.components.growable ~= nil and v:HasTag("tree") and not v:HasTag("stump") then
            v.components.growable:DoGrowth()
        end
    end
    return true
end
 
Edited by RustyNayle
Link to comment
Share on other sites

Thanks @Kzisor .  I'm supergreen to coding, if it weren't for the help from those such as @Zackreaver and @DarkXero, my Wanda mod character would have only been custom stats and starting inventory, but you guys are all so generously helping me to make her into a much more immersive playing experience.  @DarkXero , any idea how to make this book work?

Link to comment
Share on other sites

Guys, what do you think about local season? Is it possible in general?

 

Would require you to remove seasons from world_network and adding a player_seasons component or something.

 

The component would update itself when the player enters a new part of the map.

 

All season mechanics should depend on item/player position.

 

The mechanics are here already. Look up the areaaware component.

It helps the monkeys transform in nightmare areas when the phase is right.

Nightmare areas are rooms with "Nightmare" tag.

 

So to make seasonal biomes, you would have to go through all tasks and rooms, putting "autumn" (only autumn in the area), "winter", "spring", "summer", "autumn/winter (autumn then winter then autumn again cycle)", "autumn/winter/spring", "autumn/winter/spring/summer" (complete cycle in area) tags.

 

Then you have to edit all the world temperature and stuff depending on seasons, if needed. World temperature depends on season, so you would need player_worldtemperature component.

 

Basically, a lot of rewriting.

Link to comment
Share on other sites

So, are we talking about powerful spellbooks that actually add a temporary tag to the current area of turf to make it Spring on just those tiles; making it rain, causing snow to melt, mushrooms to regrow, flowers to multiply (pollinate), and farms to yield quicker?  What about a craftable turf that is Spring all the time using really rare items so they can only make enough for a couple of farms?

Edited by RustyNayle
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...