Hook trò chơi (Callback)¶
Đây là các hàm Lua được GameServer gọi tại các sự kiện cụ thể. Đăng ký chúng bằng BridgeFunctionAttach() từ ScriptCore.lua.
OnReadScript()¶
Được gọi khi kịch bản được tải/tải lại. Sử dụng để khởi tạo.
OnShutScript()¶
Được gọi khi server tắt. Sử dụng để dọn dẹp.
OnTimerThread()¶
Được gọi mỗi nhịp hẹn giờ (khoảng mỗi giây một lần). Sử dụng cho tác vụ định kỳ.
OnConnectDataBase()¶
Được gọi khi kết nối cơ sở dữ liệu được thiết lập.
OnCommandManager(aIndex, code, arg) -> number¶
Được gọi khi người chơi sử dụng lệnh tùy chỉnh. Trả về 1 để chặn xử lý mặc định, 0 để cho qua.
function BridgeFunction_OnCommandManager(aIndex, code, arg)
if code == 100 then
GCNoticeSend(aIndex, 1, "Custom command executed!")
return 1 -- Đã xử lý
end
return 0 -- Chưa xử lý
end
OnCharacterEntry(aIndex)¶
Được gọi khi nhân vật vào thế giới trò chơi.
function BridgeFunction_OnCharacterEntry(aIndex)
local player = GetUser(aIndex)
if player then
GCNoticeSend(aIndex, 1, "Welcome, " .. player.Name .. "!")
end
end
OnCharacterClose(aIndex)¶
Được gọi khi nhân vật ngắt kết nối.
function BridgeFunction_OnCharacterClose(aIndex)
LogAdd(LOG_BLUE, "Player disconnected: index " .. aIndex)
end
OnGremoryCaseReady(aIndex)¶
Được gọi khi dữ liệu Gremory Case đã tải cho người chơi. Sử dụng thay cho OnCharacterEntry cho các thao tác 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¶
Được gọi khi người chơi nói chuyện với NPC. Trả về 1 để chặn hội thoại mặc định, 0 để cho phép.
function BridgeFunction_OnNpcTalk(aIndex, bIndex)
local npc = GetUser(bIndex)
if npc and npc.Class == 257 then -- Lớp NPC tùy chỉnh
GCNoticeSend(aIndex, 1, "Hello from custom NPC!")
return 1
end
return 0
end
OnMonsterDie(aIndex, bIndex) -> number¶
Được gọi khi quái vật chết. aIndex = quái vật, bIndex = người giết. Trả về 1 để chặn rơi đồ mặc định, 0 để cho phép.
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)¶
Được gọi khi người chơi chết. aIndex = nạn nhân, bIndex = kẻ giết.
function BridgeFunction_OnUserDie(aIndex, bIndex)
LogAdd(LOG_RED, "Player " .. aIndex .. " killed by " .. bIndex)
end
OnUserRespawn(aIndex, killerType)¶
Được gọi khi người chơi hồi sinh sau khi chết.
function BridgeFunction_OnUserRespawn(aIndex, killerType)
local player = GetUser(aIndex)
if player then
player.Life = player.MaxLife
end
end
OnCheckUserTarget(aIndex, bIndex) -> number¶
Được gọi để xác nhận người chơi có thể tấn công người chơi khác không. Trả về 0 để chặn, 1 để cho phép.
function BridgeFunction_OnCheckUserTarget(aIndex, bIndex)
local attacker = GetUser(aIndex)
local target = GetUser(bIndex)
if attacker and target and attacker.Map == 0 then
return 0 -- Không PvP tại Lorencia
end
return 1
end
OnCheckUserKiller(aIndex, bIndex) -> number¶
Được gọi để xác nhận hình phạt PK. Trả về 0 để bỏ qua xử lý PK, 1 để áp dụng.
OnItemGet(aIndex, itemObjIndex, pItem) -> number¶
Được gọi khi người chơi nhặt vật phẩm. Trả về 0 để chặn, 1 để cho phép.
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¶
Được gọi khi người chơi vứt vật phẩm. Trả về 0 để chặn, 1 để cho phép.
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¶
Được gọi khi nhận gói tin tùy chỉnh (headcode 0xFE). Trả về 1 nếu đã xử lý.
function BridgeFunction_OnPacketRecv(aIndex, lpMsg, size)
-- Phân tích gói tin tùy chỉnh ở đây
return 0
end
OnMapChange(aIndex, oldMap, newMap)¶
Được gọi khi người chơi đổi bản đồ.
function BridgeFunction_OnMapChange(aIndex, oldMap, newMap)
LogAdd(LOG_BLUE, "Player " .. aIndex .. " moved from map " .. oldMap .. " to " .. newMap)
end
OnValidateSkillUse(aIndex, skillIndex, [targetIndex]) -> boolean¶
Được gọi để xác nhận kỹ năng có thể sử dụng không. Trả về true để cho phép, false để chặn. Có hai dạng nạp chồng (có và không có mục tiêu).
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)¶
Được gọi khi giao dịch bắt đầu giữa hai người chơi.
function BridgeFunction_OnTradeStart(aIndex, bIndex)
LogAdd(LOG_BLUE, "Trade started: " .. aIndex .. " <-> " .. bIndex)
end
OnTradeConfirm(aIndex, bIndex)¶
Được gọi khi cả hai người chơi xác nhận giao dịch.
function BridgeFunction_OnTradeConfirm(aIndex, bIndex)
LogAdd(LOG_GREEN, "Trade confirmed: " .. aIndex .. " <-> " .. bIndex)
end