Bỏ qua

Tương tác NPC

Hook OnNpcTalk kích hoạt khi người chơi nhấp vào NPC. Trả về 1 để chặn hộp thoại NPC mặc định, 0 để cho phép.

Hộp thoại NPC tùy chỉnh

local CUSTOM_NPC_CLASS = 257  -- ID lớp quái vật của NPC

local function OnNpcTalk(aIndex, bIndex)
    local npc = GetUser(bIndex)
    if npc == nil then return 0 end

    if npc.Class == CUSTOM_NPC_CLASS then
        local player = GetUser(aIndex)
        if player == nil then return 1 end

        GCChatTargetSend(npc, aIndex, "Hello, " .. player.Name .. "!")
        GCChatTargetSend(npc, aIndex, "Your level is " .. player.Level)
        return 1  -- Chặn cửa sổ NPC mặc định
    end

    return 0  -- Không phải NPC của chúng ta, cho phép hành vi mặc định
end

BridgeFunctionAttach("OnNpcTalk", OnNpcTalk)

NPC tăng sức mạnh (Buff)

local BUFF_NPC_CLASS = 258
local BUFF_DURATION = 3600  -- 1 giờ tính bằng giây

local function OnNpcTalk(aIndex, bIndex)
    local npc = GetUser(bIndex)
    if npc == nil or npc.Class ~= BUFF_NPC_CLASS then return 0 end

    local player = GetUser(aIndex)
    if player == nil then return 1 end

    -- Kiểm tra người chơi đã có buff chưa
    if CheckEffect(player, 100) then
        GCChatTargetSend(npc, aIndex, "You already have an active buff!")
        return 1
    end

    -- Kiểm tra người chơi có đủ tiền không (10.000 Zen)
    if not gObjCharacterReduceZen(player, 10000, true, true) then
        GCChatTargetSend(npc, aIndex, "You need 10,000 Zen for a buff.")
        return 1
    end

    -- Áp dụng buff: +50 sát thương, +30 phòng thủ trong 1 giờ
    AddEffect(player, 1, 100, BUFF_DURATION, 50, 30, 0, 0, 0, 0, 0, bIndex, -1)
    GCChatTargetSend(npc, aIndex, "Buff applied! +50 DMG, +30 DEF for 1 hour.")

    return 1
end

BridgeFunctionAttach("OnNpcTalk", OnNpcTalk)

NPC dịch chuyển (Chọn bản đồ)

local TELEPORT_NPC_CLASS = 259

local DESTINATIONS = {
    { name = "Lorencia", map = 0, x = 130, y = 130 },
    { name = "Devias",   map = 2, x = 222, y = 60  },
    { name = "Noria",    map = 3, x = 176, y = 110 },
}

local function OnNpcTalk(aIndex, bIndex)
    local npc = GetUser(bIndex)
    if npc == nil or npc.Class ~= TELEPORT_NPC_CLASS then return 0 end

    local player = GetUser(aIndex)
    if player == nil then return 1 end

    -- Để đơn giản, dịch chuyển dựa trên cấp độ người chơi
    local dest = DESTINATIONS[1]  -- Mặc định: Lorencia
    if player.Level >= 100 then
        dest = DESTINATIONS[2]  -- Devias
    end
    if player.Level >= 200 then
        dest = DESTINATIONS[3]  -- Noria
    end

    gObjTeleport(aIndex, dest.map, dest.x, dest.y)
    GCNoticeSend(aIndex, 1, "Teleported to " .. dest.name .. "!")

    return 1
end

BridgeFunctionAttach("OnNpcTalk", OnNpcTalk)