Internal gamemode workings
From GMod Wiki
Lua: Internal Gamemode Workings |
Description: | Hopes to explain the internal workings of the gamemode system. |
Original Author: | Garry |
Created: | 11th July 2006 |
Gamemodes are Loaded and Set.
Load Gamemode
The load gamemode process loads and stores the gamemode onto a table. E indicates the process is made in the engine using C++, L indicates Lua.
- E: LoadGamemode( "sandbox" )
- E: Makes global table called GM
- E: Sets GM.Folder (a string containing the path of the gamemode)
- E: Run Lua script
- Client: lua/gamemodes/(gamemode)/cl_init.lua
- Server: lua/gamemodes/(gamemode)/init.lua
- L: Runs scripts, fills GM with the gamemode
- E: Calls gamemode.Register( GM, "sandbox", "base" ) - "base" being the derived gamemode
- L: gamemode.Register adds gamemode to table and derives the base gamemode
- E: Removes global GM table
Set Gamemode
Set Gamemode is called to actually set the gamemode (duh?)
- E: Calls gamemode.Get( "sandbox" )
- L: gamemode.Get returns the gamemode table
- E: Sets global GAMEMODE to gamemode table
- E: Loads SWEPS, SENTS and EFFECTS in derived gamemode
- E: Loads SWEPS, SENTS and EFFECTS in current gamemode
- E: Calls GAMEMODE:Initialize()
Regular Operation
The gamemode is now set. The gamemode system will now be called at specific points in the engine to make particular decisions (Such as when a player spawns, is killed etc). This is how this is handled.
- E: Calls hook.Call( "function_name", GAMEMODE, arguments )
- L: hook.Call runs hooked functions (non gamemode)
- L: hook.Call calls the gamemode function