Jump to content

[Question] Make a function similar to "MakeNoGrowInWinter" for others seasons ?


Recommended Posts

Hi,

I would like to add some plants into my world. For diversity and balance, i want them to not grow during some seasons, like summer and autumn. So there is a   "MakeNoGrowInWinter(inst)" that look like what i want, but i have two questions :

 


function MakeNoGrowInWinter(inst)
    inst.components.pickable:WatchWorldState("iswinter", TogglePickable)
    TogglePickable(inst.components.pickable, TheWorld.state.iswinter)
end


local function TogglePickable(pickable, iswinter)
    if iswinter then
        pickable:Pause()
    else
        pickable:Resume()
    end
end

This is the MakeNoGrowInWinter function and the related function.

First question, how does it works ? It seems to pause and resume pickable function, meaning that it will "disable" the time before regen and all this stuff ?

Second question, if i want to do a similar function, i see what code i must have, more or less, but i don't see where to put it. The MakeNoGrowInWinter is in a data/script/standardcomponent.lua. Where and how should i place my function ?
In modmain.lua ? creating a component ? In the file of the prefab itself ? (I have maybe one, or two prefabs when i want this function, so a shared code is maybe not needed).

 

Thanks for your help.

Link to comment
Share on other sites

Do not have time to look at gamefiles at the moment, but just looking at this to functions, it looks like you only put

inst.components.pickable:WatchWorldState("iswinter", TogglePickable)
TogglePickable(inst.components.pickable, TheWorld.state.iswinter)

in your masterpostinit or modmain+addprefabpostinit with your plant, of course replace "iswinter" with you season.
And the whole Toggle function a local one in the same script, with your season.

Try out if this works. If not, I can look in game scripts to find out more.

 

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