KDScript

KDRenewable

ParameterTypeDescriptionDefault value
renewable_frequencytimehow often to check the inventory3m (3 minutes)
renewable_thresholdintegermaximum count of the object allowed in inventory0
renewable_physicalbooleanwhether to keep physics models on created objectsfalse

KDRenewable ensures that a supply of an object is always available to the player. Whenever the player's inventory stack count of the object drops below a threshold, a new instance of the object is created at the KDRenewable marker's position. Only one new instance may exist at a time, so another will not be created until the previous one has been picked up or destroyed.

The renewable object is identified by a ScriptParams link with the data Renewable from the KDRenewable marker to an archetype. This script correctly handles the standard T2 crystal types, looking for the corresponding arrows in inventory. It also correctly handles archetypes (or their parents) with Transmute links, as used by the Transmogrify script in Public Scripts.

The renewable_threshold parameter specifies the maximum stack count of the object that may be in the player's inventory. The renewable_frequency parameter specifies how often the inventory check is performed. At each interval, if the inventory stack count is below the threshold and any previously created instance has been consumed, a new instance is created.

By default, the new instance is created without a physics model to avoid, for example, a bomb or projectile immediately making impact. (Once an object has entered and left the player's inventory, the engine will make it physical again.) As such, the marker should be positioned and rotated appropriately for the object being created. If the renewable_physical parameter is true, however, any physics model on the created object will not be removed (though neither will one be added if the archetype does not specify one).

This script is a replacement for the RenewableResource script in T2's miss16.osm, whose additional behaviors can lead to bugs in missions. It does not share that script's feature of notifying the managing marker with a TurnOn message when a created object is picked up. For backwards compatibility with that script:

This script is part of the KDScript module. Copyright © 2012–2013 Kevin Daughtridge. See introduction for details.