• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

Quest System - without changing map

averatec

Advanced OT User
Joined
Jun 1, 2007
Messages
2,243
Solutions
4
Reaction score
159
Location
Poland
data/libs, create new file 130-newquestsystem.lua and put this code into it:
Code:
function addItems(thing, items)
    local result = ""
    for i,v in ipairs(items) do
        if (type(v) == "table") then
            local tmp = nil
           
            if (v.container ~= nil) then
                tmp = getThing(doCreateItemEx(v.container, 1))
                result = result .. addItems(tmp, v.items)
            else
                tmp = getThing(doCreateItemEx(v.id, v.count))
            end
           
            if (v.actionid ~= nil) then
                doSetItemActionId(tmp.uid, v.actionid)
            end       
           
            if (v.description ~= nil) then
                doSetItemSpecialDescription(tmp.uid, v.description)
            end       
           
            if(doAddContainerItemEx(thing.uid, tmp.uid) ~= RETURNVALUE_NOERROR) then
                print("[Warning] AddItems:", "Something went wrong!")
            end
   
            if (v.container == nil) then
                local ret = ", "
                result = result .. ret
                ret = getItemDescriptions(tmp.uid)
                if(tmp.type > 0 and isItemRune(tmp.itemid)) then
                    result = result .. tmp.type .. " charges " .. ret.name
                elseif(tmp.type > 0 and isItemStackable(tmp.itemid)) then
                    result = result .. tmp.type .. " " .. ret.plural
                else
                    result = result .. ret.article .. " " .. ret.name
                end
            end
        else
            print("[Warning] AddItems:", "Grr! I expected table!")
        end
    end
    return result
end

function doPlayerAddQuest(cid, items, storage, container)
    if(not storage) then
        return false
    end

    if(getCreatureStorage(cid, storage) > 0) then
        doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "empty message")
        return false
    end

    if (type(items) ~= "table") then
        return false
    end
   
    local reward = nil
    local result = ""
    if (#items == 1) then
        reward = getThing(doCreateItemEx(items[1].id, items[1].count))
    else
        if (not container) then
            if (#items > 8) then
                container = 1988 -- default container bp
            else
                container = 1987 -- default container bag
            end
        end
        reward = getThing(doCreateItemEx(container, 1))
        result = addItems(reward, items)
    end
   
    local ret = getItemDescriptions(reward.uid)
    local tmp = result
    result = "You have found " .. ret.article .. " " .. ret.name
    if (tmp ~= "") then
        result = result .. tmp
    end

     if(doPlayerAddItemEx(cid, reward.uid, false) == RETURNVALUE_NOERROR)then
        doCreatureSetStorage(cid, storage, 1)
        result = result .. "."
    else
        result = (getPlayerFreeCap(cid) < getItemWeight(reward.uid)) and result .. ". Weighing " .. getItemWeight(reward.uid) .. " oz it is too heavy." or result .. ", but you have no room to take it."
    end   
    doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, result)
    return true
end

How to use?
Create any action, creatureevent or whatever you want to give rewards.

Sample code:
Code:
local reward = {
    { id = 2400, count = 1, actionid = 1234, description = "holy sword" },
    { id = 2160, count = 10 },
    { container = 1988, items = {
            { id = 2400, count = 1, actionid = 1234, description = "holy sword" },
            { id = 2160, count = 10 },
            { container = 1988, items = {
                    { id = 2400, count = 1, actionid = 1234, description = "holy sword" },
                    { id = 2160, count = 10 }
                }
            }
        }
    }
}
local storage = 1234
local container = 1988 -- main container

function onUse(cid, item, fromPosition, itemEx, toPosition)
    doPlayerAddQuest(cid, reward, storage, container)
end
 
Last edited:
You should use some classes, it is really easier to handle then, than creating such arrays. XD
 
Back
Top