BillBobJoy Posted March 14, 2014 Share Posted March 14, 2014 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. Link to comment https://forums.kleientertainment.com/forums/topic/32855-mod-help-how-would-you-check-the-state-of-something-every-time-the-game-loads/ Share on other sites More sharing options...
seronis Posted March 14, 2014 Share Posted March 14, 2014 SimPostInit Link to comment https://forums.kleientertainment.com/forums/topic/32855-mod-help-how-would-you-check-the-state-of-something-every-time-the-game-loads/#findComment-431613 Share on other sites More sharing options...
squeek Posted March 14, 2014 Share Posted March 14, 2014 (edited) SimPostInitYep. AddSimPostInit(function(inst) local season = GetSeasonManager():GetSeason()end) Edited March 14, 2014 by squeek Link to comment https://forums.kleientertainment.com/forums/topic/32855-mod-help-how-would-you-check-the-state-of-something-every-time-the-game-loads/#findComment-431681 Share on other sites More sharing options...
BillBobJoy Posted March 15, 2014 Author Share Posted March 15, 2014 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) Link to comment https://forums.kleientertainment.com/forums/topic/32855-mod-help-how-would-you-check-the-state-of-something-every-time-the-game-loads/#findComment-431935 Share on other sites More sharing options...
squeek Posted March 15, 2014 Share Posted March 15, 2014 (edited) 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 March 15, 2014 by squeek Link to comment https://forums.kleientertainment.com/forums/topic/32855-mod-help-how-would-you-check-the-state-of-something-every-time-the-game-loads/#findComment-431944 Share on other sites More sharing options...
BillBobJoy Posted March 15, 2014 Author Share Posted March 15, 2014 (edited) 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()endto 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 March 15, 2014 by BillBobJoy Link to comment https://forums.kleientertainment.com/forums/topic/32855-mod-help-how-would-you-check-the-state-of-something-every-time-the-game-loads/#findComment-431950 Share on other sites More sharing options...
BillBobJoy Posted March 15, 2014 Author Share Posted March 15, 2014 (edited) @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 usefulmrhat.zip Edited March 15, 2014 by BillBobJoy Link to comment https://forums.kleientertainment.com/forums/topic/32855-mod-help-how-would-you-check-the-state-of-something-every-time-the-game-loads/#findComment-431957 Share on other sites More sharing options...
squeek Posted March 15, 2014 Share Posted March 15, 2014 (edited) 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 March 15, 2014 by squeek Link to comment https://forums.kleientertainment.com/forums/topic/32855-mod-help-how-would-you-check-the-state-of-something-every-time-the-game-loads/#findComment-431965 Share on other sites More sharing options...
BillBobJoy Posted March 15, 2014 Author Share Posted March 15, 2014 (edited) @squeekwhen I run it I get a crash Log:log.txt it is having trouble with the if data.season == SEASONS.SUMMER then receiving a nil Edited March 15, 2014 by BillBobJoy Link to comment https://forums.kleientertainment.com/forums/topic/32855-mod-help-how-would-you-check-the-state-of-something-every-time-the-game-loads/#findComment-431973 Share on other sites More sharing options...
squeek Posted March 15, 2014 Share Posted March 15, 2014 @squeek when I run it I get a crash Are you using the edited version? I didn't have it right at first. Link to comment https://forums.kleientertainment.com/forums/topic/32855-mod-help-how-would-you-check-the-state-of-something-every-time-the-game-loads/#findComment-431987 Share on other sites More sharing options...
BillBobJoy Posted March 15, 2014 Author Share Posted March 15, 2014 (edited) @squeekNo, I missed the edit and just started to test it now, that seems like it did the trick. Thanks again! Edited March 15, 2014 by BillBobJoy Link to comment https://forums.kleientertainment.com/forums/topic/32855-mod-help-how-would-you-check-the-state-of-something-every-time-the-game-loads/#findComment-431988 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now