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:

  1. Run the module's .sql file (if any) once on the game DB.
  2. Add the command to Data\Commands\LuaCommands.xml (if the module uses chat commands).
  3. Remove the -- in front of the LoadModule("Name\\Name") line in Data\LuaAPI\Main.lua.
  4. Edit the module's Config.lua.
  5. 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

ModuleWhat it doesDefault in Main.luaNeeds SQL
WelcomeMessageSends a notice when a character enters the gameOnNo
CmdCommandsExample /test chat commandOnNo
NpcMessageNPCs talk on their own, monsters taunt when they kill a playerOnNo
CustomWindowNameShows character info in the game window titleOnNo (reads the existing acc_recharge table)
CustomItemExchangeExchange items for coins using chat commandsOffNo
CumulativeRechargeRewards by top-up tier (one-time / daily / weekly / monthly)OffYes
DailyRewardOne gift bag per account per day on loginOffYes
EntrylimitBlocks IP / MAC / hard disk serial numbers; locks a test serverOffNo
ItemOptionExpandAdds stats to equipment that reaches the specified levelOffNo
MonsterSpawnKeeps a fixed number of monsters at set spots, rewards on killOffNo
RandomQuestSystemRandom monster-kill quest event on a scheduleOffNo
RechargeGiftNPC gives gifts based on total top-up amountOffNo (uses the acc_recharge table)
ShopPointRateMonsters drop coins; converts EXP into ZenOffNo
WarehouseOpens the warehouse remotely with the /warehouse commandOffNo
"Default" is the state of Main.lua in the current installation. Each additional module you enable needs Reload LuaAPI.

Chat command IDs used by the modules

IDModule
2000CmdCommands (/test)
2001Warehouse
3001 - 3010CustomItemExchange

When adding your own command, choose an ID that no module uses yet.

Writing your own module

  1. Create the folder Data\LuaAPI\Includes\NewName\, the file NewName.lua and Config.lua.
  2. In NewName.lua, load the configuration with require("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").
  3. Add LoadModule("NewName\\NewName") to Main.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 table ModuleNameConfig); do not hard-code numbers / text in the code.
  • Text sent to players lives in the Text table 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 OnShutScript is received (LuaAPI reload) so they are not duplicated.