• 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+ Quests system quest.lua

Lbtg

Intermediate OT User
Joined
Nov 22, 2008
Messages
2,306
Reaction score
129
Please help with quests system, script so i can put quests in maps, example

Action ID - 2000 for quests containers to add in map editor
UNIQ ID - Storage ID

And inside of choosen container box, chest, died body antyhing, whats put inside player gets as reward and gets storage so its lifetime reward

Code i trying to work with


Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if not storage then
        storage = item.uid
        if storage > 65535 then
            return false
        end
    end

    if player:getStorageValue(storage) > 0 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'The ' .. ItemType(item.itemid):getName() .. ' is empty.')
        return true
    end

    local items, reward = {}
    local size = item:isContainer() and item:getSize() or 0
    if size == 0 then
        reward = item:clone()
    else
        local container = Container(item.uid)
        for i = 0, container:getSize() - 1 do
            items[#items + 1] = container:getItem(i):clone()
        end
    end

    size = #items
    if size == 1 then
        reward = items[1]:clone()
    end

    local result = ''
    if reward then
        local ret = ItemType(reward.itemid)
        if ret:isRune() then
            result = ret:getArticle() .. ' ' ..  ret:getName() .. ' (' .. reward.type .. ' charges)'
        elseif ret:isStackable() and reward:getCount() > 1 then
            result = reward:getCount() .. ' ' .. ret:getPluralName()
        elseif ret:getArticle() ~= '' then
            result = ret:getArticle() .. ' ' .. ret:getName()
        else
            result = ret:getName()
        end
    else
        if size > 20 then
            reward = Game.createItem(item.itemid, 1)
        elseif size > 8 then
            reward = Game.createItem(1988, 1)
        else
            reward = Game.createItem(1987, 1)
        end

        for i = 1, size do
            local tmp = items[i]
            if reward:addItemEx(tmp) ~= RETURNVALUE_NOERROR then
                print('[Warning] QuestSystem:', 'Could not add quest reward to container')
            end
        end
        local ret = ItemType(reward.itemid)
        result = ret:getArticle() .. ' ' .. ret:getName()
    end

    if player:addItemEx(reward) ~= RETURNVALUE_NOERROR then
        local weight = reward:getWeight()
        if player:getFreeCapacity() < weight then
            player:sendCancelMessage(string.format('You have found %s weighing %.2f oz. You have no capacity.', result, (weight / 100)))
        else
            player:sendCancelMessage('You have found ' .. result .. ', but you have no room to take it.')
        end
        return true
    end

    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have found ' .. result .. '.')
    player:setStorageValue(storage, 1)
    return true
end

Now its like 1 first quest i click working, and all other i start click it says ' the chest is empty', tho on map editor UNIQ ids of containers is different.

Thanks in advance
 
Solution
This part is weird.
Lua:
    if not storage then
        storage = item.uid
        if storage > 65535 then
            return false
        end
    end
try changing to this
Lua:
local storage = item:getUniqueId()
if storage < 2000 or storage > 65535 then
    print("Quest Chest Error: UniqueId out of range. (" .. storage .. ")")
    return false
end
This part is weird.
Lua:
    if not storage then
        storage = item.uid
        if storage > 65535 then
            return false
        end
    end
try changing to this
Lua:
local storage = item:getUniqueId()
if storage < 2000 or storage > 65535 then
    print("Quest Chest Error: UniqueId out of range. (" .. storage .. ")")
    return false
end
 
Solution
This part is weird.
Lua:
    if not storage then
        storage = item.uid
        if storage > 65535 then
            return false
        end
    end
try changing to this
Lua:
local storage = item:getUniqueId()
if storage < 2000 or storage > 65535 then
    print("Quest Chest Error: UniqueId out of range. (" .. storage .. ")")
    return false
end


Lua:
Quest Chest Error: UniqueId out of range. (65537)
Quest Chest Error: UniqueId out of range. (65538)
Quest Chest Error: UniqueId out of range. (65539)
Quest Chest Error: UniqueId out of range. (1256)

my current chests:

actionid 2000
uniqID 1251

actionid 2000
uniqID 1252

actionid 2000
uniqID 1253

actionid 2000
uniqID 1254

actionid 2000
uniqID 1255
 
Lua:
Quest Chest Error: UniqueId out of range. (65537)
Quest Chest Error: UniqueId out of range. (65538)
Quest Chest Error: UniqueId out of range. (65539)
Quest Chest Error: UniqueId out of range. (1256)

my current chests:

actionid 2000
uniqID 1251

actionid 2000
uniqID 1252

actionid 2000
uniqID 1253

actionid 2000
uniqID 1254

actionid 2000
uniqID 1255

If you want to test your luck and use uniqueid's below 2000, just remove that part of the if statement

Otherwise, change all your chests to use unique's from 2000+
 
If you want to test your luck and use uniqueid's below 2000, just remove that part of the if statement

Otherwise, change all your chests to use unique's from 2000+
Aswell my line about quest.lua on actions.xml


Lua:
    <!-- Quests -->
    <action actionid="2000" script="quests/quests.lua" />


oke will try soon
Post automatically merged:

If you want to test your luck and use uniqueid's below 2000, just remove that part of the if statement

Otherwise, change all your chests to use unique's from 2000+
Works perfecly <3 Thanks alot
 
Last edited:
Back
Top