Contents |
Scorched 3D supports the use of scripts to both enhance the engine and to create new and funky weapons. Scripting support was introduced in Scorched3D version 42.
Scripting is useful when you want to perform actions based on complex decisions, or simply when an alternative is not available via the XML configuration files. For example, you may want to find all the players in a given team and give them some money, or kill all players below a certain amount of health. Scripting makes all of this possible.
Scripts are written in the LUA scripting language. Scripts are saved as 'plain text files' usualy with the lua file extension. See LUA Documentation for documentation on the LUA scripting language.
The LUA interpreter imbeded in Scorched3D supports the following standard libraries-
All of the standard libraries are documented in the LUA Documentation.
Scorched3D adds some new functions and structures to LUA so the script can interact with the scorched engine. For example, some of these functions allow you to fire weapons or send messages to other players. These Scorched specific libraries and functions are documented later.
LUA makes heavy use of tables to store structured data. Scorched3D represents most of its complex information as tables. For example the position and velocity vectors are represented as tables containing three entries (x, y & z). You can access these entries by using the fullstop, e.g. table.x.
See LUA Documentation for a more detailed explanation of table operations.
Its probably worth noting that internaly Scorched3D uses fixed point maths. All numbers used by the engine are stored as fixed point, including those used by the LUA library. This ensures that all maths operations (and so the simulation) remains consistent accross different architectures.
But don't worry this completely is hidden from you at all times, and other than a slightly reduced maths accuracy it shouldn't be noticable. The fixed point numbers used currently support up to four decimal places (.0001) and numbers up to two hundred thousand (200000).
LUA is a fully functioning programming (scripting) language (LUA Documentation). However LUA scripts run within a virtual machine that only allows it to perform specified operations. When LUA was added to Scorched3D any operation that was deemed to be unsecure was removed from the language. Removed functions include any that accessed the operating system and all file reading/writing functions.
Scorched3D currently allows two types of scripting -
Scorched3D provides two scripting libraries -