• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

[8.6] Task

Blade33711

Member
Joined
Aug 6, 2012
Messages
133
Solutions
1
Reaction score
5
Location
Poland
I have this script:
config:
Code:
<config name="talkactionTask_conf"><![CDATA[
canGetOnlyOneTime = false

task = {
    ['rotworm'] = {storage = X, beginStorageValue = X, finishStorageValue = X, count = X,
                        requiedLevelToReward = X,
                        rewards = {'exp', X, 'cash', X, 'item', {X, n}}}
    }

mainStorage = X

function isSummon(cid)
        if(not isCreature(cid)) then
                return false
        end
        return getCreatureMaster(cid) ~= cid
end

function checkInfoAboutTask(tableTask)
local message = ''
for i = 1, #tableTask/2 do
        local rewardType, rewardCount = tableTask[i*2-1], tableTask[i*2]
        if rewardType == 'item' and type(rewardCount) == 'table' then
                for item = 1, #rewardCount/2 do
                        local rewardItemId, rewardItemCount = rewardCount[item*2-1], rewardCount[item*2]
                        message = message .. ('* ' .. rewardItemCount .. 'x ' .. getItemNameById(rewardItemId)) .. '\n'
                end
        else
                message = message .. ((rewardType == 'item' and '* ' .. getItemNameById(rewardCount)) or
                                                        (rewardType == 'exp' and '* ' .. rewardCount .. ' Experience ') or
                                                        (rewardType == 'cash' and '* ' .. rewardCount .. ' Money ') or
                                                        (rewardType == 'smsPoints' and '* ' .. rewardCount .. ' Sms points ')) .. '\n'
        end
end
return message
end

function doAddExp(cid, amount)
        return doSendAnimatedText(getThingPos(cid), amount, COLOR_WHITE) and doPlayerAddExperience(cid, amount) or false
end
]]></config>
Code:
<talkaction words="!task" event="script"><![CDATA[
domodlib('talkactionTask_conf')
function onSay(cid, words, param, channel)

local taskMenu, message = task[param:lower()], ''
if taskMenu and (taskMenu.potionTask and getCreatureStorage(cid, taskMenu.storage) == -1 or getCreatureStorage(cid, mainStorage) < 1) then
        if(getCreatureStorage(cid, taskMenu.storage) > 0) or taskMenu.potionTask and getCreatureStorage(cid, taskMenu.storage) > taskMenu.count then
                return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'Already you have made this task!')
        end
        if taskMenu.potionTask and getCreatureStorage(cid, taskMenu.storage) > -1 then
                return true
        else
                doCreatureSetStorage(cid, mainStorage, taskMenu.beginStorageValue)
        end
        doCreatureSetStorage(cid, taskMenu.storage, 0)
        return doPlayerPopupFYI(cid, 'The decision taken, your task is to '..(taskMenu.potionTask and 'use' or 'kill')..' - ' .. taskMenu.count.. ' ' ..param:lower().. (taskMenu.count > 1 and 's' or '') .. '\nRewards which you receive for finishing this task:\n' .. checkInfoAboutTask(taskMenu.rewards) .. (taskMenu.potionTask and '' or 'If you want to abort the current job enough that you use the command "!task cancel".\n')..'If you want to know about the current job simply use the command "!task info"\nIf you wish to receive a prize for the job simply use the command !task reward')
elseif isInArray({'cancel', 'delete', 'abort'}, param:lower()) and getCreatureStorage(cid, mainStorage) > 0 then
        for _, v in pairs(task) do
                if not v.potionTask and getCreatureStorage(cid, v.storage) >= 0 then
                        doCreatureSetStorage(cid, mainStorage, -1)
                        doCreatureSetStorage(cid, v.storage, -1)
                        return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'You canceled the current task.')
                end
        end
elseif isInArray({'reward', 'end', 'finish'}, param:lower()) then
        local rewards, showMessage = 'Items that you got as a reward is: ', false
        for _, v in pairs(task) do
                if (v.potionTask and getCreatureStorage(cid, v.storage) == v.count or getCreatureStorage(cid, mainStorage) == v.finishStorageValue) then
                        showMessage = true
                        if not v.potionTask then
                                doCreatureSetStorage(cid, mainStorage, -1)
                        else
                                doCreatureSetStorage(cid, v.storage, v.count + 1)
                        end
                        if not v.requiedLevelToReward or v.requiedLevelToReward >= getPlayerLevel(cid) then
                                for i = 1, #v.rewards/2 do
                                        local rewardType, rewardCount = v.rewards[i*2-1], v.rewards[i*2]
                                        if rewardType == 'item' and type(rewardCount) == 'table' and #rewardCount > 1 then
                                                for item = 1, #rewardCount / 2 do
                                                        local rewardItemId, rewardItemCount = rewardCount[item*2-1], rewardCount[item*2]
                                                        rewards = rewards .. rewardItemCount .. 'x ' .. getItemNameById(rewardItemId) .. ', '
                                                        doPlayerAddItem(cid, rewardItemId, rewardItemCount, true)
                                                end
                                        else
                                                rewards = rewards .. rewardCount .. 'x ' .. (rewardType == 'item' and getItemNameById(rewardCount) or rewardType == 'exp' and 'experience' or rewardType == 'cash' and 'money' or rewardType == 'smsPoints' and 'sms points') .. ', '
                                                if rewardType == 'item' then
                                                        doPlayerAddItem(cid, rewardCount, 1, true)
                                                elseif rewardType == 'exp' then
                                                        doAddExp(cid, rewardCount)
                                                elseif rewardType == 'cash' then
                                                        doPlayerAddMoney(cid, rewardCount)
                                                elseif rewardType == 'smsPoints' then
                                                        db.executeQuery("UPDATE `accounts` SET `premium_points` = `premium_points` + " .. rewardCount .. " WHERE `name` = '" .. getAccountByName(getCreatureName(cid)) .. "' LIMIT 1;")
                                                end
                                        end
                                end
                        else
                                rewards = 'Your experience level is too high to be able to receive the reward.'
                        end
                end
        end
        return showMessage and doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, string.sub(rewards, 1, string.len(rewards) - 1)..'.')
else
        for k, v in pairs(task) do
                if isInArray((v.potionTask and {'potion','potions'} or {'info', 'information', 'details'}), param:lower()) and (v.potionTask and getCreatureStorage(cid, v.storage) >= 0 or getCreatureStorage(cid, mainStorage) > 0) then
                        if (v.potionTask and getCreatureStorage(cid, v.storage) <= v.count or isInArray({v.finishStorageValue, v.beginStorageValue}, getCreatureStorage(cid, mainStorage))) then
                                return doPlayerPopupFYI(cid, 'Your current task is to '..(v.potionTask and 'use' or 'kill')..' - ' .. v.count.. ' ' ..k:lower().. (v.count > 1 and 's' or '') .. '\nYou have killed ' .. getCreatureStorage(cid, v.storage) .. ' of ' .. v.count .. ' ' .. k:lower() .. (v.count == 1 and '' or 's') .. '. You must kill ' .. v.count - getCreatureStorage(cid, v.storage) .. ' ' .. k:lower() .. (v.count == 1 and '' or 's') .. ' yet\nRewards which you receive for finishing this task:\n' .. checkInfoAboutTask(v.rewards))
                        end
                end
        end
end
return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'Wrong command!')
end
]]></talkaction>

I need help to when you type !task reward sees the message:
1. when I don't finish my task: You have not completed the task. - Now I do not get any messages.

When type !task monster
1. if I choose the same task: You have begun this task. - Now I got the message: Wrong command
 
Last edited:
Back
Top