Scripting
Game modes are typically heavily scripting-oriented, with game flow such as spawning, killing, and reviving being delegated to a secondary language such as Lua or C#.
Lua scripting
As Lua scripts are integrated into the CryENGINE, we don't need to do any additional loading for it to work. To access your script table (based on the Lua file named the same as your game mode in Game/Scripts/GameRules
):
m_script = GetEntity()->GetScriptTable();
Invoking methods
To invoke methods on your script table, see the IScriptSystem BeginCall
and EndCall
functions:
IScriptSystem *pScriptSystem = gEnv->pScriptSystem; pScriptSystem->BeginCall(m_script, "MyMethod"); pScriptSystem->EndCall();
When executing the previous code, we'll be able to execute Lua code in a function named MyMethod
contained inside our game mode's script table. An example of the table can be seen as follows:
MyGameMode = { } function MyGameMode:MyMethod() end
Invoking methods with parameters
To provide your...