Jump to content

IsMasterSim and season change trigger


Recommended Posts

Hey guys, just wondering if anyone knows where I would need to place the IsMasterSim requirement in a component file, or would it go in modmain? Right now Nature's Wild still runs if you are the client, I think this is how to stop it.

 

Also, have been looking for a trigger/event to listen for when the season changes, but seasontick seems to go every day and had no results from _msadvanceseason either. Any ideas are appreciated.

 

Thanks.

Link to comment
Share on other sites

Hey guys, just wondering if anyone knows where I would need to place the IsMasterSim requirement in a component file, or would it go in modmain? Right now Nature's Wild still runs if you are the client, I think this is how to stop it.

 

Also, have been looking for a trigger/event to listen for when the season changes, but seasontick seems to go every day and had no results from _msadvanceseason either. Any ideas are appreciated.

 

Thanks.

Well, you should only be adding components at all in the master sim, so the requirement wouldn't go in the component, but in the prefab's fn (or postinit) in order to decide whether to add the component or not.

And you're looking for

inst:WatchWorldState("season", function(inst, season)    print("We have not entered: "..season)end)
Link to comment
Share on other sites

Well, you should only be adding components at all in the master sim, so the requirement wouldn't go in the component, but in the prefab's fn (or postinit) in order to decide whether to add the component or not.

And you're looking for

inst:WatchWorldState("season", function(inst, season)    print("We have not entered: "..season)end)

Ahhhh, that's good to know. Thanks @Simplex.

Link to comment
Share on other sites

Well this is not picking up the season change at all. Not sure what is wrong. Here are the things I have tried:

inst:WatchWorldState("iswinter", OnSeasonChange)inst:WatchWorldState("issummer", OnSeasonChange)inst:WatchWorldState("season", OnSeasonChange)inst:WatchWorldState("season", function (inst, season)self:OnSeasonChangeend)self.inst:ListenForEvent("ms_advanceseason", OnSeasonChange, TheWorld) self.inst:ListenForEvent("seasonChange", OnSeasonChange)

One time it triggered but only once. Not sure why it is not picking up the season change. Any suggestions?

Link to comment
Share on other sites

Well this is not picking up the season change at all. Not sure what is wrong. Here are the things I have tried:

inst:WatchWorldState("iswinter", OnSeasonChange)inst:WatchWorldState("issummer", OnSeasonChange)inst:WatchWorldState("season", OnSeasonChange)inst:WatchWorldState("season", function (inst, season)self:OnSeasonChangeend)self.inst:ListenForEvent("ms_advanceseason", OnSeasonChange, TheWorld) self.inst:ListenForEvent("seasonChange", OnSeasonChange)
One time it triggered but only once. Not sure why it is not picking up the season change. Any suggestions?

Have you used it like in my example, i.e. using the second parameter directly? You'll no longer get a "data" table, you'll get the name of the new season itself.

Link to comment
Share on other sites

Directly copied from walrus_camp.lua

inst:WatchWorldState("iswinter", OnIsWinter)local function OnIsWinter(inst)    --print("OnIsWinter", inst)    if inst:IsAsleep() then        UpdateCampOccupied(inst)        CheckSpawnHuntingParty(inst, nil, not TheWorld.state.isday)    endend

Here is another example from standardcomponents.lua

local function TogglePickable(pickable, iswinter)    pickable[iswinter and "Pause" or "Resume"](pickable)endfunction MakeNoGrowInWinter(inst)    inst.components.pickable:WatchWorldState("iswinter", TogglePickable)    TogglePickable(inst.components.pickable, TheWorld.state.iswinter)end

You could bypass that with the following:

inst:ListenForEvent("seasontick", OnSeasonTick)
Edited by Kzisor
Link to comment
Share on other sites

Have you used it like in my example, i.e. using the second parameter directly? You'll no longer get a "data" table, you'll get the name of the new season itself.

Yes I tried it. Even using just you example with only the print would not do anything. Do we need to listen or place this outside of the class constructor now, because I still have them in there.

@ProfFarnsworth, Maybe ms_setseason? I recall using that to change the season manually, but I'm not certain that's what gets pushed when they change naturally. 

 

Yes listening for setseason seems to do nothing as well.

 

Directly copied from walrus_camp.lua

inst:WatchWorldState("iswinter", OnIsWinter)local function OnIsWinter(inst)    --print("OnIsWinter", inst)    if inst:IsAsleep() then        UpdateCampOccupied(inst)        CheckSpawnHuntingParty(inst, nil, not TheWorld.state.isday)    endend

Here is another example from standardcomponents.lua

local function TogglePickable(pickable, iswinter)    pickable[iswinter and "Pause" or "Resume"](pickable)endfunction MakeNoGrowInWinter(inst)    inst.components.pickable:WatchWorldState("iswinter", TogglePickable)    TogglePickable(inst.components.pickable, TheWorld.state.iswinter)end

You could bypass that with the following:

inst:ListenForEvent("seasontick", OnSeasonTick)

Yeah I was looking at those codes as well to see how they detect seasons, but even when I listen for "issummer" and "iswinter" and have them both point to my function they never trigger.

 

For some reason the "seasontick" sends it's signal once every day, not every season.

 

Thanks for all the quick feedback guys.

Edited by ProfFarnsworth
Link to comment
Share on other sites

Yes I tried it. Even using just you example with only the print would not do anything. Do we need to listen or place this outside of the class constructor now, because I still have them in there.

 

Yes listening for setseason seems to do nothing as well.

Yeah I was looking at those codes as well to see how they detect seasons, but even when I listen for "issummer" and "iswinter" and have them both point to my function they never trigger.

 

For some reason the "seasontick" sends it's signal once every day, not every season.

 

Thanks for all the quick feedback guys.

Can I ask how are you testing that? Are you just sitting and waiting for the next season?

Link to comment
Share on other sites

I just push the next season through the console using TheWorld:PushEvent("ms_advanceseason").

This doesn't advance the season, it just increases the current season's day counter by 1. Use

TheWorld:PushEvent("ms_setseason", "winter")
If it still doesn't work, enter the following after the "ms_setseason" push:

TheWorld:PushEvent("seasondirty")
Do let me know if the "seasondirty" push was necessary; it shouldn't be.

And, of course, all of these commands should only be used on the server, they won't work on clients.

Link to comment
Share on other sites

Son of a B&%$&!!!!!

 

Alright, so that worked fine for the detection but for some reason the season is inverted. i.e.when I check for winter it triggers on the season change into summer, and vice versa. Not sure if this has anything to do with it:

local SEASONS = table.invert(SEASON_NAMES)

Either way, I made my code accommodating to it. Thanks again for all the help, each of you!!

Edited by ProfFarnsworth
Link to comment
Share on other sites

Son of a B&%$&!!!!!

 

Alright, so that worked fine for the detection but for some reason the season is inverted. i.e.when I check for winter it triggers on the season change into summer, and vice versa. Not sure if this has anything to do with it:

local SEASONS = table.invert(SEASON_NAMES)
Either way, I made my code accommodating to it. Thanks again for all the help, each of you!!

That's odd. No offence, but I'd say the fault lies somewhere in your code :razz:.

That table.invert simply inverts the key and values of a table. It's equivalent to:

function table.invert(t)    local u = {}    for k, v in pairs(t) do        u[v] = k    end    return uend
And, afterall, did you need to push "seasonsdirty" as well?
Link to comment
Share on other sites

That's odd. No offence, but I'd say the fault lies somewhere in your code :razz:.

That table.invert simply inverts the key and values of a table. It's equivalent to:

function table.invert(t)    local u = {}    for k, v in pairs(t) do        u[v] = k    end    return uend
And, afterall, did you need to push "seasonsdirty" as well?

 

 

None taken at all. Here is the code I use:

function GrasshopperSpawner:OnSeasonChange(inst, season)    --print("Season change detected")    --local season = data.season    --if season == SEASONS.winter then    if TheWorld.state.iswinter then        self:KillGrasshoppers()       else--if (SEASONS.spring ~= nil and season == SEASONS.spring) or (SEASONS.spring == nil and season == SEASONS.summer) then        self:SpawnGrasshopper()    endend

Ignore the commented stuff. With this when I push setseason, "summer", it runs KillGrasshoppers, changing to winter runs the "else" condition. I even have an if not TheWorld.state.iswinter check in SpawnGrasshoppers. When eliminating the "not", they spawn in summer.

 

Nope didn't need seasonsdirty to detect the change.

 

Link to comment
Share on other sites

None taken at all. Here is the code I use:

--snip--

Ignore the commented stuff. With this when I push setseason, "summer", it runs KillGrasshoppers, changing to winter runs the "else" condition. I even have an if not TheWorld.state.iswinter check in SpawnGrasshoppers. When eliminating the "not", they spawn in summer.

The issue with your code is that you're checking for TheWorld.state.iswinter but you have a "season" callback, and the "season" world state variable is updated before "iswinter". This means your callback runs before the game has the chance to update "iswinter". This should work as intended:

local function OnSeasonChange(inst, season)    local ghs = inst.components.grasshopperspawner    if not ghs then return end    if season == "winter" then        ghs:KillGrasshoppers()       else        ghs:SpawnGrasshopper()    endend
I also made it a standalone function instead of a component method because otherwise it wouldn't work as a callback (its first parameter would be the 'self' implicit parameter, not inst)

Nope didn't need seasonsdirty to detect the change.

That's good to know, I wasn't sure if the "dirty" event would be pushed on the server as well.

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