Ir para o conteúdo

Interação com NPC

O hook OnNpcTalk é disparado quando um jogador clica em um NPC. Retorne 1 para bloquear o diálogo padrão do NPC, 0 para permitir.

Diálogo de NPC Customizado

local CUSTOM_NPC_CLASS = 257  -- Your NPC's monster class ID

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  -- Block default NPC window
    end

    return 0  -- Not our NPC, allow default behavior
end

BridgeFunctionAttach("OnNpcTalk", OnNpcTalk)

NPC de Buff

local BUFF_NPC_CLASS = 258
local BUFF_DURATION = 3600  -- 1 hour in seconds

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

    -- Check if player already has the buff
    if CheckEffect(player, 100) then
        GCChatTargetSend(npc, aIndex, "You already have an active buff!")
        return 1
    end

    -- Check if player can afford the buff (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

    -- Apply buff: +50 damage, +30 defense for 1 hour
    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 de Teletransporte (Seletor de Mapas)

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

    -- For simplicity, teleport based on player level
    local dest = DESTINATIONS[1]  -- Default: 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)