Ir para conteúdo

Featured Replies

Postado
  • Diretor
-- Import required modules and libraries
domodlib('arenaFunctions')
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

-- Initialize conversation states as local variables
local focus = 0
local talk_start = 0
local TS = 0

-- Function to check if a string contains another string (case-insensitive)
local function msgcontains(txt, str)
    return string.find(string.lower(txt), string.lower(str))
end

-- Function to handle player saying something to the NPC
function onCreatureSay(cid, type, msg)
    msg = string.lower(msg)

    if (msgcontains(msg, 'hi') and focus == 0) then
        selfSay('Hello ' .. getCreatureName(cid) .. ', do you want to fight in the arena?')
        focus = cid
        talk_start = os.clock()
        TS = 1
    elseif msgcontains(msg, 'hi') and focus ~= cid then
        selfSay('I\'m busy.')
    elseif TS == 1 then
        if msgcontains(msg, 'yes') or msgcontains(msg, 'fight') or msgcontains(msg, 'arena') then
            local myArenaLevel = 3 -- Replace this with the appropriate storage value for your system
            local enterArena = myArenaLevelIs(cid)

            if getPlayerStorageValue(cid, myArenaLevel) < 3 then
                if getPlayerLevel(cid) >= enterArena.RLV then
                    if getPlayerMoney(cid) >= enterArena.RC then
                        setPlayerStorageValue(cid, talkNPC, 1)
                        doPlayerRemoveMoney(cid, enterArena.RC)
                        selfSay("Now you can face the... " .. enterArena.LN .. " level!")
                    else
                        selfSay("You don't have " .. enterArena.RC .. " gold! Come back when you are ready!")
                    end
                else
                    selfSay("You don't have level " .. enterArena.RLV .. " yet! Come back when you are ready!")
                end
            else
                selfSay("Cancel[6]") -- Note: Ensure the 'Cancel' table is defined in the arenaFunctions module.
            end
        elseif msgcontains(msg, 'no') then
            selfSay("Bye two!")
        else
            selfSay("Sorry, I didn't understand. Do you want to fight in the arena?")
        end

        focus = 0  -- Reset conversation state: focus
        talk_start = 0  -- Reset conversation state: talk_start
        TS = 0  -- Reset conversation state: TS
    elseif msgcontains(msg, 'bye') then
        selfSay("Bye three!")
        focus = 0  -- Reset conversation state: focus
        talk_start = 0  -- Reset conversation state: talk_start
        TS = 0  -- Reset conversation state: TS
    end

    return true
end

-- Function to handle NPC behavior on think
function onThink()
    doNpcSetCreatureFocus(focus)

    if (os.clock() - talk_start) > 10 then
        if focus > 0 then
            selfSay('Bye four.')
        end
        focus = 0  -- Reset conversation state: focus
        talk_start = 0  -- Reset conversation state: talk_start
        TS = 0  -- Reset conversation state: TS
    end
end

-- Set the appropriate callback and add the FocusModule
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, onCreatureSay)
npcHandler:addModule(FocusModule:new())

 

 

20230912_034613.png.cf49b650c34dd7d7b1f79bd49c70f53c.png

Eu sou um entusiasta da programação apaixonado por ajudar a comunidade open source a crescer. Sempre em busca de novos desafios e oportunidades para contribuir com meu código.  #OpenSource #Programação #Contribuição

 

  • 1 year later...
  • Respostas 6
  • Visualizações 836
  • Created
  • Última resposta

Top Posters In This Topic

Most Popular Posts

  • -- Import required modules and libraries domodlib('arenaFunctions') local keywordHandler = KeywordHandler:new() local npcHandler = NpcHandler:new(keywordHandler) NpcSystem.parseParameters(npcHandler)

  • -- Import required modules and libraries domodlib('arenaFunctions') local keywordHandler = KeywordHandler:new() local npcHandler = NpcHandler:new(keywordHandler) NpcSystem.parseParameters(npcHandler)

Postado
  • Autor

Desculpa reviver o tópico, mas pode marcar como resolvido (jurava que tinha vindo aqui pedir isso ano passado)


O último script postado ainda apresentava o mesmo erro "Call stack overflow", porém por ser só um erro visual que não interfere nada na quest e não gera nenhum outro bug creio que esteja resolvido...

Participe da conversa

Você pode postar agora e se cadastrar mais tarde. Se você tem uma conta, faça o login para postar com sua conta.

Visitante
Responder

Quem Está Navegando 0

  • Nenhum usuário registrado visualizando esta página.

Estatísticas dos Fóruns

  • Tópicos 96.9k
  • Posts 519.7k

Informação Importante

Confirmação de Termo