Overview
Each module is a folder in Data\LuaAPI\Includes\ containing Config.lua (configuration, which you edit), a .lua file with the same name (the code, no need to edit) and README.txt. Some modules need tables created in the game DB using the accompanying .sql file.
General way to enable any module:
- Run the module's
.sqlfile (if any) once on the game DB. - Add the command to
Data\Commands\LuaCommands.xml(if the module uses chat commands). - Remove the
--in front of theLoadModule("Name\\Name")line inData\LuaAPI\Main.lua. - Edit the module's
Config.lua. - Click Reload LuaAPI on the GameServer control window.
Most modules have an Enable = true / false key in Config.lua to turn them on / off without editing Main.lua (the LoadModule line still loads the file, but the module does not attach to any event when Enable = false). Exceptions: CmdCommands has no Config.lua; NpcMessage uses two keys, TalkEnable and TauntEnable.
Module list
| Module | What it does | Default in Main.lua | Needs SQL |
|---|---|---|---|
| WelcomeMessage | Sends a notice when a character enters the game | On | No |
| CmdCommands | Example /test chat command | On | No |
| NpcMessage | NPCs talk on their own, monsters taunt when they kill a player | On | No |
| CustomWindowName | Shows character info in the game window title | On | No (reads the existing acc_recharge table) |
| CustomItemExchange | Exchange items for coins using chat commands | Off | No |
| CumulativeRecharge | Rewards by top-up tier (one-time / daily / weekly / monthly) | Off | Yes |
| DailyReward | One gift bag per account per day on login | Off | Yes |
| Entrylimit | Blocks IP / MAC / hard disk serial numbers; locks a test server | Off | No |
| ItemOptionExpand | Adds stats to equipment that reaches the specified level | Off | No |
| MonsterSpawn | Keeps a fixed number of monsters at set spots, rewards on kill | Off | No |
| RandomQuestSystem | Random monster-kill quest event on a schedule | Off | No |
| RechargeGift | NPC gives gifts based on total top-up amount | Off | No (uses the acc_recharge table) |
| ShopPointRate | Monsters drop coins; converts EXP into Zen | Off | No |
| Warehouse | Opens the warehouse remotely with the /warehouse command | Off | No |
Main.lua in the current installation. Each additional module you enable needs Reload LuaAPI.Chat command IDs used by the modules
| ID | Module |
|---|---|
| 2000 | CmdCommands (/test) |
| 2001 | Warehouse |
| 3001 - 3010 | CustomItemExchange |
When adding your own command, choose an ID that no module uses yet.
Writing your own module
- Create the folder
Data\LuaAPI\Includes\NewName\, the fileNewName.luaandConfig.lua. - In
NewName.lua, load the configuration withrequire("NewName\\Config"), write the handler function (prefix the function name with the module name so it does not clash with other modules), then attach it:BridgeFunctionAttach("OnCharacterEntry", "NewName_OnLogin"). - Add
LoadModule("NewName\\NewName")toMain.lua, then click Reload LuaAPI.
-- Includes\HelloModule\HelloModule.lua
require("HelloModule\\Config")
local Cfg = HelloModuleConfig
function HelloModule_OnLogin(aIndex)
Message.Send(aIndex, 1, Cfg.Text.Hello)
end
if Cfg.Enable then
BridgeFunctionAttach("OnCharacterEntry", "HelloModule_OnLogin")
Log.Add("[HelloModule] Loaded")
else
Log.Add("[HelloModule] Disabled")
end
Conventions followed by the sample modules, which you should keep:
- Configuration lives in
Config.lua(global tableModuleNameConfig); do not hard-code numbers / text in the code. - Text sent to players lives in the
Texttable of the configuration. - SQL statements built by string concatenation always go through
DB.Escape(see Asynchronous DB queries). - NPCs or monsters created by a module must be removed when
OnShutScriptis received (LuaAPI reload) so they are not duplicated.