• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Different daily task for each player

Mizakinha

New Member
Joined
Apr 18, 2021
Messages
35
Reaction score
4
Save ladies and gentlemen!

I have a script on my daily task server, it works normally. Only he gives the same task to ALL players on the server. There is a table with several monster options for the player to kill, he takes 2 random monsters inside that table and the player can choose one of them. Only he gives the SAME options for ALL players.

Can anyone help me identify the location to make it random for each different player? I'll leave the script here.

TFS 0.3.6

Lua:
function onCreatureTurn(creature)
end

function msgcontains(txt, str)
return (string.find(txt, str) and not string.find(txt, '(%w+)' .. str) and not string.find(txt, str .. '(%w+)'))
end

local talkState = {}
local focus = 0
local talk_start = 0
local lookNpcDir = getNPCXMLLOOKDIR(getNPCXMLNAME(getThis()))
local tchau = false
local opcoesDiarias = {}
local hora = os.date("%d") -- mudar para dias
local dia = os.date("%d")
local strinSay1 = ""
local stringSay2 = ""
local expToGive1 = 680
local expToGive2 = 680
local strinSay1, strinSay2 = "", ""

function onCreatureSay(cid, type, msg)
local msg = string.lower(msg)
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
if not (getDistanceToCreature(cid) <= 3) then
    return true
end

if msgcontains(string.lower(msg), 'hi') then
    if focus ~= 0 then
       selfSay(getCreatureName(cid) .. ' aguarde...')
       return true
    else
        focus = cid
        talk_start = os.clock()
    end
end


local getNpcTaskName = getPlayerStorageValue(cid, storages.miniQuests.storNpcTaskName3)
local pokeTask1 = getPlayerStorageValue(cid, storages.miniQuests.storPokeNameTask3)
local pokeCountTask1 = tonumber(getPlayerStorageValue(cid, storages.miniQuests.storPokeCountTask3))
local minhaHora = getPlayerStorageValue(cid, storages.miniQuests.storDayTask3)
   
if tonumber(minhaHora) ~= tonumber(hora) then
    setPlayerStorageValue(cid, storages.miniQuests.storNpcTaskName3, -1)
    setPlayerStorageValue(cid, storages.miniQuests.storPokeNameTask3, -1)
    setPlayerStorageValue(cid, storages.miniQuests.storPokeCountTask3, -1)
    setPlayerStorageValue(cid, storages.miniQuests.storDayTask3, -1)
end

local getNpcTaskName = getPlayerStorageValue(cid, storages.miniQuests.storNpcTaskName3)
local pokeTask1 = getPlayerStorageValue(cid, storages.miniQuests.storPokeNameTask3)
local pokeCountTask1 = tonumber(getPlayerStorageValue(cid, storages.miniQuests.storPokeCountTask3))
local minhaHora = getPlayerStorageValue(cid, storages.miniQuests.storDayTask3)

if pokeTask1 == "amanha" and msgcontains(string.lower(msg), 'hi') then
   selfSay("You have already done a daily task today.")
   talkState[talkUser] = 0
   tchau = true
   focus = 0
   return true  
end  

if ((pokeTask1 == strinSay1 or pokeTask1 == strinSay2) and getNpcTaskName == getCreatureName(getThis())) and msgcontains(string.lower(msg), 'hi') then  
 
   local expToGive = expToGive1
       if pokeTask1 == strinSay2 then  
          expToGive = expToGive2
       end  
   if pokeCountTask1 <= 0 then
       selfSay('Here is your reward.')  
       doPlayerAddExp(cid, expToGive)
       doSendAnimatedText(getThingPos(cid), expToGive, 215)
       doPlayerAddItem(cid, 17837, 2)
       setPlayerStorageValue(cid, storages.miniQuests.storPokeNameTask3, "amanha")
   elseif pokeCountTask1 > 0 then
       selfSay('Need to defeat ' .. pokeCountTask1 .. ' ' .. pokeTask1 .. (pokeCountTask1 > 1 and "s" or '') .. '.')
   end      
 
   talkState[talkUser] = 0
   tchau = true
   focus = 0
   return true  
end

count = 0

    if((msgcontains(string.lower(msg), 'hi') or  msgcontains(string.lower(msg), 'help')) and (getDistanceToCreature(cid) <= 3)) then
   
        local stringToSay1 = ""
        for i = 1, #opcoesDiarias[1] do
            local pokeCount = opcoesDiarias[1][i][2]
            local pokeWord = pokeCount > 1 and "" or ""
            stringToSay1 = stringToSay1 .. pokeCount .. " " .. opcoesDiarias[1][i][1] .. pokeWord .. (i == 1 and "" or " e ")
        end
       
        local stringToSay2 = ""
        for i = 1, #opcoesDiarias[2] do
            local pokeCount = opcoesDiarias[2][i][2]
            local pokeWord = pokeCount > 1 and "" or ""
            stringToSay2 = stringToSay2 .. pokeCount .. " " .. opcoesDiarias[2][i][1] .. pokeWord .. (i == 1 and "" or " e ")
        end
       
        selfSay('Hello! My daily tasks are of the rookie level. You can kill ' .. stringToSay1 .. " or " .. stringToSay2 .. ".")
        talkState[talkUser] = 1
       
       
    elseif msgcontains(string.lower(msg), string.lower(strinSay1)) or msgcontains(string.lower(msg), string.lower(strinSay2)) and getDistanceToCreature(cid) <= 3 and talkState[talkUser] == 1 then  
        local pokeCounts = 0
        if msgcontains(string.lower(msg), string.lower(strinSay1)) then
            setPlayerStorageValue(cid, storages.miniQuests.storNpcTaskName3, getCreatureName(getThis()))
            setPlayerStorageValue(cid, storages.miniQuests.storPokeNameTask3, opcoesDiarias[1][1][1])
            setPlayerStorageValue(cid, storages.miniQuests.storPokeCountTask3, opcoesDiarias[1][1][2])
            setPlayerStorageValue(cid, storages.miniQuests.storDayTask3, hora)
            pokeCounts = opcoesDiarias[1][1][2]
        else
            setPlayerStorageValue(cid, storages.miniQuests.storNpcTaskName3, getCreatureName(getThis()))
            setPlayerStorageValue(cid, storages.miniQuests.storPokeNameTask3, opcoesDiarias[2][1][1])
            setPlayerStorageValue(cid, storages.miniQuests.storPokeCountTask3, opcoesDiarias[2][1][2])
            setPlayerStorageValue(cid, storages.miniQuests.storDayTask3, hora)
            pokeCounts = opcoesDiarias[2][1][2]
        end

        selfSay('Okay. I will keep in touch with you. Good luck with ' .. pokeCounts.. ' ' .. msg .. (pokeCounts > 1 and 's' or '') .. '.')
        talkState[talkUser] = 0
        focus = 0
        tchau = true
        return true
    end
end


local tablePoke = diarias.Hard
local dificult = 3
function onThink()
    -- resetar tasks
    if hora ~= os.date("%d") then
       opcoesDiarias = {}
       tablePoke = diarias.Hard
       hora = os.date("%d")
    end
   
    if #opcoesDiarias == 0 then -- vamos iniciar as opcoesDiarias
       
        local sorteio1 = math.random(1, #tablePoke)
        local op1 = tablePoke[sorteio1]
                   table.remove(tablePoke, sorteio1)
                   strinSay1 = op1
                 
        local sorteio2 = math.random(1, #tablePoke)
        local op2 = tablePoke[sorteio2]
                   table.remove(tablePoke, sorteio2)
                   strinSay2 = op2
                     
        local pokeCount1 = math.random(50, 80)    * dificult
        local pokeCount2 = math.random(50, 80)    * dificult
        opcoesDiarias[1] = { {op1, pokeCount1} }
        opcoesDiarias[2] = { {op2, pokeCount2} }
       
        expToGive1 = 680 * pokeCount1
        expToGive2 = 680 * pokeCount2
    end

    if focus  ~= 0 then
        if getDistanceToCreature(focus) > 3 then
            tchau = true
            focus = 0
        end

        if (os.clock() - talk_start) > 15 then
            if focus > 0 then
                tchau = true
                focus = 0
            end
        end
        doNpcSetCreatureFocus(focus)
    end

        if tchau then
            tchau = false
            doCreatureSetLookDir(getThis(), lookNpcDir)
            selfSay('Goodbye.')
        end
end
 
Solution
if I change os.date("%d") to os.date("%H") or os.date("%M") it doesn't work.

I switched to minutes and went to do the task. I finished the task and when I returned to the NPC to deliver instead of giving me the reward he gave me another task. If I do it this way I will have to finish the task in 1 minute or 1 hour, if I take longer than that he will offer me another task

That's because on this line 45, you reset the task if the time is not the same as start time:

Lua:
if tonumber(minhaHora) ~= tonumber(hora) then
    setPlayerStorageValue(cid, storages.miniQuests.storNpcTaskName3, -1)
    setPlayerStorageValue(cid, storages.miniQuests.storPokeNameTask3, -1)
    setPlayerStorageValue(cid, storages.miniQuests.storPokeCountTask3...
Whats ur table of monsters named?
Please add all scripts included in this system to make it easier to determine the issue.

Sorry.

the table with the options is in the folder data\lib\107-main tables.lua

The part of this script with the table is this:
Lua:
diarias = {
    Easy = {"Botamon", "Poyomon", "Yuramon", "Nyokimon", "Pichimon", "Pabumon", "Kuramon", "Kiimon", "Leafmon", "Pafumon", "Relemon", "Metal Koromon", "Tsubumon", "Zerimon", "Conomon", "Yukimi Botamon", "Punimon"},
    Medio = {"Koromon", "Tokomon", "Tanemon", "Yokomon", "Bukamon", "Motimon", "Demi Meramon", "Tsumemon", "Yaamon", "Minomon", "Kyaromon", "Viximon", "Kapurimon", "Upamon", "Pagumon", "Gummymon", "Chocomon", "Nyaromon", "Tsunomon", "Wanyamon", "Sunmon", "Budmon"},
    Hard = {"Agumon", "Patamon", "Palmon", "Biyomon", "Gomamon", "Tentomon", "Candlemon", "Keramon", "Impmon", "Kunemon", "Kudamon", "Renamon", "Hagurumon", "Armadillomon", "Elecmon", "Terriermon", "Lopmon", "Salamon", "Gabumon", "Pico Devimon", "Mushroomon", "Floramon", "Chuumon"},
    Expert = {"Greymon"},
    }

The script that counts the monsters that the player still needs to kill to complete the task is in the folder data\creaturescripts\scripts\pokeDeath.lua

The part of the script that makes this counter is this:
Lua:
function checkDirias(cid, nameDeath)

        local master = getCreatureMaster(cid)
        local getNpcTaskName = getPlayerStorageValue(master, storages.miniQuests.storNpcTaskName)
        local pokeTask1 = getPlayerStorageValue(master, storages.miniQuests.storPokeNameTask1)
        local pokeCountTask1 = tonumber(getPlayerStorageValue(master, storages.miniQuests.storPokeCountTask1))
        
       if pokeTask1 ~= -1 and pokeTask1 == nameDeath then
          setPlayerStorageValue(master, storages.miniQuests.storPokeCountTask1, pokeCountTask1 -1)
          local getCountNow = tonumber(getPlayerStorageValue(master, storages.miniQuests.storPokeCountTask1))
          if getCountNow >= 1 then
             doSendMsg(master, getNpcTaskName .. ": Need to defeat " .. getCountNow .. " " .. nameDeath .. (getCountNow > 1 and "s" or "") .. ".")
          else
             doSendMsg(master, getNpcTaskName .. ": You have completed my task come and get your reward.")
          end
       end
      
        local getNpcTaskName2 = getPlayerStorageValue(master, storages.miniQuests.storNpcTaskName2)
        local pokeTask2 = getPlayerStorageValue(master, storages.miniQuests.storPokeNameTask2)
        local pokeCountTask2 = tonumber(getPlayerStorageValue(master, storages.miniQuests.storPokeCountTask2))
        
       if pokeTask2 ~= -1 and pokeTask2 == nameDeath then
          setPlayerStorageValue(master, storages.miniQuests.storPokeCountTask2, pokeCountTask2 -1)
          local getCountNow2 = tonumber(getPlayerStorageValue(master, storages.miniQuests.storPokeCountTask2))
          if getCountNow2 >= 1 then
             doSendMsg(master, getNpcTaskName2 .. ": Need to defeat " .. getCountNow2 .. " " .. nameDeath .. (getCountNow2 > 1 and "s" or "") .. ".")
          else
             doSendMsg(master, getNpcTaskName2 .. ": You have completed my task come and get your reward.")
          end
       end
      
       local getNpcTaskName3 = getPlayerStorageValue(master, storages.miniQuests.storNpcTaskName3)
       local pokeTask3 = getPlayerStorageValue(master, storages.miniQuests.storPokeNameTask3)
       local pokeCountTask3 = tonumber(getPlayerStorageValue(master, storages.miniQuests.storPokeCountTask3))
        
       if pokeTask3 ~= -1 and pokeTask3 == nameDeath then
          setPlayerStorageValue(master, storages.miniQuests.storPokeCountTask3, pokeCountTask3 -1)
          local getCountNow3 = tonumber(getPlayerStorageValue(master, storages.miniQuests.storPokeCountTask3))
          if getCountNow3 >= 1 then
             doSendMsg(master, getNpcTaskName3 .. ": Need to defeat " .. getCountNow3 .. " " .. nameDeath .. (getCountNow3 > 1 and "s" or "") .. ".")
          else
             doSendMsg(master, getNpcTaskName3 .. ": You have completed my task come and get your reward.")
          end
       end
      
       local getNpcTaskName4 = getPlayerStorageValue(master, storages.miniQuests.storNpcTaskName4)
       local pokeTask4 = getPlayerStorageValue(master, storages.miniQuests.storPokeNameTask4)
       local pokeCountTask4 = tonumber(getPlayerStorageValue(master, storages.miniQuests.storPokeCountTask4))
        
       if pokeTask4 ~= -1 and pokeTask4 == nameDeath then
          setPlayerStorageValue(master, storages.miniQuests.storPokeCountTask4, pokeCountTask4 -1)
          local getCountNow4 = tonumber(getPlayerStorageValue(master, storages.miniQuests.storPokeCountTask4))
          if getCountNow4 >= 1 then
             doSendMsg(master, getNpcTaskName4 .. ": Need to defeat " .. getCountNow4 .. " " .. nameDeath .. (getCountNow4 > 1 and "s" or "") .. ".")
          else
             doSendMsg(master, getNpcTaskName4 .. ": You have completed my task come and get your reward.")
          end
       end
end

Note: there are 4 tables and 4 counters because there are 4 daily task NPCs. All are interconnected, if the player makes 1, he cannot make another. So far so good, the problem is that all the players are always receiving the same monsters and this means that there are a lot of ks in the respawns.

How do I get each player to receive different monsters when they get the task with the NPC?
 
Save ladies and gentlemen!

I have a script on my daily task server, it works normally. Only he gives the same task to ALL players on the server. There is a table with several monster options for the player to kill, he takes 2 random monsters inside that table and the player can choose one of them. Only he gives the SAME options for ALL players.

Can anyone help me identify the location to make it random for each different player? I'll leave the script here.

TFS 0.3.6

Lua:
function onCreatureTurn(creature)
end

function msgcontains(txt, str)
return (string.find(txt, str) and not string.find(txt, '(%w+)' .. str) and not string.find(txt, str .. '(%w+)'))
end

local talkState = {}
local focus = 0
local talk_start = 0
local lookNpcDir = getNPCXMLLOOKDIR(getNPCXMLNAME(getThis()))
local tchau = false
local opcoesDiarias = {}
local hora = os.date("%d") -- mudar para dias
local dia = os.date("%d")
local strinSay1 = ""
local stringSay2 = ""
local expToGive1 = 680
local expToGive2 = 680
local strinSay1, strinSay2 = "", ""

function onCreatureSay(cid, type, msg)
local msg = string.lower(msg)
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
if not (getDistanceToCreature(cid) <= 3) then
    return true
end

if msgcontains(string.lower(msg), 'hi') then
    if focus ~= 0 then
       selfSay(getCreatureName(cid) .. ' aguarde...')
       return true
    else
        focus = cid
        talk_start = os.clock()
    end
end


local getNpcTaskName = getPlayerStorageValue(cid, storages.miniQuests.storNpcTaskName3)
local pokeTask1 = getPlayerStorageValue(cid, storages.miniQuests.storPokeNameTask3)
local pokeCountTask1 = tonumber(getPlayerStorageValue(cid, storages.miniQuests.storPokeCountTask3))
local minhaHora = getPlayerStorageValue(cid, storages.miniQuests.storDayTask3)
 
if tonumber(minhaHora) ~= tonumber(hora) then
    setPlayerStorageValue(cid, storages.miniQuests.storNpcTaskName3, -1)
    setPlayerStorageValue(cid, storages.miniQuests.storPokeNameTask3, -1)
    setPlayerStorageValue(cid, storages.miniQuests.storPokeCountTask3, -1)
    setPlayerStorageValue(cid, storages.miniQuests.storDayTask3, -1)
end

local getNpcTaskName = getPlayerStorageValue(cid, storages.miniQuests.storNpcTaskName3)
local pokeTask1 = getPlayerStorageValue(cid, storages.miniQuests.storPokeNameTask3)
local pokeCountTask1 = tonumber(getPlayerStorageValue(cid, storages.miniQuests.storPokeCountTask3))
local minhaHora = getPlayerStorageValue(cid, storages.miniQuests.storDayTask3)

if pokeTask1 == "amanha" and msgcontains(string.lower(msg), 'hi') then
   selfSay("You have already done a daily task today.")
   talkState[talkUser] = 0
   tchau = true
   focus = 0
   return true
end

if ((pokeTask1 == strinSay1 or pokeTask1 == strinSay2) and getNpcTaskName == getCreatureName(getThis())) and msgcontains(string.lower(msg), 'hi') then
 
   local expToGive = expToGive1
       if pokeTask1 == strinSay2 then
          expToGive = expToGive2
       end
   if pokeCountTask1 <= 0 then
       selfSay('Here is your reward.')
       doPlayerAddExp(cid, expToGive)
       doSendAnimatedText(getThingPos(cid), expToGive, 215)
       doPlayerAddItem(cid, 17837, 2)
       setPlayerStorageValue(cid, storages.miniQuests.storPokeNameTask3, "amanha")
   elseif pokeCountTask1 > 0 then
       selfSay('Need to defeat ' .. pokeCountTask1 .. ' ' .. pokeTask1 .. (pokeCountTask1 > 1 and "s" or '') .. '.')
   end    
 
   talkState[talkUser] = 0
   tchau = true
   focus = 0
   return true
end

count = 0

    if((msgcontains(string.lower(msg), 'hi') or  msgcontains(string.lower(msg), 'help')) and (getDistanceToCreature(cid) <= 3)) then
 
        local stringToSay1 = ""
        for i = 1, #opcoesDiarias[1] do
            local pokeCount = opcoesDiarias[1][i][2]
            local pokeWord = pokeCount > 1 and "" or ""
            stringToSay1 = stringToSay1 .. pokeCount .. " " .. opcoesDiarias[1][i][1] .. pokeWord .. (i == 1 and "" or " e ")
        end
     
        local stringToSay2 = ""
        for i = 1, #opcoesDiarias[2] do
            local pokeCount = opcoesDiarias[2][i][2]
            local pokeWord = pokeCount > 1 and "" or ""
            stringToSay2 = stringToSay2 .. pokeCount .. " " .. opcoesDiarias[2][i][1] .. pokeWord .. (i == 1 and "" or " e ")
        end
     
        selfSay('Hello! My daily tasks are of the rookie level. You can kill ' .. stringToSay1 .. " or " .. stringToSay2 .. ".")
        talkState[talkUser] = 1
     
     
    elseif msgcontains(string.lower(msg), string.lower(strinSay1)) or msgcontains(string.lower(msg), string.lower(strinSay2)) and getDistanceToCreature(cid) <= 3 and talkState[talkUser] == 1 then
        local pokeCounts = 0
        if msgcontains(string.lower(msg), string.lower(strinSay1)) then
            setPlayerStorageValue(cid, storages.miniQuests.storNpcTaskName3, getCreatureName(getThis()))
            setPlayerStorageValue(cid, storages.miniQuests.storPokeNameTask3, opcoesDiarias[1][1][1])
            setPlayerStorageValue(cid, storages.miniQuests.storPokeCountTask3, opcoesDiarias[1][1][2])
            setPlayerStorageValue(cid, storages.miniQuests.storDayTask3, hora)
            pokeCounts = opcoesDiarias[1][1][2]
        else
            setPlayerStorageValue(cid, storages.miniQuests.storNpcTaskName3, getCreatureName(getThis()))
            setPlayerStorageValue(cid, storages.miniQuests.storPokeNameTask3, opcoesDiarias[2][1][1])
            setPlayerStorageValue(cid, storages.miniQuests.storPokeCountTask3, opcoesDiarias[2][1][2])
            setPlayerStorageValue(cid, storages.miniQuests.storDayTask3, hora)
            pokeCounts = opcoesDiarias[2][1][2]
        end

        selfSay('Okay. I will keep in touch with you. Good luck with ' .. pokeCounts.. ' ' .. msg .. (pokeCounts > 1 and 's' or '') .. '.')
        talkState[talkUser] = 0
        focus = 0
        tchau = true
        return true
    end
end


local tablePoke = diarias.Hard
local dificult = 3
function onThink()
    -- resetar tasks
    if hora ~= os.date("%d") then
       opcoesDiarias = {}
       tablePoke = diarias.Hard
       hora = os.date("%d")
    end
 
    if #opcoesDiarias == 0 then -- vamos iniciar as opcoesDiarias
     
        local sorteio1 = math.random(1, #tablePoke)
        local op1 = tablePoke[sorteio1]
                   table.remove(tablePoke, sorteio1)
                   strinSay1 = op1
               
        local sorteio2 = math.random(1, #tablePoke)
        local op2 = tablePoke[sorteio2]
                   table.remove(tablePoke, sorteio2)
                   strinSay2 = op2
                   
        local pokeCount1 = math.random(50, 80)    * dificult
        local pokeCount2 = math.random(50, 80)    * dificult
        opcoesDiarias[1] = { {op1, pokeCount1} }
        opcoesDiarias[2] = { {op2, pokeCount2} }
     
        expToGive1 = 680 * pokeCount1
        expToGive2 = 680 * pokeCount2
    end

    if focus  ~= 0 then
        if getDistanceToCreature(focus) > 3 then
            tchau = true
            focus = 0
        end

        if (os.clock() - talk_start) > 15 then
            if focus > 0 then
                tchau = true
                focus = 0
            end
        end
        doNpcSetCreatureFocus(focus)
    end

        if tchau then
            tchau = false
            doCreatureSetLookDir(getThis(), lookNpcDir)
            selfSay('Goodbye.')
        end
end

Here is the part that is changing the monsters. It is only changing monsters once per day, when the previous stored day (hora variable) is no longer equal to os.date("%d"). So everyday (or gameworld restart) there will be only 2 monsters to choose from.

If you want it to change for every player then you have change it to select 2 monsters after the player asks for a task.

Lua:
function onThink()
    -- resetar tasks
    if hora ~= os.date("%d") then
       opcoesDiarias = {}
       tablePoke = diarias.Hard
       hora = os.date("%d")
    end
  
    if #opcoesDiarias == 0 then -- vamos iniciar as opcoesDiarias
 
Aqui está a parte que está mudando os monstros. Só muda os monstros uma vez por dia, quando o dia anterior armazenado (variável) não é mais igual a os.date ("% d"). Portanto, todos os dias (ou reinício do mundo do jogo) haverá apenas 2 monstros para escolher.

Se você quiser que ele mude para todos os jogadores, você deve alterá-lo para selecionar 2 monstros depois que o jogador pedir uma tarefa.

[código = lua]
function onThink ()
- tarefas de reset
se hora ~ = os.date ("% d") então
opcoesDiarias = {}
tablePoke = diarias.Hard
hora = os.date ("% d")
fim

if #opcoesDiarias == 0 then - vamos iniciar as opcoesDiarias
[/ código]
can you tell me how that part of the script would look with this change?
 
I have a hard time finding something named diaras since im on the phone. But you want something like: math.random(diaras.#Easy)
I will be home in a couple of days and can look into it more then if noone havent helped you then.
 
I have a hard time finding something named diaras since im on the phone. But you want something like: math.random(diaras.#Easy)
I will be home in a couple of days and can look into it more then if noone havent helped you then.
I would like the NPC to change the monsters he gives to each player.

When the first player goes to take the mission, the npc will offer the monster X and Y. when the second player goes to take the mission the npc will offer the monster A and B. Understood?

As it is now he is offering x and y to everyone.
 
can you tell me how that part of the script would look with this change?
The easiest thing you could do, would be to change how frequently the NPC switches tasks:
Lua:
os.date("%d")
to:
Lua:
os.date("%H")
or
Lua:
os.date("%M")

%d = day of the month (1-31)
%H = hour of the day (00-23)
%M = minute of the hour (00-59)

That way he will change the monsters every 1 minute or 1 hour instead of every 1 day.

CONS:
1. If a player knows how it works they could wait a minute or hour and ask again and receive 2 new monsters. They could repeat this until they get a tasks that they like.
2. Every player that comes in the same minute or hour will get the same tasks to choose from.

Although it is an improvement from 1 change per day to 1 change per hour or minute, it's still not the best solution.


The best solution, to achieve what you want, would be to edit the code to do the random task generation at the time the player asks for a task. Store that time in a local table or an unused storage value and check next time they ask for a task that it's been 24 hours since they last asked.
 
The easiest thing you could do, would be to change how frequently the NPC switches tasks:
Lua:
os.date("%d")
to:
Lua:
os.date("%H")
or
Lua:
os.date("%M")

%d = day of the month (1-31)
%H = hour of the day (00-23)
%M = minute of the hour (00-59)

That way he will change the monsters every 1 minute or 1 hour instead of every 1 day.

CONS:
1. If a player knows how it works they could wait a minute or hour and ask again and receive 2 new monsters. They could repeat this until they get a tasks that they like.
2. Every player that comes in the same minute or hour will get the same tasks to choose from.

Although it is an improvement from 1 change per day to 1 change per hour or minute, it's still not the best solution.


The best solution, to achieve what you want, would be to edit the code to do the random task generation at the time the player asks for a task. Store that time in a local table or an unused storage value and check next time they ask for a task that it's been 24 hours since they last asked.
if I change os.date("%d") to os.date("%H") or os.date("%M") it doesn't work.

I switched to minutes and went to do the task. I finished the task and when I returned to the NPC to deliver instead of giving me the reward he gave me another task. If I do it this way I will have to finish the task in 1 minute or 1 hour, if I take longer than that he will offer me another task
 
if I change os.date("%d") to os.date("%H") or os.date("%M") it doesn't work.

I switched to minutes and went to do the task. I finished the task and when I returned to the NPC to deliver instead of giving me the reward he gave me another task. If I do it this way I will have to finish the task in 1 minute or 1 hour, if I take longer than that he will offer me another task

That's because on this line 45, you reset the task if the time is not the same as start time:

Lua:
if tonumber(minhaHora) ~= tonumber(hora) then
    setPlayerStorageValue(cid, storages.miniQuests.storNpcTaskName3, -1)
    setPlayerStorageValue(cid, storages.miniQuests.storPokeNameTask3, -1)
    setPlayerStorageValue(cid, storages.miniQuests.storPokeCountTask3, -1)
    setPlayerStorageValue(cid, storages.miniQuests.storDayTask3, -1)
end

There may be more spots where the time is checked. Go through your code and make the necessary adjustments.

If you remove the lines above, then there will be another problem. You need to add a different way reset player task after 24 hours.
 
Last edited:
Solution
Isso porque nesta linha 45, você zera a tarefa se a hora não for igual à hora de início:

[CÓDIGO = lua] se ton numero (minhaHora) ~ = ton numero (hora) então
setPlayerStorageValue (cid, storages.miniQuests.storNpcTaskName3, -1)
setPlayerStorageValue (cid, storages.miniQuests.storPokeNameTask3, -1)
setPlayerStorageValue (cid, storages.miniQuests.storPokeCountTask3, -1)
setPlayerStorageValue (cid, storages.miniQuests.storDayTask3, -1)
fim [/ CODE]

Pode haver mais locais onde a hora é verificada. Examine seu código e faça os ajustes necessários.
beauty. Thank you for your help
 
beauty. Thank you for your help
Honestly as I look at it more carefully now, it was made from the ground up to change once per day for the whole game world. So many of the variables are stored globally in the NPC file and not individually by character storage. There are still more changes needed to make it the way you want it.

Maybe on the weekend if I have time I'll re-write it for you, or maybe another person on the forum will do it.
 
Honestly as I look at it more carefully now, it was made from the ground up to change once per day for the whole game world. So many of the variables are stored globally in the NPC file and not individually by character storage. There are still more changes needed to make it the way you want it.

Maybe on the weekend if I have time I'll re-write it for you, or maybe another person on the forum will do it.

Thanks!

If you can, it would help me a lot.

Is having a lot of ks on my server because of that.
 
Back
Top