Skip to content

LuaAPI Events

itvnnnd87 edited this page Oct 24, 2026 · 3 revisions

Events and chat commands

Events (callbacks)

aIndex is the player index; every Player.* function takes it. All events run on the GameServer main thread.

Write your code inside the functions below (System\Callbacks.lua, CallbacksDB.lua, Timers.lua), after the existing BridgeFunction_... line, which runs the modules. Functions you do not need can be deleted.

Function Called when
onGameServerStart() Scripts have just been loaded (startup or reload).
onScriptUnload() Before a reload or a server shutdown.
onPlayerLogin(aIndex) A character enters the game (once, after entering is complete).
onPlayerLogout(aIndex) A character leaves the game (exit or back to character select). Data can be read and messages sent, but nothing can be changed.
onPlayerDie(aIndex, killerIndex) A character dies. killerIndex = -1 if unknown.
onLuaCommand(aIndex, code, name, arg) A chat command from LuaCommands.xml (below). Return 1 if handled.
onDBQueryResult(label, param, result) Result of DB.Query (Database). Return 1 to run the query again.
onTimerProcessSecond() Every second.
onTimerProcessMinute() When a new minute starts.
onTimerProcessHour() When a new hour starts.
onTimerProcessDayChange() When a new day starts (00:00).

47 more events (items, shops, trade, teleport, monsters, PvP, skills ...) are listed on the Game events page.

function onPlayerLogin(aIndex)
    BridgeFunction_OnCharacterEntry(aIndex)   -- keep this line first (attached modules)

    Message.Send(aIndex, 1, "Welcome " .. Player.GetName(aIndex))
end

Script chat commands

File Data\Commands\LuaCommands.xml (ships with this sample command; its handler is Includes\CmdCommands\Commands.lua):

<CommandList>
	<CommandSystem Type="16" Description="Custom Lua Comands">
		<Command ID="2000" name= "test" Description="" Authority="0"/>
	</CommandSystem>
</CommandList>
Attribute Meaning
ID Identifier, passed to the script as code.
Description Free text for your own notes. Not used by the server.
name What the player types: /test (or .test). Not case sensitive. Any language can be used (save the file as UTF-8).
Authority 0 = everyone, 2 = GM only (after .auth).

If a command has the same name as a built-in server command, the server command wins.

Reading the arguments after the command name (positions start at 0):

-- /test 5 abc  ->  arg = "5 abc"
Util.ArgNumber(arg, 0)   -- 5
Util.ArgString(arg, 1)   -- "abc"
function onLuaCommand(aIndex, code, name, arg)
    if BridgeFunction_OnCommandManager(aIndex, 16, code, arg) == 1 then return 1 end

    if code == 2000 then
        Message.Send(aIndex, 1, "You typed /" .. name .. " " .. arg)
        return 1
    end

    return 0
end

Next: Function reference

Clone this wiki locally