Scripting:TWTrapAIEcology

Building pieces of another world.
Revision as of 18:29, 21 June 2020 by gravatar The Watcher [userbureaucratsysopPHRhYmxlIGNsYXNzPSJ0d3BvcHVwIj48dHI+PHRkIGNsYXNzPSJ0d3BvcHVwLWVudHJ5dGl0bGUiPkdyb3Vwczo8L3RkPjx0ZD51c2VyPGJyIC8+YnVyZWF1Y3JhdDxiciAvPnN5c29wPGJyIC8+PC90ZD48L3RyPjwvdGFibGU+] (talk | contribs)
Jump to navigation Jump to search

TWTrapAIEcology is a script that allows a controlled population of AIs to be spawned dynamically during play.

Periodically this script will check whether the number of currently spawned AIs has reached a configurable population limit. If the count is less than the limit, the script will select an AI archetype to spawn, and then choose a spawn point at which the AI should be created. If AIs are killed and despawn, the population drops, and new AIs will be spawned to replace them. Note that this only works if the AI despawns - use the TWTrapAIEcologyDespawn script to make that happen.

At most one AI is spawned each time the script checks the current population. This is a deliberate restriction imposed to prevent AIs being spawned on top of each other.

The AI archetype is chosen based on links from the TWTrapAIEcology host object to archetypes. By default the script will use weighted random selection if multiple AI archetypes are linked, and if only a single AI archetype is linked that is always used.

Example from demo.osm

The spawn point is chosen based on links from the TWTrapAIEcology to concrete objects in the world. If multiple spawn points are linked, one is chosen at random, whereas if only one spawn point is linked that one is always used. The default behaviour is to try and find the first randomly selected spawn point that is not visible on screen. If all spawn points are on screen, spawning is aborted. This behaviour can be disabled if desired - the spawn point is sent a TurnOn message when an AI spawns there, so particle effects can be tiggered.

It is important to note that, while a fnord (a Marker or similar) could be used to mark the location of a spawn point, using a standard fnord is NOT recommended if you want to spawn AIs off screen. fnord objects are not rendered, and this means that the engine can not determine whether the object is on screen: it will always say it is not because, well, you can't see it; it's not rendered! While this is a fine and useful attribute for a normal fnord to have, if you want to make sure that AIs are always spawned off screen, you can't use a fnord unless you give it a transparent, physicsless object and change its Render Type to 'Normal'. An example using this setup can be found in the TWScript Demo mission.



Authors

  • gravatar The Watcher [userbureaucratsysopPHRhYmxlIGNsYXNzPSJ0d3BvcHVwIj48dHI+PHRkIGNsYXNzPSJ0d3BvcHVwLWVudHJ5dGl0bGUiPkdyb3Vwczo8L3RkPjx0ZD51c2VyPGJyIC8+YnVyZWF1Y3JhdDxiciAvPnN5c29wPGJyIC8+PC90ZD48L3RyPjwvdGFibGU+]