Jump to content

Question about weather


Recommended Posts

Hi,

I would like to add custom weather to my mod. I have some ideas in mind, but i don't know anything about how weather works.


One thing i would like to do is : wet snow. During winter i would like snow to give wetness, like it did in the first days of DS RoG beta. Since it make the game harder, i would also like this kind of weather to only happens after some time (so let say 40 days to avoid the first winter in a classic playstyle). Someone already has some experience with weather ? Any clue to where to start ? Is it a really big change ? (My modding skill aren't great, it could be an expert thing)

Thanks for any help :)

Link to comment
Share on other sites

GetMoistureRate() in the Moisture component checks whether it's raining. Try changing the first line to

if not (TheWorld.state.israining or (TheWorld.state.issnowing and TheWorld.state.cycles > 40)) then

 

Link to comment
Share on other sites

Can i do this by Addcomponentpostinit ?
I tried this :




local function SnowIsWet(component)

function Moisture:GetMoistureRate()
    if not (TheWorld.state.israining or (TheWorld.state.issnowing and TheWorld.state.cycles > 40)) then
        return 0
    end

    local waterproofmult =
        (   self.inst.components.sheltered ~= nil and
            self.inst.components.sheltered.sheltered and
            self.inst.components.sheltered.waterproofness or 0
        ) +
        (   self.inst.components.inventory ~= nil and
            self.inst.components.inventory:GetWaterproofness() or 0
        ) +
        (   self.inherentWaterproofness or 0
        )
    if waterproofmult >= 1 then
        return 0
    end

    local rate = easing.inSine(TheWorld.state.precipitationrate, self.minMoistureRate, self.maxMoistureRate, 1)
    return rate * (1 - waterproofmult)
end

end
AddComponentPostInit("moisture", SnowIsWet)

But got a crash :


[00:01:13]: error calling ComponentPostInit: moisture in mod SummerFloraFauna: 
[string "../mods/SummerFloraFauna/scripts/postinit.l..."]:183: attempt to index global 'Moisture' (a nil value)
LUA ERROR stack traceback:
        ../mods/SummerFloraFauna/scripts/postinit.lua(183,1)
        =(tail call) ?
        =[C] in function 'xpcall'
        scripts/mods.lua(131,1) in function 'fn'
        scripts/entityscript.lua(526,1) in function 'AddComponent'
        scripts/prefabs/player_common.lua(1810,1) in function 'fn'
        scripts/mainfunctions.lua(146,1)	
[00:01:13]: Disabling SummerFloraFauna because it had an error.	
[00:01:13]: [string "../mods/SummerFloraFauna/scripts/postinit.l..."]:183: attempt to index global 'Moisture' (a nil value)
LUA ERROR stack traceback:
        ../mods/SummerFloraFauna/scripts/postinit.lua(183,1)
        =(tail call) ?
        =[C] in function 'xpcall'
        scripts/mods.lua(131,1) in function 'fn'
        scripts/entityscript.lua(526,1) in function 'AddComponent'
        scripts/prefabs/player_common.lua(1810,1) in function 'fn'
        scripts/mainfunctions.lua(146,1)
[00:01:13]: [string "../mods/SummerFloraFauna/scripts/postinit.l..."]:183: attempt to index global 'Moisture' (a nil value)
LUA ERROR stack traceback:
        ../mods/SummerFloraFauna/scripts/postinit.lua(183,1)
        =(tail call) ?
        =[C] in function 'xpcall'
        scripts/mods.lua(131,1) in function 'fn'
        scripts/entityscript.lua(526,1) in function 'AddComponent'
        scripts/prefabs/player_common.lua(1810,1) in function 'fn'
        scripts/mainfunctions.lua(146,1)	

 

Link to comment
Share on other sites

local easing = GLOBAL.require"easing"

local function SnowIsWet(self)

	self.GetMoistureRate = function()
		if not (GLOBAL.TheWorld.state.israining or (GLOBAL.TheWorld.state.issnowing and GLOBAL.TheWorld.state.cycles > 40)) then
			return 0
		end

		local waterproofmult =
        (   self.inst.components.sheltered ~= nil and
            self.inst.components.sheltered.sheltered and
            self.inst.components.sheltered.waterproofness or 0
        ) +
        (   self.inst.components.inventory ~= nil and
            self.inst.components.inventory:GetWaterproofness() or 0
        ) +
        (   self.inherentWaterproofness or 0
        )
		if waterproofmult >= 1 then
			return 0
		end

		local rate = easing.inSine(GLOBAL.TheWorld.state.precipitationrate, self.minMoistureRate, self.maxMoistureRate, 1)
		return rate * (1 - waterproofmult)
	end

end

AddComponentPostInit("moisture", SnowIsWet)

Briefly tested and it seems to work.

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...