UPDATED FOR GMS 2.3+
This project contains a series of functions designed to generate an ordered list of all targets with a given parent object. This list can then be scrolled through to select any of the given targets and "lock on" to them. If a target leaves the given range or is destroyed, the scripts will update the list again and target the next nearest, or it will select the next one on the list and find another target to add (this behaviour can be changed). Multiple instances can have target lists so you can have multiplayer games or AI using the same system.
Features
All functions are called from a single object and can be easily added to a player or an enemy object later. The PARENT object must be used for all objects that you wish to target and should not be changed.
The included demo project contains two folders of objects in the resource tree. The BASE objects are the ones you should be using in a real game, and the DEMO objects can be removed. Note that the demo objects hold a lot of information in the form of comments so take a moment to read through them before removing them from the file.
Included with this project is a script from GMLScripts, which you can find here: http://www.gmlscripts.com/script/instance_nth_nearest
GMLScripts licence can be found here: http://www.gmlscripts.com/license.txt
End User Licence Agreement (EULA).
Change notes:
This update adds new functionality to the asset, namely a "targeting pause" script that permits you to pause the targeting system when not required. This addition has meant that the INIT script now requires an extra argument for the alarm to call the update script in. If you update this in a project, be aware that you will need to update the arguments in that script and that you no longer have to set the update alarm manually.
Updated and improved the asset for 2.3+