Expiry default
New items in the world have a timer after which they go away. This part lets your mod change that timer for items the game creates without a time of its own.
WorldItems the expiry timer for new items
Use SetExpiryOverride to change the timer for new items, ExpiryMinutes to read it, and ClearExpiryOverride to take your change back off.
public static class WorldItems
{
public static int ExpiryMinutes { get; }
public static bool SetExpiryOverride(int minutes);
public static bool SetExpiryOverride(string owner, int minutes);
public static void ClearExpiryOverride();
public static bool ClearExpiryOverride(string owner);
}
| Method | Returns | What it does |
|---|---|---|
SetExpiryOverride(minutes) | bool | Sets the timer for new items, in the shared slot that older mods use. true when it was set. |
SetExpiryOverride(owner, minutes) | bool | The same, for your own mod id. |
ClearExpiryOverride() | void | Puts back the game’s timer (the shared slot). |
ClearExpiryOverride(owner) | bool | Removes your mod’s timer. true when it had one. |
| Property | Type | What it means |
|---|---|---|
ExpiryMinutes | int | The level’s normal item timer, in minutes, without any change from a mod. -1 when it cannot be read. |
Things to know
ExpiryMinutesis the level’s normal item timer in minutes. It is-1when the level has no logic object or the read fails, and a failure goes to the log once. (It isinfo_game_logic.itemExpirationTimeMinutes.)SetExpiryOverride(minutes)sets the timer for new items that the game starts without a time of their own. Each item gets a random time between half ofminutesand one and a half timesminutes, sominutesis an average, not an exact time.- A value below
1means those items never expire. - Pass your mod id as the
ownerargument so mods do not overwrite each other. Each mod id keeps its own timer, and the newestSetExpiryOverridewins. ClearExpiryOverride(owner)removes only your timer, and the timer of the mod that set one before you applies again. It returnsfalsewhen you had none.- The versions without
ownershare one slot for older mods. Anownerthat is not a valid mod id throws anArgumentException. ClearExpiryOverride()puts back the game’s own timer. It works at any time, including insideEvents.SceneLoaded.- Set the timer again in your
Events.SceneLoadedhandler, which runs after the clear, or inEvents.WhenReady, which runs after the load. - It applies to new items the game creates without a time. That means items dropped or spawned by the game’s own code (including
Spawn.Itemand coins), perished items that leave a replacement, and spawner items when the spawner is set to let items expire. Those spawns also run while a save loads, so the timer applies to them too. (The calls areItemOperations.SetCollectibleItemValuesand the default-time calls toCollectible.StartExpirationTimer. The spawner setting isexpireItems.) - If something goes wrong while the framework applies the timer, the game’s own timer is used. The failure goes to the log once and never reaches the game.
Limits
- A value above 21,474,836 is refused: it returns
false, writes one line to the log and keeps the current timer, because the game’s timer would overflow. It also returnsfalsewhen the framework could not set up this feature. - The timer is cleared whenever a save starts loading and on every new level. A call made while a save is loading can be wiped by these clears. (It is cleared on
SaveController.PlayerWillLoadGameand on eachLoadSceneMode.Singlescene load (a level change or the main menu).) - It does not apply to items that already have a time, or to items the game makes with no timer. Items in an expiration zone have their own time. Items from crimes and animal drops have no timer. A timer that is already running is not restarted. (Items with
noExpirationTimerare skipped.) - The timer is kept in memory only. It is lost when the game restarts.