• TibiaFace

    Tibiaface | Una comunidad Open Tibia donde encontras : mapas, scripts, Otserver, npc y amigos etc ...

    .
    demo menumenu

    Afiliados



    Votar:

    [NPC] problema con tiempo - npc

    Compartir:

    Ver el tema anterior Ver el tema siguiente Ir abajo  Mensaje (Página 1 de 1.)

    1[NPC] problema con tiempo - npc Empty [NPC] problema con tiempo - npc Lun Nov 27, 2023 12:33 am

    akane

    akane
    Miembro
    Miembro
    hola a todos, tengo un problema con este script en donde se supone que al momento de decir las palabras claves tales como winner, next round, etc se debería esperar 5 minutos para continuar con la mision, el tema es que al momento de usar este script en tfs 0.4 no daba ningun problema pero ahora donde cambié a otx 2.15 no funciona.

    Código:
    local keywordHandler = KeywordHandler:new()
    local npcHandler = NpcHandler:new(keywordHandler)
    NpcSystem.parseParameters(npcHandler)
    local talkState = {}

    -- Definir una variable para rastrear el tiempo de espera
    local waitTime = 300  -- 300 segundos (5 minutos)
    local intervalTime = 4000 -- 10 segundos
    local infoIntervalTime = 20000 -- 20 segundos para infoMessages
    local lastIntervalTime = 0
    local lastInfoIntervalTime = 0

    -- Las partes del mensaje de información
    local infoMessages = {
        "If you want to participate in our tournament, just say 'participate'.",
        "Have you already won your first fight? Then say 'winner' to move on to the next round.",
        "This year there have been quite strong competitors participating, so use the strongest equipment you have.",
        "Are you winning battles? Keep it up; maybe you'll be the next champion.",
        "When the battles end, it takes a while to prepare the arenas again, so keep that in mind and be patient.",
        "Participants, good luck everyone."
    }

    -- Variable para rastrear el mensaje actual de información
    local currentInfoMessage = 1

    function onCreatureAppear(cid)
        npcHandler:onCreatureAppear(cid)
    end

    function onCreatureDisappear(cid)
        npcHandler:onCreatureDisappear(cid)
    end

    function onCreatureSay(cid, type, msg)
        npcHandler:onCreatureSay(cid, type, msg)
    end

    function onThink()
        npcHandler:onThink()

        local now = os.time() * 1000

        -- Obtener el primer jugador visible para el NPC
        local spectators = getSpectators(getNpcPos(), 7, 7, false)
        local cid = spectators[1]

        -- Verificar si ha pasado el tiempo suficiente para enviar el próximo mensaje de información
        if now - lastInfoIntervalTime >= infoIntervalTime then
            local nextMessage = infoMessages[currentInfoMessage]
            npcHandler:say(nextMessage, cid)
            currentInfoMessage = currentInfoMessage + 1

            if currentInfoMessage > #infoMessages then
                currentInfoMessage = 1  -- Reiniciar el contador si llega al final
            end

            lastInfoIntervalTime = now
        end

        -- Verificar si ha pasado el tiempo suficiente desde el último intervalo general de mensajes
        if now - lastIntervalTime >= intervalTime then
            -- Puedes dejar esta parte vacía ya que no hay mensajes generales
            lastIntervalTime = now
        end
    end

    function getRemainingTime(cid)
        local lastWinTime = getPlayerStorageValue(cid, 21024)
        if lastWinTime > 0 then
            local currentTime = os.time()
            local elapsedTime = currentTime - lastWinTime
            return math.max(0, waitTime - elapsedTime)
        end
        return 0
    end

    function creatureSayCallback(cid, type, msg)
        if not npcHandler:isFocused(cid) then
            return false
        end

        local playerStorage = getPlayerStorageValue(cid, 21021) -- Reemplaza con el storage correcto

        if msgcontains(msg, 'participate') then
            npcHandler:say('Very good, I will give you the ticket to participate in the fights. You have understood?', cid)
            talkState[cid] = 1
            setPlayerStorageValue(cid, 21021, 1)
        elseif talkState[cid] == 1 and msgcontains(msg, 'yes') then
            if getPlayerStorageValue(cid, 21021) >= 1 then
                npcHandler:say('Then get ready for your first fight. Go to arena 1. When you win the fight, tell me {winner}.', cid)
                talkState[cid] = 2
                doPlayerAddItem(cid, 2329, 1)
                setPlayerStorageValue(cid, 21022, 1)
            else
                doPlayerSendCancel(cid, "No tienes el storage necesario para usar este item.")
            end
        elseif talkState[cid] == 2 and msgcontains(msg, 'winner') then
            if getPlayerStorageValue(cid, 21024) >= 1 then
                npcHandler:say('Congratulations, you are the winner! The next fight will start in 5 minutes. Come back after 5 minutes for the {second round}.', cid)
                setPlayerStorageValue(cid, 21025, os.time()) -- Almacena el tiempo de la última victoria
                talkState[cid] = 3
            else
                doPlayerSendCancel(cid, "No tienes el storage necesario para usar este item.")
            end
        elseif talkState[cid] == 3 and msgcontains(msg, 'second round') then
            if getPlayerStorageValue(cid, 21025) > 0 then
                local remainingTime = getRemainingTime(cid)
                if remainingTime == 0 then
                    npcHandler:say('Let the next fight begin. Go to arena 4, when you win the fight tell me {next round}.', cid)
                    setPlayerStorageValue(cid, 21026, 1)
                    talkState[cid] = 4
                else
                    local minutes = math.floor(remainingTime / 60)
                    local seconds = remainingTime % 60
                    npcHandler:say("You need to wait " .. minutes .. " minutes and " .. seconds .. " seconds before the next fight.", cid)
                end
            else
                doPlayerSendCancel(cid, "No tienes el storage necesario para usar este item.")
            end
        elseif talkState[cid] == 4 and msgcontains(msg, 'next round') then
            if getPlayerStorageValue(cid, 21028) >= 1 then
                npcHandler:say('Congratulations, you are the winner! The next fight will start in 5 minutes. Come back after 5 minutes for the {third round}.', cid)
                setPlayerStorageValue(cid, 21029, os.time()) -- Almacena el tiempo de la última victoria
                talkState[cid] = 5
            else
                doPlayerSendCancel(cid, "No tienes el storage necesario para usar este item.")
            end
        elseif talkState[cid] == 5 and msgcontains(msg, 'third round') then
            if getPlayerStorageValue(cid, 21029) > 0 then
                local remainingTime = getRemainingTime(cid)
                if remainingTime == 0 then
                    npcHandler:say('Let the next fight begin. Go to arena 2, when you win the fight tell me {next round}.', cid)
                    setPlayerStorageValue(cid, 21030, 1)
                    talkState[cid] = 6
                else
                    local minutes = math.floor(remainingTime / 60)
                    local seconds = remainingTime % 60
                    npcHandler:say("You need to wait " .. minutes .. " minutes and " .. seconds .. " seconds before the next fight.", cid)
                end
            else
                doPlayerSendCancel(cid, "No tienes el storage necesario para usar este item.")
            end
        else
        -- Si no se cumplen las condiciones anteriores, el NPC podría dar una pista sobre la conversación actual
        if talkState[cid] == 1 then
            npcHandler:say("To participate in the tournament, say 'yes' when you're ready.", cid)
        elseif talkState[cid] == 2 then
            npcHandler:say("You're in the middle of the first round, if you still don't fight go to arena 1. If you're the winner, say 'winner'.", cid)
        elseif talkState[cid] == 3 then
            npcHandler:say("Congratulations on winning the first round! Get ready for the second round. When prepared, say 'second round'.", cid)
        elseif talkState[cid] == 4 then
            npcHandler:say("You're in the middle of the second round, if you still don't fight go to arena 4. If you're the winner, say 'next round'.", cid)
        elseif talkState[cid] == 5 then
            npcHandler:say("Congratulations on winning the second round! Get ready for the third round. When prepared, say 'third round'.", cid)
        elseif talkState[cid] == 6 then
            npcHandler:say("You're in the middle of the second round, if you still don't fight go to arena 5. If you're the winner, say 'next round'.", cid)
        else
            npcHandler:say("I'm not sure where we left off. If you need assistance, feel free to ask about the current task.", cid)
        end
    end


        return true
    end

    npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
    npcHandler:addModule(FocusModule:new())

    este es el script, como dije antes estoy usando otx 2.15

    3 participantes

    2[NPC] problema con tiempo - npc Empty Re: [NPC] problema con tiempo - npc Lun Nov 27, 2023 11:08 am

    [Admin] God Maya

    [Admin] God Maya
    Administrador
    Administrador
    Marca algun error en consola



    [NPC] problema con tiempo - npc YNU5B25
    3 participantes
    http://www.tibiaface.com

    3[NPC] problema con tiempo - npc Empty Re: [NPC] problema con tiempo - npc Lun Nov 27, 2023 10:49 pm

    akane

    akane
    Miembro
    Miembro
    [Admin] God Maya escribió:Marca algun error en consola
    ninguno, pero tampoco hace nada

    3 participantes

    4[NPC] problema con tiempo - npc Empty Re: [NPC] problema con tiempo - npc Mar Nov 28, 2023 10:50 am

    [Admin] God Maya

    [Admin] God Maya
    Administrador
    Administrador
    Intenta copiar todo el contenido principal a otro npc



    [NPC] problema con tiempo - npc YNU5B25
    3 participantes
    http://www.tibiaface.com

    5[NPC] problema con tiempo - npc Empty Re: [NPC] problema con tiempo - npc Mar Nov 28, 2023 8:53 pm

    akane

    akane
    Miembro
    Miembro
    [Admin] God Maya escribió:Intenta copiar todo el contenido principal a otro npc

    sigue sin hacer nada :/

    3 participantes

    6[NPC] problema con tiempo - npc Empty Re: [NPC] problema con tiempo - npc Mar Nov 28, 2023 9:04 pm

    SoyFabi

    SoyFabi
    Miembro
    Miembro
    akane escribió:ninguno, pero tampoco hace nada

    Osea si el player tiene el storage 21024 que en este caso seria al decir Winner entonces pasa a la siguiente mission que seria el storage 21025 que seria second round. Entonces es donde hay que esperar 5 minutos... osea
    setPlayerStorageValue(cid, 21025, os.time()).

    Pero no entiendo para que usar function getRemainingTime(cid)

    setPlayerStorageValue(21025, os.time() + 300) -- 5 minutos

    mejor usar eso no?


    Código:
    local keywordHandler = KeywordHandler:new()
    local npcHandler = NpcHandler:new(keywordHandler)
    NpcSystem.parseParameters(npcHandler)
    local talkState = {}

    -- Definir una variable para rastrear el tiempo de espera
    local waitTime = 300  -- 300 segundos (5 minutos)
    local intervalTime = 4000  -- 10 segundos
    local infoIntervalTime = 20000  -- 20 segundos para infoMessages
    local lastIntervalTime = 0
    local lastInfoIntervalTime = 0

    -- Las partes del mensaje de información
    local infoMessages = {
        "If you want to participate in our tournament, just say 'participate'.",
        "Have you already won your first fight? Then say 'winner' to move on to the next round.",
        "This year there have been quite strong competitors participating, so use the strongest equipment you have.",
        "Are you winning battles? Keep it up; maybe you'll be the next champion.",
        "When the battles end, it takes a while to prepare the arenas again, so keep that in mind and be patient.",
        "Participants, good luck everyone."
    }

    -- Variable para rastrear el mensaje actual de información
    local currentInfoMessage = 1

    function onCreatureAppear(cid)
        npcHandler:onCreatureAppear(cid)
    end

    function onCreatureDisappear(cid)
        npcHandler:onCreatureDisappear(cid)
    end

    function onCreatureSay(cid, type, msg)
        npcHandler:onCreatureSay(cid, type, msg)
    end

    function onThink()
        npcHandler:onThink()

        local now = os.time() * 1000

        -- Obtener el primer jugador visible para el NPC
        local spectators = getSpectators(getNpcPos(), 7, 7, false)
        local cid = spectators[1]

        -- Verificar si ha pasado el tiempo suficiente para enviar el próximo mensaje de información
        if now - lastInfoIntervalTime >= infoIntervalTime then
            local nextMessage = infoMessages[currentInfoMessage]
            npcHandler:say(nextMessage, cid)
            currentInfoMessage = currentInfoMessage + 1

            if currentInfoMessage > #infoMessages then
                currentInfoMessage = 1  -- Reiniciar el contador si llega al final
            end

            lastInfoIntervalTime = now
        end

        -- Verificar si ha pasado el tiempo suficiente desde el último intervalo general de mensajes
        if now - lastIntervalTime >= intervalTime then
            -- Puedes dejar esta parte vacía ya que no hay mensajes generales
            lastIntervalTime = now
        end
    end

    function creatureSayCallback(cid, type, msg)
        if not npcHandler:isFocused(cid) then
            return false
        end

        if msgcontains(msg, 'participate') then
            npcHandler:say('Very good, I will give you the ticket to participate in the fights. You have understood?', cid)
            talkState[cid] = 1
            setPlayerStorageValue(cid, 21021, 1)
        elseif talkState[cid] == 1 and msgcontains(msg, 'yes') then
            if getPlayerStorageValue(cid, 21021) >= 1 then
                npcHandler:say('Then get ready for your first fight. Go to arena 1. When you win the fight, tell me {winner}.', cid)
                talkState[cid] = 2
                doPlayerAddItem(cid, 2329, 1)
                setPlayerStorageValue(cid, 21022, 1)
            else
                doPlayerSendCancel(cid, "No tienes el storage necesario para usar este item.")
            end
        elseif talkState[cid] == 2 and msgcontains(msg, 'winner') then
            if getPlayerStorageValue(cid, 21024) >= 1 then
                npcHandler:say('Congratulations, you are the winner! The next fight will start in 5 minutes. Come back after 5 minutes for the {second round}.', cid)
                setPlayerStorageValue(cid, 21025, os.time() + 300) -- 5 minutos
                talkState[cid] = 3
            else
                doPlayerSendCancel(cid, "No tienes el storage necesario para usar este item.")
            end
        elseif talkState[cid] == 3 and msgcontains(msg, 'second round') then
            local timeStorage = getPlayerStorageValue(cid, 21025)
            if timeStorage > os.time() then
                local remainingTime = timeStorage - os.time()
                local minutes = math.floor(remainingTime / 60)
                local seconds = remainingTime % 60

                if minutes > 0 then
                    npcHandler:say('You must wait ' .. minutes .. ' minutes and ' .. seconds .. ' second more.', cid)
                else
                    npcHandler:say('You must wait ' .. seconds .. ' second more.', cid)
                end
            elseif timeStorage > 0 and timeStorage < os.time() then
                if getPlayerStorageValue(cid, 21025) > 0 then
                    npcHandler:say('Let the next fight begin. Go to arena 4, when you win the fight tell me {next round}.', cid)
                    setPlayerStorageValue(cid, 21026, 1)
                    talkState[cid] = 4
                else
                    doPlayerSendCancel(cid, "No tienes el storage necesario para usar este item.")
                end
            end
        elseif talkState[cid] == 4 and msgcontains(msg, 'next round') then
            if getPlayerStorageValue(cid, 21028) >= 1 then
                npcHandler:say('Congratulations, you are the winner! The next fight will start in 5 minutes. Come back after 5 minutes for the {third round}.', cid)
                setPlayerStorageValue(cid, 21029, os.time() + 300)
                talkState[cid] = 5
            else
                doPlayerSendCancel(cid, "No tienes el storage necesario para usar este item.")
            end
        elseif talkState[cid] == 5 and msgcontains(msg, 'third round') then
            local timeStorage = getPlayerStorageValue(cid, 21029)
            if timeStorage > os.time() then
                local remainingTime = timeStorage - os.time()
                local minutes = math.floor(remainingTime / 60)
                local seconds = remainingTime % 60

                if minutes > 0 then
                    npcHandler:say('You must wait ' .. minutes .. ' minutes and ' .. seconds .. ' second more.', cid)
                else
                    npcHandler:say('You must wait ' .. seconds .. ' second more.', cid)
                end
            elseif timeStorage > 0 and timeStorage < os.time() then
                if getPlayerStorageValue(cid, 21029) > 0 then
                    npcHandler:say('Let the next fight begin. Go to arena 2, when you win the fight tell me {next round}.', cid)
                    setPlayerStorageValue(cid, 21030, 1)
                    talkState[cid] = 6
                 else
                    doPlayerSendCancel(cid, "No tienes el storage necesario para usar este item.")
                end
            end
        else
            -- Si no se cumplen las condiciones anteriores, el NPC podría dar una pista sobre la conversación actual
            if talkState[cid] == 1 then
                npcHandler:say("To participate in the tournament, say 'yes' when you're ready.", cid)
            elseif talkState[cid] == 2 then
                npcHandler:say("You're in the middle of the first round, if you still don't fight go to arena 1. If you're the winner, say 'winner'.", cid)
            elseif talkState[cid] == 3 then
                npcHandler:say("Congratulations on winning the first round! Get ready for the second round. When prepared, say 'second round'.", cid)
            elseif talkState[cid] == 4 then
                npcHandler:say("You're in the middle of the second round, if you still don't fight go to arena 4. If you're the winner, say 'next round'.", cid)
            elseif talkState[cid] == 5 then
                npcHandler:say("Congratulations on winning the second round! Get ready for the third round. When prepared, say 'third round'.", cid)
            elseif talkState[cid] == 6 then
                npcHandler:say("You're in the middle of the second round, if you still don't fight go to arena 5. If you're the winner, say 'next round'.", cid)
            else
                npcHandler:say("I'm not sure where we left off. If you need assistance, feel free to ask about the current task.", cid)
            end
        end

        return true
    end

    npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
    npcHandler:addModule(FocusModule:new())

    3 participantes

    7[NPC] problema con tiempo - npc Empty Re: [NPC] problema con tiempo - npc Mar Nov 28, 2023 9:58 pm

    akane

    akane
    Miembro
    Miembro
    la funcion function getRemainingTime(cid) era para que cuando el player pidiera entrar en el segundo round, el npc dijera que tiene que esperar x minutos y por cada vez que hables antes de los 5 minutos, el npc dijera debes esperar 5 o 4, 3 ,2 minutos para volver a hablar. de hecho como dije en el primer post, en mi ot 0.4 si funcionaba sin problemas, pero donde actualicé a otx 2.15 dejó de funcionar el sistema



    akane escribió:la funcion function getRemainingTime(cid) era para que cuando el player pidiera entrar en el segundo round, el npc dijera que tiene que esperar x minutos y por cada vez que hables antes de los 5 minutos, el npc dijera debes esperar 5 o 4, 3 ,2 minutos para volver a hablar. de hecho como dije en el primer post, en mi ot 0.4 si funcionaba sin problemas, pero donde actualicé a otx 2.15 dejó de funcionar el sistema
    me funcionó perfecto, como siempre salvandome, muchas gracias soyfabi

    3 participantes

    Contenido patrocinado


    3 participantes

    Ver el tema anterior Ver el tema siguiente Volver arriba  Mensaje (Página 1 de 1.)

    Permisos de este foro:
    No puedes responder a temas en este foro.

     

    BienvenidosTibiaFace es una comunidad de Open Tibia. Para participar debes estar registrado (click para Regístrate).