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

TFS 1.0 Questsystem

bybbzan

mapper
Joined
Aug 4, 2012
Messages
809
Solutions
2
Reaction score
136
Location
Sweden
Hi guys. I got a question about the questsystem in 1.0
If i do ActionID 2000 and Unique 5000 on a chestbox. I will get an item with id 5000.
How to fix so i get the items i put in the black boxes and not the Unique id item?

quests.lua
Code:
local annihilatorReward = {1990, 2400, 2431, 2494}
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if item.uid > 1000 and item.uid <= 22670 then
        local itemWeight = getItemWeight(item.uid, 1, FALSE)
        local playerCap = getPlayerFreeCap(cid)
        if isInArray(annihilatorReward, item.uid) == TRUE then
            if getPlayerStorageValue(cid, 30015) == -1 then
                if playerCap >= itemWeight then
                    if item.uid == 1990 then
                        local container = doPlayerAddItem(cid, 1990, 1)
                        doAddContainerItem(container, 2326, 1)
                    else
                        doPlayerAddItem(cid, item.uid, 1)
                    end
                    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You have found a ' .. getItemName(item.uid) .. '.')
                    setPlayerStorageValue(cid, 30015, 1)
                else
                    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You have found a ' .. getItemName(item.uid) .. ' weighing ' .. itemWeight .. ' oz it\'s too heavy.')
                end
            else
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "It is empty.")
            end
        elseif getPlayerStorageValue(cid, item.uid) == -1 then
            if playerCap >= itemWeight then
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You have found a ' .. getItemName(item.uid) .. '.')
                doPlayerAddItem(cid, item.uid, 1)
                setPlayerStorageValue(cid, item.uid, 1)
            else
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You have found a ' .. getItemName(item.uid) .. ' weighing ' .. itemWeight .. ' oz it\'s too heavy.')
            end
        else
            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "It is empty.")
        end
    else
        return FALSE
    end
    return TRUE
end
 
Use this
actions.xml
Code:
<action actionid="2000" script="quests/system.lua"/>

system.lua
Code:
local specialQuests = {
   [2001] = 30015 --Annihilator
}

local questsExperience = {
   [30015] = 10000
}

function onUse(cid, item, fromPosition, itemEx, toPosition)

   local storage = specialQuests[item.actionid]
   if(not storage) then
     storage = item.uid
     if(storage > 65535) then
       return false
     end
   end

   if(getPlayerStorageValue(cid, storage) > 0) then
     doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "It is empty.")
     return true
   end

   local items = {}
   local reward = 0

   local size = isContainer(item.uid) and getContainerSize(item.uid) or 0
   if(size == 0) then
     reward = doCopyItem(item, false)
   else
     for i = 0, size do
       local tmp = getContainerItem(item.uid, i)
       if(tmp.itemid > 0) then
         table.insert(items, tmp)
       end
     end
   end

   size = table.maxn(items)
   if(size == 1) then
     reward = doCopyItem(items[1], true)
   end

   local result = ""
   if(reward ~= 0) then
     local ret = getItemDescriptions(reward.itemid)
     if(reward.type > 0 and isItemRune(reward.itemid)) then
       result = reward.type .. " charges " .. ret.name
     elseif(reward.type > 0 and isItemStackable(reward.itemid)) then
       result = reward.type .. " " .. ret.plural
     else
       result = ret.article .. " " .. ret.name
     end
   else
     if(size > 20) then
       reward = doCopyItem(item, false)
     elseif(size > 8) then
       reward = getThing(doCreateItemEx(1988, 1))
     else
       reward = getThing(doCreateItemEx(1987, 1))
     end

     for i = 1, size do
       local tmp = doCopyItem(items[i], true)
       if(doAddContainerItemEx(reward.uid, tmp.uid) ~= RETURNVALUE_NOERROR) then
         print("[Warning] QuestSystem:", "Could not add quest reward")
       else
         local ret = ", "
         if(i == 1) then
           ret = ""
         elseif(i == size) then
           ret = " and "
         end

         result = result .. ret
         ret = getItemDescriptions(tmp.itemid)
         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
     end
   end

   if(doPlayerAddItemEx(cid, reward.uid, false) ~= RETURNVALUE_NOERROR) then
     result = "You have found a reward weighing " .. getItemWeightByUID(reward.uid) .. " oz. It is too heavy or you have not enough space."
   else
     result = "You have found " .. result .. "."
     setPlayerStorageValue(cid, storage, 1)
     if(questsExperience[storage] ~= nil) then
       doPlayerAddExp(cid, questsExperience[storage])
     end
   end

   doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, result)
   return true
end

You can choose any uniqueid here.
You have to delete the actions.xml lines for the quest.lua if you use those chests with the system.lua.
 
You can choose any uniqueid here.

Code:
Lua Script Error: [Action Interface]
data/actions/scripts/other/system.lua:onUse
data/actions/scripts/other/system.lua:47: attempt to compare number with nil
stack traceback:
   [C]: in function '__lt'
   data/actions/scripts/other/system.lua:47: in function <data/actions/scripts/other/system.lua:9>
 
Didn't work.
Code:
Lua Script Error: [Action Interface]
data/actions/scripts/quests/quests.lua:onUse
data/actions/scripts/quests/quests.lua:41: attempt to call global 'doCopyItem' (
a nil value)
stack traceback:
        [C]: in function 'doCopyItem'
        data/actions/scripts/quests/quests.lua:41: in function <data/actions/scr
ipts/quests/quests.lua:9>
 
Back
Top