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

CreatureEvent KillingInTheNameOF (task system) for OTHIRE 7.72

Hello, I use this datapack:
https://github.com/peonso/tibialegacyserver
I get this error when I write tasks:
Code:
Lua Script Error: [Npc interface]
data/npc/scripts/KillingInTheNameOf.lua:onCreatureSay

data/npc/scripts/KillingInTheNameOf.lua:22: attempt to call global 'getTasksByPlayer' (a nil value)
stack traceback:
        data/npc/scripts/KillingInTheNameOf.lua:22: in function 'callback'
        data/npc/scripts/lib/npcsystem/npchandler.lua:301: in function 'onCreatureSay'
        data/npc/scripts/KillingInTheNameOf.lua:8: in function <data/npc/scripts/KillingInTheNameOf.lua:8>
It works when I use normal othire data, can someone please help me?
@Peonso meaby?
getTasksByPlayer function is not implemented
 
I get this error:
16lbw5z.png


Can you help me to implement that?
 
Hello this script work Othire 0.0.3

Npctask.lua
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
function onCreatureAppear(cid) npcHandler:eek:nCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:eek:nCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:eek:nCreatureSay(cid, type, msg) end
function onThink() npcHandler:eek:nThink() end
keywordHandler:addKeyword({'task'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Help me and kill rat or bug?"})
keywordHandler:addKeyword({'mission'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Help me and kill rat or bug??"})
function creatureSayCallback(cid, type, msg)
function creatureSayCallback(cid, type, msg)
return false
end

local storage = 82000
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

if msgcontains(msg, 'tarantula')then
if getPlayerStorageValue(cid, 82006) == -1 then
npcHandler:say("Do you can help me and kill 200 of this creatures?", cid)
talk_state = 1
elseif getPlayerStorageValue(cid, storage) == 12 then
npcHandler:say("Great! You killed 200 Tarantula and finished the task. Your reward is 5000 gold coins 70000 experience points.", cid)
setPlayerStorageValue(cid, storage, -12)
doPlayerAddExp(cid, 70000)
doPlayerAddMoney(cid, 5000)

else
npcHandler:say("I do not have anymore quests for you, adventurer.", cid)
end
elseif msgcontains(msg, 'yes') and talk_state == 1 then
npcHandler:say("I appreciate that! Now go and kill 200 of this creatures, then back to me if you done this.", cid)
setPlayerStorageValue(cid, storage, 11)
talk_state = 2
end

if msgcontains(msg, 'giant spider') then
if getPlayerStorageValue(cid, 82007) == -1 then
npcHandler:say("Do you can help me and kill 50 of this creatures?", cid)
talk_state = 3
elseif getPlayerStorageValue(cid, storage) == 14 then
npcHandler:say("Great! You killed 50 Giant Spiders and finished the task. Your reward is 10.000 gold coins 100000 experience points.", cid)
setPlayerStorageValue(cid, storage, -14)
doPlayerAddExp(cid, 100000)
doPlayerAddItem(cid, 2160, 1)
else
npcHandler:say("I do not have anymore quests for you, adventurer.", cid)
end
elseif msgcontains(msg, 'yes') and talk_state == 3 then
npcHandler:say("I appreciate that! Now go and kill 50 of this creatures, then back to me if you done this.", cid)
setPlayerStorageValue(cid, storage, 13)
talk_state = 4



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



data/creaturescript/script create tsak.lua
and paste this code

function onKill(cid, target)
local config = {
["spider"] = {storage = 82001, begin_storage_value = 1, finished_storage_value = 2, count = 30},
["bug"] = {storage = 82002, begin_storage_value = 3, finished_storage_value = 4, count = 50},
["rat"] = {storage = 82003, begin_storage_value = 5, finished_storage_value = 6, count = 30},
["cave rat"] = {storage = 82003, begin_storage_value = 5, finished_storage_value = 6, count = 30},

["rotworm"] = {storage = 82004, begin_storage_value = 7, finished_storage_value = 8, count = 100},
["centipede"] = {storage = 82005, begin_storage_value = 9, finished_storage_value = 10, count = 50},
["slime"] = {storage = 82023, begin_storage_value = 45, finished_storage_value = 46, count = 50},
["cyclops"] = {storage = 82013, begin_storage_value = 25, finished_storage_value = 26, count = 300},


["tarantula"] = {storage = 82006, begin_storage_value = 11, finished_storage_value = 12, count = 200},
["giant spider"] = {storage = 82007, begin_storage_value = 13, finished_storage_value = 14, count = 50},

["larva"] = {storage = 82033, begin_storage_value = 65, finished_storage_value = 66, count = 50},
["scarab"] = {storage = 82034, begin_storage_value = 67, finished_storage_value = 68, count = 100},
["ancient scarab"] = {storage = 82035, begin_storage_value = 69, finished_storage_value = 70, count = 100},
["kongra"] = {storage = 82036, begin_storage_value = 71, finished_storage_value = 72, count = 100},
["sibang"] = {storage = 82036, begin_storage_value = 71, finished_storage_value = 72, count = 100},
["merlkin"] = {storage = 82036, begin_storage_value = 71, finished_storage_value = 72, count = 100},
["dworc venomsniper"] = {storage = 82027, begin_storage_value = 53, finished_storage_value = 54, count = 150},
["dworc voodoomaster"] = {storage = 82027, begin_storage_value = 53, finished_storage_value = 54, count = 150},
["dworc fleshhunter"] = {storage = 82027, begin_storage_value = 53, finished_storage_value = 54, count = 150},
["lizard sentinel"] = {storage = 82028, begin_storage_value = 55, finished_storage_value = 56, count = 100},
["lizard templar"] = {storage = 82028, begin_storage_value = 55, finished_storage_value = 56, count = 100},
["lizard snakecharmer"] = {storage = 82028, begin_storage_value = 55, finished_storage_value = 56, count = 100},
["hydra"] = {storage = 82008, begin_storage_value = 15, finished_storage_value = 16, count = 300},
["serpent spawn"] = {storage = 82009, begin_storage_value = 17, finished_storage_value = 18, count = 100},


["dragon"] = {storage = 82010, begin_storage_value = 19, finished_storage_value = 20, count = 300},
["dragon lord"] = {storage = 82011, begin_storage_value = 21, finished_storage_value = 22, count = 200},
["black knight"] = {storage = 82012, begin_storage_value = 23, finished_storage_value = 24, count = 20},



["troll"] = {storage = 82015, begin_storage_value = 29, finished_storage_value = 30, count = 50},
["skeleton"] = {storage = 82016, begin_storage_value = 31, finished_storage_value = 32, count = 50},
["ghoul"] = {storage = 82017, begin_storage_value = 33, finished_storage_value = 34, count = 150},
["minotaur"] = {storage = 82018, begin_storage_value = 35, finished_storage_value = 36, count = 100},
["minotaur guard"] = {storage = 82019, begin_storage_value = 37, finished_storage_value = 38, count = 100},
["minotaur mage"] = {storage = 82020, begin_storage_value = 39, finished_storage_value = 40, count = 20},

["orc"] = {storage = 82021, begin_storage_value = 41, finished_storage_value = 42, count = 100},
["orc warrior"] = {storage = 82021, begin_storage_value = 41, finished_storage_value = 42, count = 100},
["orc spearman"] = {storage = 82021, begin_storage_value = 41, finished_storage_value = 42, count = 100},

["warlock"] = {storage = 82022, begin_storage_value = 43, finished_storage_value = 44, count = 300},

["beholder"] = {storage = 82024, begin_storage_value = 47, finished_storage_value = 48, count = 40},

["orc berserker"] = {storage = 82025, begin_storage_value = 49, finished_storage_value = 50, count = 150},
["orc leader"] = {storage = 82025, begin_storage_value = 49, finished_storage_value = 50, count = 150},
["orc warlord"] = {storage = 82026, begin_storage_value = 51, finished_storage_value = 52, count = 50},

["dwarf"] = {storage = 82029, begin_storage_value = 57, finished_storage_value = 58, count = 200},
["dwarf soldier"] = {storage = 82029, begin_storage_value = 57, finished_storage_value = 58, count = 200},
["dwarf guard"] = {storage = 82030, begin_storage_value = 59, finished_storage_value = 60, count = 100},
["dwarf geomancer"] = {storage = 82030, begin_storage_value = 59, finished_storage_value = 60, count = 100},

["elf"] = {storage = 82031, begin_storage_value = 61, finished_storage_value = 62, count = 100},
["elf scout"] = {storage = 82031, begin_storage_value = 61, finished_storage_value = 62, count = 100},
["elf arcanist"] = {storage = 82032, begin_storage_value = 63, finished_storage_value = 64, count = 40},

["amazon"] = {storage = 82037, begin_storage_value = 73, finished_storage_value = 74, count = 100},
["valkyrie"] = {storage = 82037, begin_storage_value = 73, finished_storage_value = 74, count = 100},
["witch"] = {storage = 82038, begin_storage_value = 75, finished_storage_value = 76, count = 20},

["demon"] = {storage = 82039, begin_storage_value = 77, finished_storage_value = 78, count = 200},
["banshee"] = {storage = 82041, begin_storage_value = 81, finished_storage_value = 82, count = 30},
["behemoth"] = {storage = 82014, begin_storage_value = 27, finished_storage_value = 28, count = 200},

["hero"] = {storage = 82042, begin_storage_value = 83, finished_storage_value = 84, count = 150},
["priestess"] = {storage = 82050, begin_storage_value = 99, finished_storage_value = 100, count = 30},

["ghost"] = {storage = 82043, begin_storage_value = 85, finished_storage_value = 86, count = 40},

["smuggler"] = {storage = 82044, begin_storage_value = 87, finished_storage_value = 88, count = 200},
["wild warrior"] = {storage = 82044, begin_storage_value = 87, finished_storage_value = 88, count = 200},
["bandit"] = {storage = 82044, begin_storage_value = 87, finished_storage_value = 88, count = 200},

["mummy"] = {storage = 82045, begin_storage_value = 89, finished_storage_value = 90, count = 50},
["necromancer"] = {storage = 82046, begin_storage_value = 91, finished_storage_value = 92, count = 300},
["crypt shambler"] = {storage = 82047, begin_storage_value = 93, finished_storage_value = 94, count = 50},
["bonebeast"] = {storage = 82048, begin_storage_value = 95, finished_storage_value = 96, count = 200},
["vampire"] = {storage = 82049, begin_storage_value = 97, finished_storage_value = 98, count = 200},
["lich"] = {storage = 82040, begin_storage_value = 79, finished_storage_value = 80, count = 30},

["demon skeleton"] = {storage = 82051, begin_storage_value = 101, finished_storage_value = 102, count = 50},


["marid"] = {storage = 82052, begin_storage_value = 103, finished_storage_value = 104, count = 100},
["efreet"] = {storage = 82052, begin_storage_value = 103, finished_storage_value = 104, count = 100},
["green djinn"] = {storage = 82052, begin_storage_value = 103, finished_storage_value = 104, count = 100},
["blue djinn"] = {storage = 82052, begin_storage_value = 103, finished_storage_value = 104, count = 100},

["yeti"] = {storage = 82053, begin_storage_value = 105, finished_storage_value = 106, count = 20},
["ice warrior"] = {storage = 82054, begin_storage_value = 107, finished_storage_value = 108, count = 50},

["pirate buccaneer"] = {storage = 82055, begin_storage_value = 109, finished_storage_value = 110, count = 300},
["pirate corsair"] = {storage = 82055, begin_storage_value = 109, finished_storage_value = 110, count = 300},
["pirate cutthroat"] = {storage = 82055, begin_storage_value = 109, finished_storage_value = 110, count = 300},



}
local mob = config[string.lower(getCreatureName(target))]
if(not mob) then
return true
end
local main_storage = 82000
if(isPlayer(target) ~= TRUE) then
local count_monsters = getPlayerStorageValue(cid, mob.storage)
if(count_monsters == 0 or count_monsters == -1) then
count_monsters = 1
end

if(isPlayer(target) ~= TRUE) then
if getPlayerStorageValue(cid, main_storage) == mob.begin_storage_value and count_monsters <= mob.count then
setPlayerStorageValue(cid, mob.storage, count_monsters + 1)
doPlayerSendTextMessage(cid, TALKTYPE_ORANGE_1, "You killed "..count_monsters.." of "..mob.count.." "..getCreatureName(target).."s.")
if count_monsters == mob.count then
setPlayerStorageValue(cid, main_storage, mob.finished_storage_value)
doPlayerSendTextMessage(cid, TALKTYPE_ORANGE_1, "Congratulations! You have killed enough "..getCreatureName(target).."s.")
end
elseif getPlayerStorageValue(cid, bosses_storage) == mob.begin_storage_value and count_monsters == mob.count then
setPlayerStorageValue(cid, main_storage, mob.finished_storage_value)
doPlayerSendTextMessage(cid, TALKTYPE_ORANGE_1, "Congratulations! You have killed "..getCreatureName(target)..".")
end
end
end
return true
end

edite login.lua
and paste this :
registerCreatureEvent(cid, "onKill")

creaturescripts.xml
add this
<event name="onKill" type="kill" script="task.lua"/>


Work perfect :)
 
Paste that on the bottom of functions.la

Code:
-- TASK


RANK_NONE = 0
RANK_HUNTSMAN = 1
RANK_RANGER = 2
RANK_BIGGAMEHUNTER = 3
RANK_TROPHYHUNTER = 4
RANK_ELITEHUNTER = 5

REWARD_MONEY = 1
REWARD_EXP = 2
REWARD_ACHIEVEMENT = 3
REWARD_STORAGE = 4
REWARD_POINT = 5
REWARD_ITEM = 6

QUESTSTORAGE_BASE = 71500
KILLSSTORAGE_BASE = 72500
REPEATSTORAGE_BASE = 73500
POINTSSTORAGE = 72500
ONTASKSTORAGE = 74500
tasks =
{
[1] = {killsRequired = 50, raceName = "Noob", level = {1, 666}, premium = false, creatures = {"rat", "cave rat", "spider", "poison spider", "bug"}, rewards = {
{type = "exp", value = {8000}},
{type = "money", value = {5000}},
{type = "points", value = {1}},
{type = "storage", value = {81500,1}}
}},
[2] = {killsRequired = 50, raceName = "Orcs", level = {1, 666}, premium = false, creatures = {"orc", "orc warrior", "orc spearman", "orc berserker", "orc leader"}, rewards = {
{type = "exp", value = {10000}},
{type = "money", value = {3500}},
{type = "points", value = {1}}
}},
[3] = {bkillsRequired = 300, raceName = "Crocodiles", level = {1, 666}, premium = false, creatures = {"crocodile"}, rewards = {
{type = "exp", value = {20000}},
{type = "item", value = {2536,1}},
{type = "points", value = {1}},
{type = "storage", value = {81500,3}}
}},
[4] = {killsRequired = 300, raceName = "Tarantulas", level = {1, 666}, premium = false, creatures = {"tarantula"}, rewards = {
{type = "exp", value = {30000}},
{type = "points", value = {1}},
{type = "storage", value = {81500,4}}
}},
[5] = {killsRequired = 150, raceName = "Carniphilas", level = {1, 666}, premium = false, creatures = {"carniphila"}, rewards = {
{type = "exp", value = {30000}},
{type = "item", value = {2477,1}},
{type = "points", value = {1}},
{type = "storage", value = {81500,5}}
}}
}

tasksByPlayer = 3
repeatTimes = 3

function getPlayerRank(cid)
return (getPlayerStorageValue(cid, POINTSSTORAGE) >= 100 and RANK_ELITEHUNTER or getPlayerStorageValue(cid, POINTSSTORAGE) >= 70 and RANK_TROPHYHUNTER or getPlayerStorageValue(cid, POINTSSTORAGE) >= 40 and RANK_BIGGAMEHUNTER or getPlayerStorageValue(cid, POINTSSTORAGE) >= 20 and RANK_RANGER or getPlayerStorageValue(cid, POINTSSTORAGE) >= 10 and RANK_HUNTSMAN or RANK_NONE)
end

function getTaskByName(name, table)
local t = (table and table or tasks)
for k, v in pairs(t) do
if v.name then
if v.name:lower() == name:lower() then
return k
end
else
if v.raceName:lower() == name:lower() then
return k
end
end
end
return false
end

function getTasksByPlayer(cid)
local canmake = {}
local able = {}
for k, v in pairs(tasks) do
if getPlayerStorageValue(cid, QUESTSTORAGE_BASE + k) < 1 and getPlayerStorageValue(cid, REPEATSTORAGE_BASE + k) < repeatTimes then
able[k] = true
if getPlayerLevel(cid) < v.level[1] or getPlayerLevel(cid) > v.level[2] then
able[k] = false
end
if v.storage and getPlayerStorageValue(cid, v.storage[1]) < v.storage[2] then
able[k] = false
end

if v.rank then
if getPlayerRank(cid) < v.rank then
able[k] = false
end
end

if v.premium then
if not isPremium(cid) then
able[k] = false
end
end

if able[k] then
table.insert(canmake, k)
end
end
end
return canmake
end


function canStartTask(cid, name, table)
local v = ""
local id = 0
local t = (table and table or tasks)
for k, i in pairs(t) do
if i.name then
if i.name:lower() == name:lower() then
v = i
id = k
break
end
else
if i.raceName:lower() == name:lower() then
v = i
id = k
break
end
end
end
if v == "" then
return false
end
if getPlayerStorageValue(cid, QUESTSTORAGE_BASE + id) > 0 then
return false
end
if (getPlayerStorageValue(cid, REPEATSTORAGE_BASE + id) >= repeatTimes) or (v.norepeatable and getPlayerStorageValue(cid, REPEATSTORAGE_BASE + id) > 0) then
return false
end
if getPlayerLevel(cid) >= v.level[1] and getPlayerLevel(cid) <= v.level[2] then
if v.premium then
if isPremium(cid) then
if v.rank then
if getPlayerRank(cid) >= v.rank then
if v.storage then
if getPlayerStorageValue(cid, v.storage[1]) >= v.storage[2] then
return true
end
else
return true
end
end
else
return true
end
end
else
return true
end
end
return false
end

function getPlayerStartedTasks(cid)

local tmp = {}
for k, v in pairs(tasks) do
if getPlayerStorageValue(cid, QUESTSTORAGE_BASE + k) > 0 and getPlayerStorageValue(cid, QUESTSTORAGE_BASE + k) < 2 then
table.insert(tmp, k)
end
end
return tmp
end

function isSummon(target)
return (getCreatureMaster(target) ~= target)
end

Hi should KILLSSTORAGE_BASE = 72500 and POINTSSTORAGE = 72500 had the same storage value ?
 
I have this error in console when i try to use this lib+scripts:

5UD7by.png


Help please!
 
20:00 1/5 Noob already killed.
20:00 2/5 Noob already killed.
20:00 3/5 Noob already killed.
20:00 4/5 Noob already killed.
20:00 5/5 Noob already killed.

the main girizzly adams worked for me like a charm

Rewards loaded
Rewards loaded
Rewards loaded
Rewards loaded

0 console errors

thanks @Stellow
 
20:00 1/5 Noob already killed.
20:00 2/5 Noob already killed.
20:00 3/5 Noob already killed.
20:00 4/5 Noob already killed.
20:00 5/5 Noob already killed.

the main girizzly adams worked for me like a charm

Rewards loaded
Rewards loaded
Rewards loaded
Rewards loaded

0 console errors

thanks @Stellow

Nice to hear!
 
Hello, can you help me with a command to show task progress? Like !task
It's your lucky day!

Code:
function onSay(cid, words, param)
    if(param == '') then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "!task list, check your current list of undergoing tasks.")
        return true
    end
  
    if(param == 'list') then
        local started = getPlayerStartedTasks(cid)
        if(started and #started > 0) then
            local text = ""
            local sep = ", "
            table.sort(started, (function(a, b) return (a < b) end))
            local t = 0
            for _, id in ipairs(started) do
                t = t + 1
                if t == #started - 1 then
                    sep = " and "
                elseif t == #started then
                    sep = "."
                end
                local amount = getPlayerStorageValue(cid, KILLSSTORAGE_BASE + getTaskByName(tasks[id].name or tasks[id].raceName));
              
                text = text .. "" .. (tasks[id].name or tasks[id].raceName) .. " (".. amount.."/"..(tasks[id].killsRequired)..")" .. sep;
            end
            doPlayerSendTextMessage(cid,MESSAGE_STATUS_CONSOLE_BLUE,"The current task" .. (#started > 1 and "s" or "") .. " that you started " .. (#started > 1 and "are" or "is") .. " " .. text)
        else
            doPlayerSendTextMessage(cid,MESSAGE_STATUS_CONSOLE_BLUE,"You haven't started any task yet.")
        end
    end
    return true
end
Code:
<talkaction words="!task" access="0" filter="first word" script="taskinfo.lua"/>
 
It's your lucky day!

Code:
function onSay(cid, words, param)
    if(param == '') then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "!task list, check your current list of undergoing tasks.")
        return true
    end
 
    if(param == 'list') then
        local started = getPlayerStartedTasks(cid)
        if(started and #started > 0) then
            local text = ""
            local sep = ", "
            table.sort(started, (function(a, b) return (a < b) end))
            local t = 0
            for _, id in ipairs(started) do
                t = t + 1
                if t == #started - 1 then
                    sep = " and "
                elseif t == #started then
                    sep = "."
                end
                local amount = getPlayerStorageValue(cid, KILLSSTORAGE_BASE + getTaskByName(tasks[id].name or tasks[id].raceName));
             
                text = text .. "" .. (tasks[id].name or tasks[id].raceName) .. " (".. amount.."/"..(tasks[id].killsRequired)..")" .. sep;
            end
            doPlayerSendTextMessage(cid,MESSAGE_STATUS_CONSOLE_BLUE,"The current task" .. (#started > 1 and "s" or "") .. " that you started " .. (#started > 1 and "are" or "is") .. " " .. text)
        else
            doPlayerSendTextMessage(cid,MESSAGE_STATUS_CONSOLE_BLUE,"You haven't started any task yet.")
        end
    end
    return true
end
Code:
<talkaction words="!task" access="0" filter="first word" script="taskinfo.lua"/>

Thank you so much!
@Olddies it's because when you try to cancel a task, you have to know which task are you doing and say to NPC for cancel
 
Yeah players forget sometimes! Now you see which one you chosen and amount of them.
 
Can somebody help me? I'm using this system in my tfs 1.x it's working but is not displaying killed monsters in tasks, how can i add that feature? so if a player kil for example 40 minotaur during a task it will display something like you have killed 40/70 minotaurs?

I'm trying to use this in tfs 1.3 can somebody help me?

Creaturescriptsxml

Lua:
    <event type="kill" name="KillTask" script="killtask.lua"/>
  <event type="login" name="TaskLogin" script="tasklogin.lua"/>

killtask.lua

Code:
function onKill(cid, target, lastHit)

    local started = getPlayerStartedTasks(cid)
    if isPlayer(target) then return true end
    if started and #started > 0 then
        for _, id in ipairs(started) do
            if isInArray(tasks[id].creatures, getCreatureName(target):lower()) then
                if getCreatureStorage(cid, KILLSSTORAGE_BASE + id) < 0 then
                    doCreatureSetStorage(cid, KILLSSTORAGE_BASE + id, 0)
                end
                if getCreatureStorage(cid, KILLSSTORAGE_BASE + id) < tasks[id].killsRequired then
                    doCreatureSetStorage(cid, KILLSSTORAGE_BASE + id, getCreatureStorage(cid, KILLSSTORAGE_BASE + id) + 1)
                    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, getCreatureStorage(cid, KILLSSTORAGE_BASE + id) .. "/" .. tasks[id].killsRequired .. " " .. tasks[id].raceName .. " already killed.")
                end
            end
        end
    end
    return true
end
tasklogin.lua
Code:
function onLogin(player)
player:registerEvent('KillTask')
return true
end

in creaturescripts login.lua. i added it just in case

Code:
player:registerEvent('KillTask')

also in creaturescripts i added tasklogin.lua

Code:
function onLogin(player)
player:registerEvent('KillTask')
return true
end

to avoid some errors in console i added this code line in compat.lua

Code:
getCreatureStorage = getPlayerStorageValue

i added this at data/lib/task.lua.
And the same code of task.lua was added inside:
global.lua. in data/lib/customfunctions.lua and inside. data/npc/lib/npcsystem/custommosdules.lua

Code:
-- TASK


RANK_NONE = 0
RANK_HUNTSMAN = 1
RANK_RANGER = 2
RANK_BIGGAMEHUNTER = 3
RANK_TROPHYHUNTER = 4
RANK_ELITEHUNTER = 5

REWARD_MONEY = 1
REWARD_EXP = 2
REWARD_ACHIEVEMENT = 3
REWARD_STORAGE = 4
REWARD_POINT = 5
REWARD_ITEM = 6

QUESTSTORAGE_BASE = 1500
KILLSSTORAGE_BASE = 65000
REPEATSTORAGE_BASE = 48950
POINTSSTORAGE = 2500
tasks =
{
[1] = {bossName = "mickey", killsRequired = 5, raceName = "Noob", level = {1, 666}, premium = false, creatures = {"rat", "cave rat", "spider", "poison spider", "bug"}, rewards = {
{type = "exp", value = {8000}},
{type = "money", value = {5000}},
{type = "points", value = {1}}
--{type = "storage", value = {81500,1}}
}},
[2] = {killsRequired = 50, raceName = "Orcs", level = {1, 666}, premium = false, creatures = {"orc", "orc warrior", "orc spearman", "orc berserker", "orc leader"}, rewards = {
{type = "exp", value = {10000}},
{type = "money", value = {3500}},
{type = "points", value = {1}}
}}


-- dragons, cyclops, quaras
}

tasksByPlayer = 3
repeatTimes = 3

function getPlayerRank(cid)
    return (getPlayerStorageValue(cid, POINTSSTORAGE) >= 100 and RANK_ELITEHUNTER or getPlayerStorageValue(cid, POINTSSTORAGE) >= 70 and RANK_TROPHYHUNTER or getPlayerStorageValue(cid, POINTSSTORAGE) >= 40 and RANK_BIGGAMEHUNTER or getPlayerStorageValue(cid, POINTSSTORAGE) >= 20 and RANK_RANGER or getPlayerStorageValue(cid, POINTSSTORAGE) >= 10 and RANK_HUNTSMAN or RANK_NONE)
end

function getTaskByName(name, table)
    local t = (table and table or tasks)
    for k, v in pairs(t) do
        if v.name then
            if v.name:lower() == name:lower() then
                return k
            end
        else
            if v.raceName:lower() == name:lower() then
                return k
            end
        end
    end
    return false
end

function getTasksByPlayer(cid)
    local canmake = {}
    local able = {}
    for k, v in pairs(tasks) do
        if getCreatureStorage(cid, QUESTSTORAGE_BASE + k) < 1 and getCreatureStorage(cid, REPEATSTORAGE_BASE + k) < repeatTimes then
            able[k] = true
            if getPlayerLevel(cid) < v.level[1] or getPlayerLevel(cid) > v.level[2] then
                able[k] = false
            end
            if v.storage and getCreatureStorage(cid, v.storage[1]) < v.storage[2] then
                able[k] = false
            end
            
            if v.rank then
                if getPlayerRank(cid) < v.rank then
                    able[k] = false
                end
            end
            
            if v.premium then
                if not isPremium(cid) then
                    able[k] = false
                end
            end
        
            if able[k] then
                table.insert(canmake, k)
            end
        end
    end
    return canmake
end
            

function canStartTask(cid, name, table)
    local v = ""
    local id = 0
    local t = (table and table or tasks)
    for k, i in pairs(t) do
        if i.name then
            if i.name:lower() == name:lower() then
                v = i
                id = k
                break
            end
        else
            if i.raceName:lower() == name:lower() then
                v = i
                id = k
                break
            end
        end
    end
    if v == "" then
        return false
    end
    if getCreatureStorage(cid, QUESTSTORAGE_BASE + id) > 0 then
        return false
    end
    if (getCreatureStorage(cid, REPEATSTORAGE_BASE +  id) >= repeatTimes) or (v.norepeatable and getCreatureStorage(cid, REPEATSTORAGE_BASE +  id) > 0) then
        return false
    end
    if getPlayerLevel(cid) >= v.level[1] and getPlayerLevel(cid) <= v.level[2] then
        if v.premium then
            if isPremium(cid) then
                if v.rank then
                    if getPlayerRank(cid) >= v.rank then
                        if v.storage then
                            if getCreatureStorage(cid, v.storage[1]) >= v.storage[2] then
                                return true
                            end
                        else
                            return true
                        end
                    end
                else
                    return true
                end
            end
        else
            return true
        end
    end
    return false
end

function getPlayerStartedTasks(cid)

    local tmp = {}
    for k, v in pairs(tasks) do
        if getCreatureStorage(cid, QUESTSTORAGE_BASE + k) > 0 and getCreatureStorage(cid, QUESTSTORAGE_BASE + k) < 2 then
            table.insert(tmp, k)
        end
    end
    return tmp
end

function isSummon(cid)
    return getCreatureMaster(cid) ~= cid or false
end

npc killinginthenameof.lua
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

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() end

local choose = {}
local cancel = {}
local available = {}
function creatureSayCallback(cid, type, msg)

if npcHandler.focus ~= cid then
return false
end
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_PRIVATE and 0 or cid

if isInArray({"tasks", "task", "mission"}, msg:lower()) then
local can = getTasksByPlayer(cid)
if #can > 0 then
local text = ""
local sep = ", "
table.sort(can, (function(a, b) return (a < b) end))
local t = 0
for _, id in ipairs(can) do
t = t + 1
if t == #can - 1 then
sep = " and "
elseif t == #can then
sep = "."
end
text = text .. "{" .. (tasks[id].name or tasks[id].raceName) .. "}" .. sep
end
selfSay("The current task" .. (#can > 1 and "s" or "") .. " that you can choose " .. (#can > 1 and "are" or "is") .. " " .. text)
talkState[talkUser] = 0
else
selfSay("I don't have any task for you right now.")
end
elseif msg ~= "" and canStartTask(cid, msg) then
if #getPlayerStartedTasks(cid) >= tasksByPlayer then
selfSay("Sorry, but you already started " .. tasksByPlayer .. " tasks.")
return true
end
local task = getTaskByName(msg)
if task and getPlayerStorageValue(cid, QUESTSTORAGE_BASE + task) > 0 then
return false
end
selfSay("In this task you must defeat " .. tasks[task].killsRequired .. " " .. tasks[task].raceName .. ". Are you sure that you want to start this task?")
choose[cid] = task
talkState[talkUser] = 1
elseif msg:lower() == "yes" and talkState[talkUser] == 1 then
setPlayerStorageValue(cid, QUESTSTORAGE_BASE + choose[cid], 1)
selfSay("Excellent! You can check the status of your task saying report to me.")
choose[cid] = nil
talkState[talkUser] = 0
elseif msg:lower() == "report" then
local started = getPlayerStartedTasks(cid)
local finishedAtLeastOne = false
local finished = 0
if started and #started > 0 then
for _, id in ipairs(started) do
if getPlayerStorageValue(cid, KILLSSTORAGE_BASE + id) >= tasks[id].killsRequired then
for _, reward in ipairs(tasks[id].rewards) do
print("Rewards loaded")
local deny = false
if reward.storage then
if getPlayerStorageValue(cid, reward.storage[1]) >= reward.storage[2] then
deny = true
end
end
if isInArray({REWARD_MONEY, "money"}, reward.type:lower()) and not deny then
doPlayerAddMoney(cid, reward.value[1])
elseif isInArray({REWARD_EXP, "exp", "experience"}, reward.type:lower()) and not deny then
doPlayerAddExp(cid, reward.value[1])
doPlayerSendDefaultCancel(cid, "You gained " .. reward.value[1] .. " experience points.")
elseif isInArray({REWARD_ACHIEVEMENT, "achievement", "ach"}, reward.type:lower()) and not deny then
if doPlayerAddAchievement then
doPlayerAddAchievement(cid, reward.value[1], true)
end
elseif isInArray({REWARD_STORAGE, "storage", "stor"}, reward.type:lower()) and not deny then
setPlayerStorageValue(cid, reward.value[1], reward.value[2])
elseif isInArray({REWARD_POINT, "points", "point"}, reward.type:lower()) and not deny then
setPlayerStorageValue(cid, POINTSSTORAGE, getPlayerStorageValue(cid, POINTSSTORAGE) + reward.value[1])
elseif isInArray({REWARD_ITEM, "item", "items", "object"}, reward.type:lower()) and not deny then
doPlayerAddItem(cid, reward.value[1], reward.value[2])
end

if reward.storage then
setPlayerStorageValue(cid, reward.storage[1], reward.storage[2])
end
end

if tasks[id].norepeatable then
setPlayerStorageValue(cid, QUESTSTORAGE_BASE + id, 2)
else
setPlayerStorageValue(cid, QUESTSTORAGE_BASE + id, 0)
end
setPlayerStorageValue(cid, KILLSSTORAGE_BASE + id, 0)
if getPlayerStorageValue(cid, REPEATSTORAGE_BASE + id) < 1 then
setPlayerStorageValue(cid, REPEATSTORAGE_BASE + id, 0)
end
setPlayerStorageValue(cid, REPEATSTORAGE_BASE + id, getPlayerStorageValue(cid, REPEATSTORAGE_BASE + id) + 1)
finishedAtLeastOne = true
finished = finished + 1
end
end

if not finishedAtLeastOne then
selfSay("You haven't finished any task yet.")
else
selfSay("Awesome! you finished " .. (finished > 1 and "various" or "a") .. " task" .. (finished > 1 and "s" or "") .. ". Talk to me again if you want to start a task.")
end
else
selfSay("You haven't started any task yet.")
end
elseif msg:lower() == "started" then
local started = getPlayerStartedTasks(cid)
if started and #started > 0 then
local text = ""
local sep = ", "
table.sort(started, (function(a, b) return (a < b) end))
local t = 0
for _, id in ipairs(started) do
t = t + 1
if t == #started - 1 then
sep = " and "
elseif t == #started then
sep = "."
end
text = text .. "{" .. (tasks[id].name or tasks[id].raceName) .. "}" .. sep
end

selfSay("The current task" .. (#started > 1 and "s" or "") .. " that you started " .. (#started > 1 and "are" or "is") .. " " .. text)
else
selfSay("You haven't started any task yet.")
end
elseif msg:lower() == "cancel" then
local started = getPlayerStartedTasks(cid)
if started and #started > 0 then
selfSay("Cancelling a task will make the count restart. Wich task you want to cancel?")
talkState[talkUser] = 2
else
selfSay("You haven't started any task yet.")
end
elseif getTaskByName(msg) and talkState[talkUser] == 2 and isInArray(getPlayerStartedTasks(cid), getTaskByName(msg)) then
local task = getTaskByName(msg)
if getPlayerStorageValue(cid, KILLSSTORAGE_BASE + task) > 0 then
selfSay("You currently killed " .. getPlayerStorageValue(cid, KILLSSTORAGE_BASE + task) .. "/" .. tasks[task].killsRequired .. " " .. tasks[task].raceName .. ". Cancelling this task will restart the count. Are you sure you want to cancel this task?")
else
selfSay("Are you sure you want to cancel this task?")
end
talkState[talkUser] = 3
cancel[cid] = task
elseif msg:lower() == "yes" and talkState[talkUser] == 3 then
setPlayerStorageValue(cid, QUESTSTORAGE_BASE + cancel[cid], -1)
setPlayerStorageValue(cid, KILLSSTORAGE_BASE + cancel[cid], -1)
selfSay("You have cancelled the task " .. (tasks[cancel[cid]].name or tasks[cancel[cid]].raceName) .. ".")
talkState[talkUser] = 0
elseif isInArray({"points", "rank"}, msg:lower()) then
selfSay("At this time, you have " .. getPlayerStorageValue(cid, POINTSSTORAGE) .. " Paw & Fur points. You " .. (getPlayerRank(cid) == 5 and "are an Elite Hunter" or getPlayerRank(cid) == 4 and "are a Trophy Hunter" or getPlayerRank(cid) == 3 and "are a Big Game Hunter" or getPlayerRank(cid) == 2 and "are a Ranger" or getPlayerRank(cid) == 1 and "are a Huntsman" or "haven't been ranked yet") .. ".")
talkState[talkUser] = 0
end
end

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

Npc replies, but can't check tasks and tasks aren't being counted ( no errors in console).
 
Last edited:
Back
Top