Jump to content

Recommended Posts

Hello, I want to check what season at the start of ever loaded game. I was thinking I could use the

 

ListenFor Event([event], [desired function])

 

But I cannot find an event synonymous with the start of a loaded save.

Would something like this work to switch between summer heat insulation and winter cold insulation?

function dynamicinsulatoin(inst)	if inst.prefab == "mrhat" then		if rog_enabled then			local season = GetSeasonManager()			if season:IsSummer() then				inst.components.insulator:SetSummer()			else				inst.components.insulator:SetWinter()			end		end	endendAddSimPostInit(dynamicinsulatoin)

No. You should never use PostInits on custom prefabs. There's no need. That stuff can just go in the prefab file.

For this, you'd want the following in your mrhat prefab:

 

-- somewhere above the fn function in the prefab filelocal function OnSeasonChange(inst, data)    if inst.components.insulator and inst.components.insulator.type then        if data.season == SEASONS.SUMMER then            inst.components.insulator:SetSummer()        else            inst.components.insulator:SetWinter()        end    endend-- inside the prefab's fn function:    inst:ListenForEvent("seasonChange", OnSeasonChange, GetWorld())
EDIT: The code above would make it change insulation as the seasons change. If you want it to only get set once on load and never change after that, then you would just do this in the prefab's fn function:

    if GetSeasonManager():IsSummer() then        inst.components.insulator:SetSummer()    else        inst.components.insulator:SetWinter()    end
Edited by squeek

Yeah I could not figure out how to get it to change on its own so originaly what i did was add 

if GetSeasonManager():IsSummer() then    inst.components.insulator:SetSummer()else    inst.components.insulator:SetWinter()end

to the onequip function, it worked but not if you already had the hat on when you loaded the save.

 

I'll try that out, thanks again

Edited by BillBobJoy

@squeek

 

I tried out the code you supplied and I seem to be having the same problem, when I posted this thread I was original attempting to get this to work using ListenForEvent but for some reason it was just ignoring it, I'm not sure if that's whats happening or what.

 

Edit:

 

here is the code I have, if it is useful

mrhat.zip

Edited by BillBobJoy

Forgot that events are handled weird, and it's the source that gets sent to the callback function instead of the listener.

This should work:

inst:ListenForEvent("seasonChange", function(_, data) OnSeasonChange(inst, data) end, GetWorld())
EDIT: Fixed. Edited by squeek

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
×
  • Create New...