• 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 TFS 1.2 Task system issues

SixNine

Active Member
Joined
Dec 12, 2018
Messages
369
Reaction score
32
The issues im talking about

  1. Doesnt give rewards (no errors)
  2. Once you take task it says You must kill: (51) rats('s). when it should say You must kill: (50) rats('s). (so basically it adds one more for some reason)
  3. Issue with creature count it says
22:57 (2) Rats LvL 1 left.
22:57 (1) Rats LvL 1 left.
22:57 (0) Rats LvL 1 left.
22:57 You have finished the Undeads task.

when it should be

22:57 (2) Rrats LvL 1 left.
22:57 (1) Rats LvL 1 left.
22:57 You have finished the Undeads task.

Code
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

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 tasks = {
    [1] = {id = 1, levelReq = 1, msg = "{Rats} have been terrorizing the undergrounds of west. I need you to {kill 50 of them}.",
        name = {"Rats", "rats", "1"},
        monsters = {
            [1] = {name = "rats", amount = 50, storage = 6601}
        },
        exp = 10000,
        itemRewards = {{2160, 25}, {2152, 1}}
        },
    [2] = {id = 2, levelReq = 5, msg = "Some Message.",
        name = {"orcs", "Orcs", "2"},
        monsters = {
            [1] = {name = "Orc", amount = 50, storage = 6602}
        },
        exp = 50000,
        itemRewards = {{2152, 5}}
        }
}

local taskStorage = 6500

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

    local player = Player(cid)
    if not player then return true end
    
    if msg and msg == "tasks" or msg == "mission" then
        local text = "Tasks: "
        for i = 1, #tasks do
            if i == #tasks then
                text = text..""..tasks[i].name[1].."."
            else
                text = text..""..tasks[i].name[1]..", "
            end
        end
        
        selfSay(text, cid)
        return true
        
    elseif msg and msg ~= "cancel" then
        local TASK = nil
        
        for i = 1, #tasks do
            if isInArray(tasks[i].name, msg) then
                TASK = tasks[i]
                break
            end
        end
        
        if not TASK then return true end
        
        local playerTask = tasks[player:getStorageValue(taskStorage)]
        
        if player:getStorageValue(taskStorage) == nil or player:getStorageValue(taskStorage) == -1 then
            player:setStorageValue(taskStorage, TASK.id)
            selfSay(TASK.msg, cid)
            return true
        end
            
        if player:getStorageValue(taskStorage) ~= playerTask.id then
            selfSay("You must complete the "..playerTask.name[1].." task first. You can also {clear task}.", cid)
            return true
    
        else
            local isComplete = true
        
            for i = 1, #TASK.monsters do
                if player:getStorageValue(TASK.monsters[i].storage) ~= TASK.monsters[i].amount then
                    isComplete = false
                    break
                end
            end
        
            if not isComplete then
              local text = "First you have to finish your current task: "
                    for i = 1, #playerTask.monsters do
                        if i == #playerTask.monsters then
                            text = text.."("..playerTask.monsters[i].amount - player:getStorageValue(playerTask.monsters[i].storage)..") "..playerTask.monsters[i].name.."('s)."
                        else
                            text = text.."("..playerTask.monsters[i].amount - player:getStorageValue(playerTask.monsters[i].storage)..") "..playerTask.monsters[i].name.."('s), "
                        end
                    end
                        
                selfSay(text, cid)
                return true
                
            else
            
                player:setStorageValue(taskStorage, -1)
                for i = 1, #TASK.monsters do
                    player:setStorageValue(TASK.monsters[i].storage, -1)
                end
                if TASK.exp then
                    player:addExperience(TASK.exp)
                end
                
                if TASK.itemRewards then
                    player:addItem(TASK.itemRewards[1], TASK.itemRewards[2])
                end
                
                selfSay("You have completed the "..TASK.name[1].." task!", cid)
                return true
            end
        end
        
    elseif msg == "cancel" then
        local TASK = tasks[player:getStorageValue(taskStorage)]
        
        if not TASK then
            selfSay("You do not have a task.", cid)
        else
            player:setStorageValue(taskStorage, -1)
            for i = 1, #TASK.monsters do
                player:setStorageValue(TASK.monsters[i].storage, -1)
            end
            selfSay("You are no longer doing the "..TASK.name[1].." task.", cid)
            return true
        end
    end
    return true
end

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

Lua:
local tasks = {
    [1] = {taskName = "Undeads",
        monsters = {
            [1] = {name = {"Rat LvL 1", "Rat LvL 2", "Rat  LvL 3"}, amount = 50, storage = 6601}
        }
    }
}

local taskStorage = 6500

-- Don't touch --
for i = 1, #tasks do
    for x = 1, #tasks[i].monsters do
        for z = 1, #tasks[i].monsters[x].name do
            tasks[i].monsters[x].name[z] = tasks[i].monsters[x].name[z]:lower()
        end
    end
end
----------------

function onKill(creature, target)
    if not creature:isPlayer() then return true end
    
    if not target:isMonster() or target:getMaster() then return true end
    
    local player = Player(creature)
    
    if player:getStorageValue(taskStorage) ~= nil and player:getStorageValue(taskStorage) ~= -1 then
        local TASK = tasks[player:getStorageValue(taskStorage)]
            
        if not TASK then return true end
        
        local MONSTERTABLE = nil
        
        for i = 1, #TASK.monsters do
            if isInArray(TASK.monsters[i].name, target:getName():lower()) then
                MONSTERTABLE = TASK.monsters[i]
                break
            end
        end
        
        if not MONSTERTABLE then return true end

            if player:getStorageValue(MONSTERTABLE.storage) < MONSTERTABLE.amount then
                player:setStorageValue(MONSTERTABLE.storage, player:getStorageValue(MONSTERTABLE.storage) + 1)
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "("..MONSTERTABLE.amount - player:getStorageValue(MONSTERTABLE.storage)..") "..target:getName().." left.")
            else
                local isComplete = true
                for i = 1, #TASK.monsters do
                    if player:getStorageValue(TASK.monsters[i].storage) ~= TASK.monsters[i].amount then
                        isComplete = false
                        break
                    end
                end
                
                if isComplete then
                    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You have finished the "..TASK.taskName.." task.")
                else
                    local text = "[Task]: "
                    
                    for i = 1, #TASK.monsters do
                        if player:getStorageValue(TASK.monsters[i].storage) ~= TASK.monsters[i].amount then
                            if i == #TASK.monsters then
                                text = text.."("..TASK.monsters[i].amount - player:getStorageValue(TASK.monsters[i].storage)..") "..TASK.monsters[i].name[1].."."
                            else
                                text = text.."("..TASK.monsters[i].amount - player:getStorageValue(TASK.monsters[i].storage)..") "..TASK.monsters[i].name[1]..", "
                            end
                        end
                    end
                
                    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, text)
                end
            end
    end
return true
end
 
Solution
I don't understand where the problem is. Can you be more specific what the npc is doing wrong
Post automatically merged:

Nvm, I found it

Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

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 tasks = {
    [1] = {id = 1, levelReq = 1, msg = "{Rats} have been terrorizing the undergrounds of west. I...
OP
OP
SixNine

SixNine

Active Member
Joined
Dec 12, 2018
Messages
369
Reaction score
32
Sorry I couldn't help with rewards. There was no reason for it not to work from the code. It must be something related to your server only.
Yea probably but its weird because in different systems using exact same method pretty much
Can you show the function pls?
Yea i can. I think its this one but there is a lot of parts of it, not even sure because its not me who created this feature
Lua:
   if rewards.addItem and next(rewards.addItem) then
        local receivedItem, itemsWorth = 0, 0
        local itemsText = ""

        if not newContainer then
            newContainer = doCreateItemEx(1987, 1)
        end

        for k, item in ipairs(rewards.addItem) do
            local itemChance = item.chance
            if not itemChance or itemChance <= 0 then
                itemChance = 100
            end

            local randomChance = math.random(1, 100)
            if itemChance >= randomChance then
                itemsText = itemsText .. (item.count > 1 and (item.count .. 'x ') or '') .. ItemType(item.id):getName()
                if k ~= #rewards.addItem then
                    itemsText = itemsText .. ', '
                end             

                doAddContainerItem(newContainer, item.id, item.count)  
            end  
        end/code]
 
Top