Skip to content

LuaAPI Game Events

itvnnnd87 edited this page Oct 24, 2026 · 1 revision

Game events

The GameServer calls these functions when something happens in the game. Basic events (login, logout, death, timers, chat commands, database) are on the Events page.

How to use them

The easiest way is to attach a module function: the GameServer starts sending the event as soon as a function is attached, and every attached function runs isolated from the others (Modules).

function NoDropInLorencia(aIndex, slot, x, y, item)
    if Object.GetMap(aIndex) == MAP_LORENCIA then
        Message.Send(aIndex, 3, "You cannot drop items in Lorencia")
        return false
    end
    return true
end

BridgeFunctionAttach("OnItemDrop", "NoDropInLorencia")

You can also write the global function yourself (function onItemDrop(aIndex, slot, x, y, item) ... end) and call Event.Refresh() after defining it at run time. Events with no function cost nothing: the GameServer does not even prepare them.

Two kinds of events

Check events ask the script before the action. Return false or 0 to block it; return true, 1 or nothing to allow it. If the script has an error or takes too long, the action is allowed (a broken script never blocks the game).

Notify events report something that already happened. They are delivered on the next server tick, in order, and only if the character is still the same one (no event for a character that has already left).

Read-only events

Check events marked read-only run in the middle of combat, item or shop processing. Inside them (and in everything they call) functions that change the game do nothing and return false. Reading data and sending messages still work. To change something because of such an event, start a short timer (Timer.Create(1, ...)) or store a flag and act in a notify event.

Check events

Function Arguments Read-only
onUseCommand aIndex, text (full command line, starting with / or .)
onNpcTalk aIndex, npcIndex
onTradeRequest aIndex, targetIndex
onTradeAnswer aIndex, requesterIndex, accepted (false result = refuse)
onTradeAccept aIndex, targetIndex (both pressed OK) yes
onCanEnterEvent aIndex, eventId
onItemUse aIndex, sourceSlot, targetSlot, useType yes
onItemPick aIndex, item yes
onItemDrop aIndex, slot, x, y, item yes
onItemMove aIndex, sourceType, sourceSlot, targetType, targetSlot, 0 yes
onItemEquip aIndex, sourceSlot, targetSlot, 0 yes
onItemUnEquip aIndex, sourceSlot, targetSlot, 0 yes
onShopBuy aIndex, npcIndex, item, price yes
onShopSell aIndex, npcIndex, item, slot, price yes
onMossMerchantUse aIndex, type yes
onCashShopBuy aIndex, package, option yes
onCashShopGift aIndex, package, option, targetName yes
onCashShopItemUse aIndex, itemCode, serial yes
onMapMoveRequest aIndex, map, gate, moveId (Move window, /move)
onGateEnter aIndex, gate yes
onCheckUserKiller killerIndex, victimIndex (false = the kill does not count as PK) yes
onCheckUserTarget attackerIndex, targetIndex (false = cannot attack this player) yes
onUseSkill aIndex, targetIndex, skill (targetIndex -1 = none) yes
  • item is an item table.
  • onGateEnter: after a block, the same character is not asked again for 3 seconds (the client retries every step).
  • onUseSkill is sent only for skills turned on with Skill.Watch(skill, true).

Notify events

Function Arguments
onPlayerConnect aIndex, account, serverMove (serverMove = true when coming from another GameServer)
onCharacterSelect aIndex, account (back to character select)
onPlayerDisconnect account, accountId (the connection is closed; the index is no longer valid)
onCharacterJoinMap aIndex, map
onTeleport aIndex, map, x, y
onTeleportMagic aIndex, x, y (Teleport skill)
onCloseWindow aIndex, window
onWarehouseOpen, onWarehouseClose aIndex
onTradeCancel aIndex, targetIndex
onEventEnter aIndex, eventId
onEventStart eventId, duration, notify
onItemGet aIndex, slot, 0, item (picked up into the inventory)
onItemMove aIndex, sourceType, sourceSlot, targetType, targetSlot, 1 (done)
onItemEquip, onItemUnEquip aIndex, sourceSlot, targetSlot, 1 (done)
onItemRepair aIndex, slot, cost, autoRepair
onShopItemBought aIndex, slot, item
onPlayerLevelUp aIndex, levelType, newLevel (levelType 0 normal, 1 master, 2 majestic)
onPlayerGiveExp aIndex, experience (all experience of one server tick added together)
onPlayerKill killerIndex, victimIndex
onPlayerRespawn aIndex, killerType (-1 unknown, 0 monster, 1 player)
onShieldBreak attackerIndex, victimIndex
onMonsterDie monsterIndex, killerIndex, class, map, x, y
onMonsterRespawn monsterIndex, class (only classes turned on with Monster.WatchRespawn(class, true))
onPacketRecv aIndex, data, size, headcode (only packets the GameServer does not handle itself)
onServerShutdown seconds (0 = shutting down now, -1 = shutdown cancelled)

onItemMove, onItemEquip and onItemUnEquip are both check events (last argument 0) and notify events (last argument 1). Return false only when the last argument is 0.

Schedule events

Sent by the Scheduler: onScheduleNotice(eventType, secondsLeft), onScheduleStart(eventType), onScheduleEnd(eventType).

Short attach names

Every event can be attached as "On" + its name without on (onItemGet → "OnItemGet"). These names are accepted too:

Attach name Event
OnUserRespawn onPlayerRespawn
OnUserItemPick, OnUserItemDrop, OnUserItemMove, OnUserItemUse onItemPick, onItemDrop, onItemMove, onItemUse
OnUserEquipItem, OnUserUnEquipItem onItemEquip, onItemUnEquip
OnCommandDone onUseCommand
OnUserGiveExp onPlayerGiveExp
OnUserTeleport onMapMoveRequest
OnUserBuyitem, OnUserSellitem onShopBuy, onShopSell
OnNpcTalk onNpcTalk, with the arguments in the order npcIndex, aIndex

Next: Library

Clone this wiki locally