Hooks do Jogo (Callbacks)¶
Estas são funções Lua chamadas pelo GameServer em eventos específicos. Registre-as usando BridgeFunctionAttach() do ScriptCore.lua.
OnReadScript()¶
Chamado quando scripts são carregados/recarregados. Use para inicialização.
OnShutScript()¶
Chamado quando o servidor desliga. Use para limpeza.
OnTimerThread()¶
Chamado em cada tick do timer (aproximadamente uma vez por segundo). Use para tarefas periódicas.
OnConnectDataBase()¶
Chamado quando a conexão com o banco de dados é estabelecida.
OnCommandManager(aIndex, code, arg) -> number¶
Chamado quando um jogador usa um comando customizado. Retorne 1 para bloquear o tratamento padrão, 0 para passar adiante.
function BridgeFunction_OnCommandManager(aIndex, code, arg)
if code == 100 then
GCNoticeSend(aIndex, 1, "Custom command executed!")
return 1 -- Handled
end
return 0 -- Not handled
end
OnCharacterEntry(aIndex)¶
Chamado quando um personagem entra no mundo do jogo.
function BridgeFunction_OnCharacterEntry(aIndex)
local player = GetUser(aIndex)
if player then
GCNoticeSend(aIndex, 1, "Welcome, " .. player.Name .. "!")
end
end
OnCharacterClose(aIndex)¶
Chamado quando um personagem desconecta.
function BridgeFunction_OnCharacterClose(aIndex)
LogAdd(LOG_BLUE, "Player disconnected: index " .. aIndex)
end
OnGremoryCaseReady(aIndex)¶
Chamado quando os dados do Gremory Case são carregados para um jogador. Use este em vez do OnCharacterEntry para operações de Gremory.
function BridgeFunction_OnGremoryCaseReady(aIndex)
GremoryGive(aIndex, GET_ITEM(14, 13), 0, 0, 0, 0, 0, 0,
GREMORY_CASE_CHARACTER, GREMORY_REWARD_EVENT, GREMORY_EXPIRE_7_DAYS)
end
OnNpcTalk(aIndex, bIndex) -> number¶
Chamado quando um jogador fala com um NPC. Retorne 1 para bloquear o diálogo padrão, 0 para permitir.
function BridgeFunction_OnNpcTalk(aIndex, bIndex)
local npc = GetUser(bIndex)
if npc and npc.Class == 257 then -- Custom NPC class
GCNoticeSend(aIndex, 1, "Hello from custom NPC!")
return 1
end
return 0
end
OnMonsterDie(aIndex, bIndex) -> number¶
Chamado quando um monstro morre. aIndex = monstro, bIndex = matador. Retorne 1 para bloquear loot padrão, 0 para permitir.
function BridgeFunction_OnMonsterDie(aIndex, bIndex)
local monster = GetUser(aIndex)
if monster and monster.Class == 275 then
GCNoticeSendToAll(0, "The boss has been defeated!")
end
return 0
end
OnUserDie(aIndex, bIndex)¶
Chamado quando um jogador morre. aIndex = vítima, bIndex = matador.
function BridgeFunction_OnUserDie(aIndex, bIndex)
LogAdd(LOG_RED, "Player " .. aIndex .. " killed by " .. bIndex)
end
OnUserRespawn(aIndex, killerType)¶
Chamado quando um jogador ressuscita após a morte.
function BridgeFunction_OnUserRespawn(aIndex, killerType)
local player = GetUser(aIndex)
if player then
player.Life = player.MaxLife
end
end
OnCheckUserTarget(aIndex, bIndex) -> number¶
Chamado para validar se um jogador pode atacar outro jogador. Retorne 0 para bloquear, 1 para permitir.
function BridgeFunction_OnCheckUserTarget(aIndex, bIndex)
local attacker = GetUser(aIndex)
local target = GetUser(bIndex)
if attacker and target and attacker.Map == 0 then
return 0 -- No PvP in Lorencia
end
return 1
end
OnCheckUserKiller(aIndex, bIndex) -> number¶
Chamado para validar penalidades PK. Retorne 0 para pular processamento PK, 1 para aplicar.
OnItemGet(aIndex, itemObjIndex, pItem) -> number¶
Chamado quando um jogador coleta um item. Retorne 0 para bloquear, 1 para permitir.
function BridgeFunction_OnItemGet(aIndex, itemObjIndex, pItem)
if pItem and pItem:IsExcItem() then
LogAdd(LOG_GREEN, "Player picked up an Excellent item!")
end
return 1
end
OnItemDrop(aIndex, slot, x, y, pItem) -> number¶
Chamado quando um jogador larga um item. Retorne 0 para bloquear, 1 para permitir.
function BridgeFunction_OnItemDrop(aIndex, slot, x, y, pItem)
if pItem and pItem:IsSetItem() then
GCNoticeSend(aIndex, 1, "You cannot drop Ancient items!")
return 0
end
return 1
end
OnPacketRecv(aIndex, lpMsg, size) -> number¶
Chamado quando um pacote customizado (headcode 0xFE) é recebido. Retorne 1 se tratado.
OnMapChange(aIndex, oldMap, newMap)¶
Chamado quando um jogador muda de mapa.
function BridgeFunction_OnMapChange(aIndex, oldMap, newMap)
LogAdd(LOG_BLUE, "Player " .. aIndex .. " moved from map " .. oldMap .. " to " .. newMap)
end
OnValidateSkillUse(aIndex, skillIndex, [targetIndex]) -> boolean¶
Chamado para validar se uma habilidade pode ser usada. Retorne true para permitir, false para bloquear. Tem duas sobrecargas (com e sem alvo).
function BridgeFunction_OnValidateSkillUse(aIndex, skillIndex, targetIndex)
if skillIndex == 41 and GetUser(aIndex).Map == 6 then
GCNoticeSend(aIndex, 1, "This skill is disabled in the Arena!")
return false
end
return true
end
OnTradeStart(aIndex, bIndex)¶
Chamado quando uma troca começa entre dois jogadores.
function BridgeFunction_OnTradeStart(aIndex, bIndex)
LogAdd(LOG_BLUE, "Trade started: " .. aIndex .. " <-> " .. bIndex)
end
OnTradeConfirm(aIndex, bIndex)¶
Chamado quando ambos os jogadores confirmam uma troca.
function BridgeFunction_OnTradeConfirm(aIndex, bIndex)
LogAdd(LOG_GREEN, "Trade confirmed: " .. aIndex .. " <-> " .. bIndex)
end