Hooks del Juego (Callbacks)¶
Estas son funciones Lua llamadas por el GameServer en eventos específicos. Regístralas usando BridgeFunctionAttach() desde ScriptCore.lua.
OnReadScript()¶
Llamado cuando los scripts se cargan/recargan. Usar para inicialización.
OnShutScript()¶
Llamado cuando el servidor se apaga. Usar para limpieza.
OnTimerThread()¶
Llamado en cada tick del temporizador (aproximadamente una vez por segundo). Usar para tareas periódicas.
OnConnectDataBase()¶
Llamado cuando se establece la conexión a la base de datos.
OnCommandManager(aIndex, code, arg) -> number¶
Llamado cuando un jugador usa un comando personalizado. Retorna 1 para bloquear el manejo predeterminado, 0 para dejarlo pasar.
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)¶
Llamado cuando un personaje entra al mundo del juego.
function BridgeFunction_OnCharacterEntry(aIndex)
local player = GetUser(aIndex)
if player then
GCNoticeSend(aIndex, 1, "Welcome, " .. player.Name .. "!")
end
end
OnCharacterClose(aIndex)¶
Llamado cuando un personaje se desconecta.
function BridgeFunction_OnCharacterClose(aIndex)
LogAdd(LOG_BLUE, "Player disconnected: index " .. aIndex)
end
OnGremoryCaseReady(aIndex)¶
Llamado cuando los datos del Gremory Case se han cargado para un jugador. Usa esto en lugar de OnCharacterEntry para operaciones 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¶
Llamado cuando un jugador habla con un NPC. Retorna 1 para bloquear el diálogo predeterminado, 0 para permitirlo.
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¶
Llamado cuando un monstruo muere. aIndex = monstruo, bIndex = asesino. Retorna 1 para bloquear el botín predeterminado, 0 para permitirlo.
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)¶
Llamado cuando un jugador muere. aIndex = víctima, bIndex = asesino.
function BridgeFunction_OnUserDie(aIndex, bIndex)
LogAdd(LOG_RED, "Player " .. aIndex .. " killed by " .. bIndex)
end
OnUserRespawn(aIndex, killerType)¶
Llamado cuando un jugador reaparece después de morir.
function BridgeFunction_OnUserRespawn(aIndex, killerType)
local player = GetUser(aIndex)
if player then
player.Life = player.MaxLife
end
end
OnCheckUserTarget(aIndex, bIndex) -> number¶
Llamado para validar si un jugador puede atacar a otro jugador. Retorna 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¶
Llamado para validar penalizaciones PK. Retorna 0 para omitir el procesamiento PK, 1 para aplicarlo.
OnItemGet(aIndex, itemObjIndex, pItem) -> number¶
Llamado cuando un jugador recoge un item. Retorna 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¶
Llamado cuando un jugador suelta un item. Retorna 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¶
Llamado cuando se recibe un paquete personalizado (headcode 0xFE). Retorna 1 si fue manejado.
OnMapChange(aIndex, oldMap, newMap)¶
Llamado cuando un jugador cambia 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¶
Llamado para validar si una habilidad puede ser usada. Retorna true para permitir, false para bloquear. Tiene dos sobrecargas (con y sin objetivo).
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)¶
Llamado cuando comienza un intercambio entre dos jugadores.
function BridgeFunction_OnTradeStart(aIndex, bIndex)
LogAdd(LOG_BLUE, "Trade started: " .. aIndex .. " <-> " .. bIndex)
end
OnTradeConfirm(aIndex, bIndex)¶
Llamado cuando ambos jugadores confirman un intercambio.
function BridgeFunction_OnTradeConfirm(aIndex, bIndex)
LogAdd(LOG_GREEN, "Trade confirmed: " .. aIndex .. " <-> " .. bIndex)
end