This page contains the two remaining GameServer functions (LoadScript and Event.Refresh) and notes about the short names in Data\LuaAPI\System\Modules.lua.
Other functions
LoadScript
Loads and runs a Lua file. This is a global function, not part of any table.
LoadScript(path)
| Parameter | Type | Description |
|---|---|---|
path | string | Path of the .lua file, following the same path rules as the File.* functions: relative paths are resolved from Data\LuaAPI\ |
Returns: no return value. If the file cannot be opened or the file has a syntax error / runtime error, the function raises a Lua error in the calling script (the error line states the file name). The UTF-8 BOM at the start of the file is removed, and the first line is skipped if it starts with #. File names with non-ASCII characters are supported.
pcall: local ok, err = pcall(LoadScript, "Includes\\MyModule\\Extra.lua").LoadScript("Includes\\MyModule\\Config.lua")
LoadScript("Includes\\MyModule\\MyModule.lua")
Event.Refresh
Tells the GameServer to rescan the callback functions (onPlayerLogin, onItemUse...) that scripts have defined, so that the GameServer starts sending those events. The GameServer only sends events to callbacks that exist, so events nobody listens to cost no resources.
Event.Refresh()
No parameters, no return value. The BridgeFunctionAttach function in Modules.lua calls this automatically when attaching a module function to a new event, so a module normally does not need to call it directly. Call it only when you define an onXxx callback yourself after the script has finished loading.
function onPlayerLevelUp(aIndex)
Message.Send(aIndex, 1, "Congratulations on leveling up!")
end
Event.Refresh()
Short names with special behavior
Most short names in Modules.lua are just aliases of namespace functions and are noted at each function. A few short names are wrapper Lua functions with different behavior:
| Short name | Behavior |
|---|---|
GetObjectMasterReset(aIndex) | Always returns 0 (the server has no Master Reset counter) |
GetObjectLang(aIndex) | Always returns 0 (single language) |
GetGameServerLang(), GetGameServerProtocol() | Always return 0 |
Is28Option() | Always returns 1 |
RandomGetNumber(n), GetRandomValue(n) | A random number from 0 to n - 1 (unlike Util.Random, which includes both ends) |
CommandCheckGameMasterLevel(aIndex, level) | Only checks whether the character is a GM with privileges enabled; level is ignored |
GetObjectGensFamily(aIndex) | The two factions are swapped compared with Player.GetGensFamily |
InventoryGetItemTable, EventInventoryGetItemTable, MuunInventoryGetItemTable, MapGetItemTable | Return an item table with additional old-style field names |
InventorySetItemTable(aIndex, slot, t) | Also accepts old-style field names |
Unsupported short names
The following names are reserved in Modules.lua but have no functionality yet. Calling them raises a Lua error with the content <name>() is not supported by LuaAPI (the error only stops the calling function; other modules keep running):
GetObjectMaxNormalPoints, GetObjectPassword, GetObjectPersonalCode, EventInventorySetItemTable, EventInventoryDelItemIndex, EventInventoryDelItemCount, MuunInventorySetItemTable, MuunInventoryDelItemCount, AddItemBag, PartyCreate, PartyDelete, PartyAddMember, PartyDelMember, SendRgbChat.