• 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!

TFS 1.X+ [1.4.2] Daily Task problem.

OTcreator

Active Member
Joined
Feb 14, 2022
Messages
425
Solutions
1
Reaction score
44
Hi,
I have a problem with this script.
Namely, after 6 o'clock the shuffle does not change.
If someone chooses Easy and has, for example, rotworms, the next day he will still have the same monster.


I noticed , that it should be given randomly, but before math.random there is a # sign - what does it deselect?

Lua:
 DT_CHOSENTASK_EASY = DT_TasksEasy[math.random(#DT_TasksEasy)]

NPC used this code and working, but not math random monsters:

Lua:
  if DT_PREMIOQTDE_EASY > 0 then
            npcHandler:say("Your EASY daily task today is: Kill {".. DT_NEEDKILL_EASY .."} {".. DT_CHOSENTASK_EASY .."}(s).\nIf you finish before {6:00am (GTM-3)}, you will receive:\n*{".. DT_PREMIOQTDE_EASY .."}x "..getAllTableText(DT_PRIZENAME_EASY, "or")..", chosen at random;\n*{"..DT_PREMIOFIXO_QTDE_EASY.."}x "..DT_PREMIOFIXO_NAME_EASY..";\n*{"..DT_EXPPRIZE_EASY.."} Experience points;\n*{"..DT_TASKPOINTS_EASY.."}x Task Point.\nDo you want to start this {EASY} task?", cid)
        else
            npcHandler:say("Your EASY daily task today is: Kill {".. DT_NEEDKILL_EASY .."} {".. DT_CHOSENTASK_EASY .."}(s).\nIf you finish before {6:00am (GTM-3)}, you will receive:\n*{"..DT_PREMIOFIXO_QTDE_EASY.."}x "..DT_PREMIOFIXO_NAME_EASY..";\n*{"..DT_EXPPRIZE_EASY.."} Experience points;\n*{"..DT_TASKPOINTS_EASY.."}x Task Point.\nDo you want to start this {EASY} task?", cid)
        end

The only # sign that I have yet noticed is in this function:

Lua:
function getAllTableText(aa, bb, cc)
local tablecheck = aa

if not tablecheck then
    return false
end

local lang = bb
local ponto = ""
if not lang then
    lang = "and"
end
if cc then
ponto = "."
end
local text = ""
for i = 1, #tablecheck do
    if i == 1 then
    text = tablecheck[i]
    elseif i == #tablecheck then
    text = text .." "..lang.." "..tablecheck[i]..""..ponto..""
    else
    text = text ..", "..tablecheck[i]
    end
end
return text
end

Link with full code system: DailyTask ~100% (https://otland.net/threads/dailytask-100.272589/#post-2638428)

This probably only works if the server is restarted, but I'm not sure.
If you don't do a server restart, the monsters are not drawn.

Since I don't shut down the server every 24/h, I removed those lines and added in globalevents resetting storage for online players and removing storages from the database for offline players.
This all works, but there is one single problem with the monster draw.

Lua:
 --RESETAR STORAGES
        for i = 1, 6 do
        db.query('DELETE FROM `player_storage` WHERE `player_storage`.`key` = '.. 367643969+i ..'')
        end
 
I noticed , that it should be given randomly, but before math.random there is a # sign - what does it deselect?
it means length Lua 5.1 Reference Manual (https://www.lua.org/manual/5.1/manual.html#2.5.5)
It looks fine, it is selecting a random monster.

Looks like you need to run "/ data / lib / task / dailytask.lua" after 6 o'clock to update the variables?
I'm new to this so I don't know the best way but something like addEvent will do this Lua functions - OTS Guide (https://docs.otland.net/ots-guide/tfs-documentation/lua_functions#addevent-callback-delay)

What happens when you /reload scripts, does the shuffle happen?
 
it means length Lua 5.1 Reference Manual (https://www.lua.org/manual/5.1/manual.html#2.5.5)
It looks fine, it is selecting a random monster.

Looks like you need to run "/ data / lib / task / dailytask.lua" after 6 o'clock to update the variables?
I'm new to this so I don't know the best way but something like addEvent will do this Lua functions - OTS Guide (https://docs.otland.net/ots-guide/tfs-documentation/lua_functions#addevent-callback-delay)

What happens when you /reload scripts, does the shuffle happen?

Wow! You're right!
While I moved the removal of storages to globalevents, the reloading there at 6am is not there, so the script did not give new mobs!
Now I just need to figure out how to do it.

What puzzles me is why I have to reload libs at 6, since storage removes the global event and npc randomly selects a monster after typing "easy".
Why does some kind of monster save in libs occur?
 
Last edited:
Wow! You're right!
While I moved the removal of storages to globalevents, the reloading there at 6am is not there, so the script did not give new mobs!
Now I just need to figure out how to do it.

What puzzles me is why I have to reload libs at 6, since storage removes the global event and npc randomly selects a monster after typing "easy".
Why does some kind of monster save in libs occur?
It's just a poorly made system, use GlobalEvents to trigger something at a specific time. You should also never reload anything when the server is live, especially libs as TFS' reload system is not good at all.
 
To po prostu słabo wykonany system, użyj GlobalEvents, aby uruchomić coś w określonym czasie. Nigdy nie powinieneś także przeładowywać czegokolwiek, gdy serwer działa, szczególnie bibliotek, ponieważ system przeładowania TFS nie jest wcale dobry.

Ok, how to change this daily code to monsters change random automaticaly on 6AM ?
 
Try this, change task by date:

Lua:
-- SCRIPT

-- Pobierz aktualną datę
local currentDate = os.date("*t")

-- Ustaw ziarno generatora liczb losowych na podstawie daty
math.randomseed(currentDate.year * 1000 + currentDate.yday)

-- Funkcja do losowania z listy zadań
local function chooseRandomTask(taskList)
    return taskList[math.random(#taskList)]
end

-- Wybierz zadania na podstawie poziomu trudności
local function chooseTasks(difficulty)
    local task = ""
    local needKill = 0
    local expPrize = 0

    if difficulty == "easy" then
        task = chooseRandomTask(DT_TasksEasy)
        needKill = math.ceil(math.random(easy.minQTDE, easy.maxQTDE))
        expPrize = math.random(easy.minEXP, easy.maxEXP)
    elseif difficulty == "medium" then
        task = chooseRandomTask(DT_TasksMedium)
        needKill = math.ceil(math.random(medium.minQTDE, medium.maxQTDE))
        expPrize = math.random(medium.minEXP, medium.maxEXP)
    elseif difficulty == "hard" then
        task = chooseRandomTask(DT_TasksHard)
        needKill = math.ceil(math.random(hard.minQTDE, hard.maxQTDE))
        expPrize = math.random(hard.minEXP, hard.maxEXP)
    elseif difficulty == "expert" then
        task = chooseRandomTask(DT_TasksExpert)
        needKill = math.ceil(math.random(expert.minQTDE, expert.maxQTDE))
        expPrize = math.random(expert.minEXP, expert.maxEXP)
    end

    return task, needKill, expPrize
end

-- Wybierz zadania dla każdego poziomu trudności
DT_CHOSENTASK_EASY, DT_NEEDKILL_EASY, DT_EXPPRIZE_EASY = chooseTasks("easy")
DT_CHOSENTASK_MEDIUM, DT_NEEDKILL_MEDIUM, DT_EXPPRIZE_MEDIUM = chooseTasks("medium")
DT_CHOSENTASK_HARD, DT_NEEDKILL_HARD, DT_EXPPRIZE_HARD = chooseTasks("hard")
DT_CHOSENTASK_EXPERT, DT_NEEDKILL_EXPERT, DT_EXPPRIZE_EXPERT = chooseTasks("expert")

-- FUNÇÃO PRA PEGAR OS NOMES DOS ITEM
function getAllTableText(aa, bb, cc)
    local tablecheck = aa

    if not tablecheck then
        return false
    end

    local lang = bb
    local ponto = ""
    if not lang then
        lang = "and"
    end
    if cc then
        ponto = "."
    end
    local text = ""
    for i = 1, #tablecheck do
        if i == 1 then
            text = tablecheck[i]
        elseif i == #tablecheck then
            text = text .." "..lang.." "..tablecheck[i]..""..ponto..""
        else
            text = text ..", "..tablecheck[i]
        end
    end
    return text
end
 
Back
Top