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

Lua Task system compatibily

Dreww

Banned User
Joined
Oct 7, 2011
Messages
252
Reaction score
409
Location
México
Hello everyone someone help me, im trying to use custom task system on my server (Tfs 1.3) from Mystera 5 (Tfs 1.0) with modal window like this:
1840453388a67717b78bce8fb0958085.png

I installed lib and creaturescripts but when i speak to npc it gives methis error:
794f5b95391d0c42702a8c99b5807a04.png

im pretty sure its compatibility issue but i dont have idea what i need to modify in order to make this work!
This is the line 82 from task_lib.lua:
8e6a92aad7bb8c299c06788286f4f4be.png

Maybe getCreatureStorage is 1.0 function and i need 1.3 one
thanks in advance and sorry my bad english
 
Last edited:
Hello djblah and thanks! codes:
020_task_lib.lua
Lua:
rankStorage = 32150

THESNAPPER = {80000, 1}
DEMODRAS = {80001, 1}
HIDE = {80002, 1}
THEBLOODTUSK = {80003, 1}
SHARDHEAD = {80004, 1}
THUL = {80005, 1}
ESMERALDA = {80006, 1}
THEOLDWIDOW = {80007, 1}
THEMANY = {80008, 1}
LEVIATHAN = {80009, 1}
STONECRACKER = {80010, 1}
THENOXIUSSPAWN = {80011, 1}
MERIKHTHESLAUGHTERER = {80012, 1}
FAHIMTHEWISE = {80013, 1}
RANDOMPIRATEBOSS = {80014, 1}
THEHORNEDFOX = {80015, 1}
NECROPHARUS = {80016, 1}

tasks =
{
[1] = {questStarted = 65000, questStorage = 65100, killsRequired = 100, raceName = "Trolls", repeatable = false, rewards = {{enable = true, type = "exp", values = 40000}, {enable = true, type = "money", values = 4000}}},
[2] = {questStarted = 65001, questStorage = 65101, killsRequired = 150, raceName = "Goblins", repeatable = false, rewards = {{enable = true, type = "exp", values = 70000}, {enable = true, type = "money", values = 5000}}},
[3] = {questStarted = 65002, questStorage = 65102, killsRequired = 300, raceName = "Rotworms", repeatable = false, rewards = {{enable = true, type = "exp", values = 100000}, {enable = true, type = "money", values = 6000}}},
[4] = {questStarted = 65003, questStorage = 65103, killsRequired = 500, raceName = "Cyclops", repeatable = false, rewards = {{enable = true, type = "exp", values = 150000}, {enable = true, type = "money", values = 8000}}},
[5] = {questStarted = 14007, questStorage = 14107, killsRequired = 300, raceName = "Crocodiles", repeatable = true, rewards = {{enable = true, type = "exp", values = 100000}, {enable = true, type = "storage", values = THESNAPPER}, {enable = true, type = "points", values = 2}}},
[6] = {questStarted = 14008, questStorage = 14108, killsRequired = 300, raceName = "Tarantulas", repeatable = true, rewards = {{enable = true, type = "exp", values = 150000}, {enable = true, type = "storage", values = HIDE}, {enable = true, type = "points", values = 2}}},
[7] = {questStarted = 14009, questStorage = 14109, killsRequired = 150, raceName = "Carniphilas", repeatable = false, rewards = {{enable = true, type = "exp", values = 250000}, {enable = true, type = "money", values = 15000}}},
[8] = {questStarted = 14010, questStorage = 14110, killsRequired = 200, raceName = "Stone Golems", repeatable = false, rewards = {{enable = true, type = "exp", values = 200000}, {enable = true, type = "money", values = 15000}}},
[9] = {questStarted = 14011, questStorage = 14111, killsRequired = 300, raceName = "Mammoths", repeatable = true, rewards = {{enable = true, type = "exp", values = 150000}, {enable = true, type = "storage", values = THEBLOODTUSK}, {enable = true, type = "points", values = 2}}},
[10] = {questStarted = 14012, questStorage = 14112, killsRequired = 300, raceName = "Ice Golems", repeatable = true, rewards = {{enable = true, type = "exp", values = 150000}, {enable = true, type = "storage", values = SHARDHEAD}, {enable = true, type = "points", values = 2}}},
[11] = {questStarted = 14013, questStorage = 14113, killsRequired = 300, raceName = "Quaras Scout", repeatable = true, rewards = {{enable = true, type = "exp", values = 250000}, {enable = true, type = "money", values = 25000}}},
[12] = {questStarted = 14014, questStorage = 14114, killsRequired = 300, raceName = "Quaras", repeatable = true, rewards = {{enable = true, type = "exp", values = 300000}, {enable = true, type = "storage", values = THUL}, {enable = true, type = "points", values = 2}}},
[13] = {questStarted = 14015, questStorage = 14115, killsRequired = 70, raceName = "Water Elementals", repeatable = false, rewards = {{enable = true, type = "exp", values = 200000}, {enable = true, type = "money", values = 20000}}},
[14] = {questStarted = 14016, questStorage = 14116, killsRequired = 70, raceName = "Earth Elementals", repeatable = false, rewards = {{enable = true, type = "exp", values = 200000}, {enable = true, type = "money", values = 20000}}},
[15] = {questStarted = 14017, questStorage = 14117, killsRequired = 70, raceName = "Energy Elementals", repeatable = false, rewards = {{enable = true, type = "exp", values = 200000}, {enable = true, type = "money", values = 20000}}},
[16] = {questStarted = 14018, questStorage = 14118, killsRequired = 70, raceName = "Fire Elementals", repeatable = false, rewards = {{enable = true, type = "exp", values = 200000}, {enable = true, type = "money", values = 20000}}},
[17] = {questStarted = 14019, questStorage = 14119, killsRequired = 200, raceName = "Mutated Rats", repeatable = true, rewards = {{enable = true, type = "exp", values = 150000}, {enable = true, type = "storage", values = ESMERALDA}, {enable = true, type = "points", values = 2}}},
[18] = {questStarted = 14020, questStorage = 14120, killsRequired = 500, raceName = "Giant Spiders", repeatable = true, rewards = {{enable = true, type = "exp", values = 250000}, {enable = true, type = "storage", values = THEOLDWIDOW}, {enable = true, type = "points", values = 2}}},
[19] = {questStarted = 14021, questStorage = 14121, killsRequired = 500, raceName = "Hydras", repeatable = true, rewards = {{enable = true, type = "storage", values = THEMANY}, {enable = true, type = "points", values = 4}}},
[20] = {questStarted = 14001, questStorage = 14101, killsRequired = 500, raceName = "Sea Serpents", repeatable = true, rewards = {{enable = true, type = "storage", values = LEVIATHAN}, {enable = true, type = "points", values = 4}}},
[21] = {questStarted = 14022, questStorage = 14122, killsRequired = 500, raceName = "Behemoths", repeatable = true, rewards = {{enable = true, type = "storage", values = STONECRACKER}, {enable = true, type = "points", values = 4}}},
[22] = {questStarted = 14002, questStorage = 14102, killsRequired = 375, raceName = "Serpents Spawn", repeatable = true, rewards = {{enable = true, type = "storage", values = THENOXIOUSSPAWN}, {enable = true, type = "points", values = 4}}},
[23] = {questStarted = 65022, questStorage = 65122, killsRequired = 125, raceName = "Green Djinns", repeatable = true, rewards = {{enable = true, type = "exp", values = 230000}, {enable = true, type = "money", values = 5000}, {enable = true, type = "storage", values = MERIKHTHESLAUGHTERER}}},
[24] = {questStarted = 65023, questStorage = 65123, killsRequired = 125, raceName = "Blue Djinns", repeatable = true, rewards = {{enable = true, type = "exp", values = 230000}, {enable = true, type = "money", values = 5000}, {enable = true, type = "storage", values = FAHIMTHEWISE}}},
[25] = {questStarted = 65024, questStorage = 65124, killsRequired = 300, raceName = "Pirates", repeatable = false, rewards = {{enable = true, type = "exp", values = 300000}, {enable = true, type = "money", values = 40000}, {enable = true, type = "storage", values = RANDOMPIRATEBOSS}}},
[26] = {questStarted = 14004, questStorage = 14104, killsRequired = 500, raceName = "Minotaurs", repeatable = false, rewards = {{enable = true, type = "storage", values = THEHORNEDFOX}}},
[27] = {questStarted = 14003, questStorage = 14103, killsRequired = 1000, raceName = "Magicians", repeatable = false, rewards = {{enable = true, type = "storage", values = NECROPHARUS}}},
[28] = {questStarted = 65030, questStorage = 65130, killsRequired = 500, raceName = "Dragons", repeatable = true, rewards = {{enable = true, type = "storage", values = DEMODRAS}, {enable = true, type = "exp", values = 400000}}},
[29] = {questStarted = 14023, questStorage = 14123, killsRequired = 6666, raceName = "Demons", repeatable = false, rewards = {{enable = true, type = "exp", values = 1000000}, {enable = true, type = "item", values = {10305,1}}}}}

function getTasksStarted(cid)
local tmp = {}
for k, v in pairs(tasks) do
if getCreatureStorage(cid, v.questStarted) == 1 then
table.insert(tmp, k)
end
end
return tmp
end

function getTaskByName(name)
for k, v in pairs(tasks) do
if v.raceName:lower() == name:lower() then
return k
end
end
return false
end

function sendTaskWindow(cid)
taskWindow = ModalWindow(1900, "Mission Management", "Select a task:")
local task_status = {}

if taskWindow:getId() == 1900 then
    taskWindow:addButton(1, "Select")
    taskWindow:setDefaultEnterButton(1)
    taskWindow:addButton(2, "Cancel")
    taskWindow:setDefaultEscapeButton(2)
    for i = 1, #tasks do
        if getCreatureStorage(cid, tasks[i].questStarted) == 2 then
            task_status[i] = "[completed]"
        else
            if getCreatureStorage(cid, tasks[i].questStarted) == 1 then
                task_status[i] = "[" .. getCreatureStorage(cid, tasks[i].questStorage) .. "/" .. tasks[i].killsRequired .. "]"
            else
                if getCreatureStorage(cid, tasks[i].questStarted) < 1 then
                    task_status[i] = tasks[i].killsRequired
                else
                    task_status[i] = tasks[i].killsRequired .. " [unknown]"
                end
            end
        end
      
        if getCreatureStorage(cid, tasks[i].questStarted) == 1 and getCreatureStorage(cid, tasks[i].questStorage) >= tasks[i].killsRequired then
            taskWindow:addChoice(i, tasks[i].raceName .. " [click for reward]")
        else
            taskWindow:addChoice(i, tasks[i].raceName .. ", " .. task_status[i])
        end
    end
end
taskWindow:sendToPlayer(cid)
return true
end
creaturescripts/scripts/task.lua
Lua:
local questCreatures =
{
["troll"] = {questStarted = 65000, questStorage = 65100, creatureStorage = 15000, killsRequired = 100, raceName = "Trolls"},
["demon"] = {questStarted = 14023, questStorage = 14123, creatureStorage = 15075, killsRequired = 6666, raceName = "Demons"}
}
local msgType = MESSAGE_STATUS_CONSOLE_ORANGE
function onKill(cid, target, lastHit)
local creature = questCreatures[getCreatureName(target):lower()]
if creature then
if isPlayer(target) then return true end
if getCreatureStorage(cid, creature.questStarted) > 0 then
if getCreatureStorage(cid, creature.questStorage) < creature.killsRequired then
if getCreatureStorage(cid, creature.questStorage) < 0 then
doCreatureSetStorage(cid, creature.questStorage, 0)
end
if (not isSummon(target)) then
if getCreatureStorage(cid, creature.creatureStorage) < 0 then
doCreatureSetStorage(cid, creature.creatureStorage, 0)
end
doCreatureSetStorage(cid, creature.questStorage, getCreatureStorage(cid, creature.questStorage) + 1)
doCreatureSetStorage(cid, creature.creatureStorage, getCreatureStorage(cid, creature.creatureStorage) + 1)
doPlayerSendTextMessage(cid, msgType, "[Mission]: " .. getCreatureStorage(cid,creature.questStorage) .. "/" .. creature.killsRequired .. " " .. creature.raceName .. " defeated.")
end
end
end
end
return true
end
creaturescripts/scripts/taskwindows.lua
Lua:
function onModalWindow(cid, modalWindowId, buttonId, choiceId)
    if modalWindowId ~= 1900 then
        return false
    end
   
    local rank = getCreatureStorage(cid, rankStorage)
    if rank < 0 then
        doCreatureSetStorage(cid, rankStorage, 0)
    end
                   
    local r_string = function() if tasks[choiceId].repeatable then return "repeatable" end return "not repeatable" end
    local r_article_string = function (id, amount)
        task_item_word = ""
        if amount > 1 then
            task_item_word = task_item_word .. amount .. "x " .. getItemName(id)
        else
            if ItemType(itemId):getArticle() == "" then
                task_item_word = task_item_word .. getItemName(id)
            else
                task_item_word = task_item_word .. ItemType(itemId):getArticle() .. " " .. getItemName(id)
            end
        end
    return task_item_word
    end
    local storage_string = {[80000] = "The Snapper",
[80001] = "Demodras",
[80002] = "The Hide",
[80016] = "Necropharus"
    }

    if buttonId == 1 then -- confirm task
        if getCreatureStorage(cid, tasks[choiceId].questStarted) < 1 then
            doCreatureSetStorage(cid, tasks[choiceId].questStarted, 1)
            doCreatureSetStorage(cid, tasks[choiceId].questStorage, 0)
            doCreatureSay(taskNPCuid, "In this mission you have to hunt " .. tasks[choiceId].killsRequired .. " " .. tasks[choiceId].raceName .. " down. Good luck!", TALKTYPE_PRIVATE_NP, false, cid, getThingPos(taskNPCuid))
        else
            if getCreatureStorage(cid, tasks[choiceId].questStarted) == 1 then
                if tasks[choiceId].killsRequired > getCreatureStorage(cid, tasks[choiceId].questStorage) then
                    doPlayerPopupFYI(cid,"Status: Active\nKills: " .. getCreatureStorage(cid, tasks[choiceId].questStorage) .. "/" .. tasks[choiceId].killsRequired .. " (" .. tasks[choiceId].killsRequired - getCreatureStorage(cid, tasks[choiceId].questStorage) .. " left)\n\nThis mission is " .. r_string() .. ".")
                    sendTaskWindow(cid)
                else
                    doCreatureSetStorage(cid, tasks[choiceId].questStarted, 2)
                    task_reward_str = "Reward(s):\n"
                    for i = 1, table.maxn(tasks[choiceId].rewards) do
                        if(tasks[choiceId].rewards[i].enable) then
                            if isInArray({"boss", "teleport", 1}, tasks[choiceId].rewards[i].type) then
                                doTeleportThing(cid, tasks[choiceId].rewards[i].values)
                                task_reward_str = task_reward_str .. "You have been teleported.\n"
                            elseif isInArray({"exp", "experience", 2}, tasks[choiceId].rewards[i].type) then
                                doPlayerAddExperience(cid, tasks[choiceId].rewards[i].values)
                                task_reward_str = task_reward_str .. "+ " .. tasks[choiceId].rewards[i].values .. " exp\n"
                            elseif isInArray({"item", 3}, tasks[choiceId].rewards[i].type) then
                                doPlayerAddItem(cid, tasks[choiceId].rewards[i].values[1], tasks[choiceId].rewards[i].values[2])
                                task_reward_str = task_reward_str .. r_article_string(tasks[choiceId].rewards[i].values[1], tasks[choiceId].rewards[i].values[2]) .. "\n"
                            elseif isInArray({"money", 4}, tasks[choiceId].rewards[i].type) then
                                doPlayerAddMoney(cid, tasks[choiceId].rewards[i].values)
                                task_reward_str = task_reward_str .. "+ " .. tasks[choiceId].rewards[i].values .. " gp\n"
                            elseif isInArray({"storage", "stor", 5}, tasks[choiceId].rewards[i].type) then
                                doCreatureSetStorage(cid, tasks[choiceId].rewards[i].values[1], tasks[choiceId].rewards[i].values[2])
                                task_reward_str = task_reward_str .. "Chance to duel " .. storage_string[tasks[choiceId].rewards[i].values[1]] .. ".\n"
                            elseif isInArray({"points", "rank", 2}, tasks[choiceId].rewards[i].type) then
                                doCreatureSetStorage(cid, rankStorage, getCreatureStorage(cid, rankStorage) + tasks[choiceId].rewards[i].values)
                                task_reward_str = task_reward_str .. "+ " .. tasks[choiceId].rewards[i].values .. " rank points.\n"
                            else
                                print("[Warning - Npc::KillingInTheNameOf] Wrong reward type: " .. (tasks[choiceId].rewards[i].type or "nil") .. ", reward could not be loaded.")
                            end
                        end
                    end
                    if task_reward_str == "Reward(s):\n" then
                        doPlayerPopupFYI(cid,task_reward_str .. "none")
                    else
                        doPlayerPopupFYI(cid,task_reward_str)
                    end
                    doCreatureSay(taskNPCuid, "Great job" .. (((rank > 4 and rank < 10) and (", Huntsman") or (rank > 9 and rank < 20) and (", Ranger") or (rank > 19 and rank < 30) and (", Big Game Hunter") or (rank > 29 and rank < 50) and (", Trophy Hunter") or (rank > 49) and (", Elite Hunter")) or ", my Beginner") .. "! Here is your reward. Keep hunting and good luck!", TALKTYPE_PRIVATE_NP, false, cid, getThingPos(taskNPCuid))
                end
            else
                if tasks[choiceId].repeatable then
                    for i = 1, table.maxn(tasks[choiceId].rewards) do
                        if isInArray({"storage", "stor", 5}, tasks[choiceId].rewards[i].type) then
                            doPlayerPopupFYI(cid,"To repeat this mission again, fight with " .. storage_string[tasks[choiceId].rewards[i].values[1]] .. " first.")
                            break
                        end
                        if i == table.maxn(tasks[choiceId].rewards) then
                            doPlayerPopupFYI(cid,"You can't repeat this mission.")
                        end
                    end
                else
                    doPlayerPopupFYI(cid,"You can't repeat this mission.")
                end
                sendTaskWindow(cid)
            end
        end
    elseif buttonId == 255 then
        doPlayerPopupFYI(cid,"Please use a button.")
        sendTaskWindow(cid)
    end
   
return true
end
I think thats all thank you in advance
 
Back
Top