LUA Support for Tremulous
User manual
Basics
LUA is a lightweight scripting language.
It can be used with tremulous DnC (testing version only) to permit to customize game's behaviour without make modification in C sourcecode and compilation.
All lua scripts must be on directory base/scripts.
- Files in base/scripts root must be exec with /execLua command (see below)
- Files in base/scripts/global are executed for each new games
- Files in base/scripts/<map_name> are executed for each new games on given map
You can use LUA scripts by two way:
- Call a script through console with command: /execLua <script_name.lua>
- Set a hook to run a script on event
Events
To hook a function to an event, use lua function:
package.AddHook(event, function)
exemple:
game.entity.AddHook("on_init", function() game.Print("Init entity") end)
There is many events available. Only few of them are currently implemented: Objects hierachy:
- Entity
- Creature
- Player
- Building
- Creature
- Map
- Game
- Item
- Weapon
- Trigger
game.entity
- on_init
- on_think
- on_destroyed
- on_hitted
game.building
- on_building
- on_up
- on_used
- on_deconstructed
game.creature
- on_attack
- on_secondary_attack
- on_third_attack
- on_spawn
- on_join_team
- on_evolve
- on_build
- on_inventory_changed
game.player
game.item
- on_got
- on_used
- on_sold
game.weapon
- on_fire
- on_secondary_fire
- on_reload
game.map
- on_init
- on_start
- on_stage_up
- on_sudden_death
- on_exit
game
- on_startup
- on_shutdown
- on_player_connect
- on_player_disconnect
- on_player_entered
game.trigger
- on_init
- on_triggered
- on_destroyed
Lua Application Program Interface
Currently, really few lua function are available. API will be improved for future versions.
game functions
- game.Print(string) : broadcast a message to all players and on console
- game.Cp(string) : like /cp command, to center a message on all players screen
- game.AddHook?(event, function) : add a hook to game objects
math functions
vector functions
entity functions
Learn Lua
To learn Lua language, you can found good tutorials here: http://lua-users.org/wiki/TutorialDirectory
unfinished article
