• 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.1] Quest.lua doesnt work

Joined
Mar 24, 2013
Messages
59
Reaction score
9
Hello i got a quest script and first it gave me a chest not the item itself so i messd arround with it with the storage values the item uid. tryd to look some guides for scripting with tfs 1.1 (didnt found any :( ) etc. tryd everything my mind could think of and now all it says Its Empty! tryd with diffrent characters (new ones) and still says its empty! it doesnt give any errors it just says its empty! help. :/

Quest.lua
Code:
local chests =
{
    [9148] = {itemid = 2495, count = 1},

    [9149] = {itemid = 8905, count = 1},

    [9150] = {itemid = 16111, count = 1},

    [9151] = {itemid = 16112, count = 1}
}


function onUse(player, item, fromPosition, target, toPosition, isHotkey)

    if chests[item.uid] then

        if player:getStorageValue(40564) ~= 2 then

            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'It\'s empty.')
 
        return true

        end

 
    local chest = chests[item.uid]

        local itemType = ItemType(chest.itemid)
 
    if itemType then

            local article = itemType:getArticle()

            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have found ' .. (#article > 0 and article .. ' ' or '') .. itemType:getName() .. '.')

        end


        player:addItem(chest.itemid, chest.count)

        player:setStorageValue(40564, 2)

    end

 
return
true
end

actions.xml
Code:
    <action fromuid="9148" touid="9151" script="quests/Quest.lua" />
 
Code:
local chests = {
    [9148] = {itemid = 2495, count = 1},
    [9149] = {itemid = 8905, count = 1},
    [9150] = {itemid = 16111, count = 1},
    [9151] = {itemid = 16112, count = 1}
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local chest = chests[item.uid]
    if chest then
        if player:getStorageValue(40564) == 2 then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "It's empty.")
            return true
        end
       
        local itemType = ItemType(chest.itemid)
        if itemType then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have found " .. itemType:getArticle() .. " " .. itemType:getName() .. ".")
        end
       
        player:addItem(chest.itemid, chest.count)
        player:setStorageValue(40564, 2)
    end
    return true
end
 
3Rm5h71.jpg
Thanks! @WibbenZ just small question now it gives me 1 item and others empty how can i make it that 1 chests gives me 3 items at one chest and let the others empty so uniqueid 9148 give me 3 items for example 2495,2496 and 2494. and that the other chest with uid. 9149 is then empty

Ps: hows it going with the /attr script :3
 
Last edited:
3Rm5h71.jpg
Thanks! @WibbenZ just small question now it gives me 1 item and others empty how can i make it that 1 chests gives me 3 items at one chest and let the others empty so uniqueid 9148 give me 3 items for example 2495,2496 and 2494. and that the other chest with uid. 9149 is then empty

Ps: hows it going with the /attr script :3

So that you get 3 items from one chest when you click it or?
I tought you wanted it to be one item per one character per chest.

If you want the player to be able to take all of them change 40564 to item.uid.

Haven't had time to check that yet :p
 
yes i want it like this you have 3 chests so 1,2,3 (duhh. xD) when you click chest 1 you get item id 2494,2495,2496 and then you wont be able to get chest 2 and 3 but if you click chest 2 also containing 3 items you wont be able to get chest 1 and 3 etc. so like a set.

u know what i mean? :p ps: how is it going with the /attr script https://otland.net/threads/want-attr-for-tfs-1-x.232072/#post-2236625 ^_^
 
Last edited:
yes i want it like this you have 3 chests so 1,2,3 (duhh. xD) when you click chest 1 you get item id 2494,2495,2496 and then you wont be able to get chest 2 and 3 but if you click chest 2 also containing 3 items you wont be able to get chest 1 and 3 etc. so like a set.

u know what i mean? :p ps: how is it going with the /attr script https://otland.net/threads/want-attr-for-tfs-1-x.232072/#post-2236625 ^_^

So one of the chests you get 3 items? And if you take that chest you can't take the others?
In that case you can do it like this:
Code:
local chests = {
    [1000] = {
        items = {{2160, 100}, {1111, 2}}
    }
}

local chest = chests[item.uid]
if(chest) then
    local bag = player:addItem(1987, 1)
    for i = 1, #chest.items do
        local targetItem = chest.items[1]
        bag:addItem(targetItem[1], targetItem[2] or 1)
    end
end

About attr.
Haven't had time to check that yet :p
 
hmm im not sure i understand that script correctly if ihave 3 chests it would look somthing like this then? item id are not the ones i want in the script but only as an example ofc.
Code:
local chests = {
    [1000] = { items = {{2160, 100}, {1111, 2},
    [1001] = { items = {{2161, 100}, {1112, 2},
    [1002] = { items = {{2162, 100}, {1113, 2},
       }
    }
}

local chest = chests[item.uid]
if(chest) then
    local bag = player:addItem(1987, 1)
    for i = 1, #chest.items do
        local targetItem = chest.items[1]
        bag:addItem(targetItem[1], targetItem[2] or 1)
    end
end

and if i want more items like this?

Code:
local chests = {

    [1000] = { items = {{2160, 100}, {1111, 2},{2160, 100},

    [1001] = { items = {{2161, 100}, {1112, 2},

    [1002] = { items = {{2162, 100}, {1113, 2},{2946, 1},{2195, 1},

       }

    }

}




local chest = chests[item.uid]

if(chest) then

    local bag = player:addItem(1987, 1)

    for i = 1, #chest.items do

        local targetItem = chest.items[1]

        bag:addItem(targetItem[1], targetItem[2] or 1)

    end

end

and about the attr didnt understood ur first message was about the attr hope you will have some time soon to spare to make it :p but i appreciate everything u helpd me with so far ofc. :)
 
hmm im not sure i understand that script correctly if ihave 3 chests it would look somthing like this then? item id are not the ones i want in the script but only as an example ofc.
Code:
local chests = {
    [1000] = { items = {{2160, 100}, {1111, 2},
    [1001] = { items = {{2161, 100}, {1112, 2},
    [1002] = { items = {{2162, 100}, {1113, 2},
       }
    }
}

local chest = chests[item.uid]
if(chest) then
    local bag = player:addItem(1987, 1)
    for i = 1, #chest.items do
        local targetItem = chest.items[1]
        bag:addItem(targetItem[1], targetItem[2] or 1)
    end
end

and if i want more items like this?

Code:
local chests = {

    [1000] = { items = {{2160, 100}, {1111, 2},{2160, 100},

    [1001] = { items = {{2161, 100}, {1112, 2},

    [1002] = { items = {{2162, 100}, {1113, 2},{2946, 1},{2195, 1},

       }

    }

}




local chest = chests[item.uid]

if(chest) then

    local bag = player:addItem(1987, 1)

    for i = 1, #chest.items do

        local targetItem = chest.items[1]

        bag:addItem(targetItem[1], targetItem[2] or 1)

    end


end
[1002] = { items = {{2162, 100}, {1113, 2},{2946, 1},{2195, 1} } }
You miseed 2 } and you also don't need a ", " there.

On those above you also missed the } * 2 but leave the ", " there.

I can help you later, pretty busy atm.
 
xD i was about to edit that u beat me to it but it works so thank you and ill wait patiently no need to rush i and others can understand that you are very bussy. :)



final script Quest.lua which doesnt work i think i tryd almost every { and } at every line but still says
cDnmqFs.jpg


Code:
local chests = {
  [9148] = { items = {{2469, 1}, {2492, 1}, {2496, 1}},
  [9149] = { items = {{2494, 1}, {2495, 1}, {2496, 1}},
  [9150] = { items = {{7588, 1}, {7589, 1}}
  }
}

local chest = chests[item.uid]
if(chest) then
  local bag = player:addItem(1987, 1)
  for i = 1, #chest.items do
  local targetItem = chest.items[1]
  bag:addItem(targetItem[1], targetItem[2] targetItem[3] or 1)
  end
end

Also when i took your script completely without changing anything it said
xPpLZtX.jpg



i could also just make 3 chests next to eachother total 9 and take the script u first made at the top 3 times to get what i want tough. but it would be awesome if it were just 1 script
@WibbenZ
 
Last edited:
A tip is to use notepad++, then just click on the brackets and they will become red, if they stay grey that mens they have no ending.
Code:
local chests = {
    [9148] = { storage = 1000, items = { {2469, 1}, {2492, 1}, {2496, 1} } },
    [9149] = { storage = 1000, items = { {2494, 1}, {2495, 1}, {2496, 1} } },
    [9150] = { storage = 1000, items = { {7588, 1}, {7589, 1} } }
}

function onUse(player, item, fromPosition, target, toPosition)
    local chest = chests[item.uid]
    if(chest) then
        if(player:getStorageValue(chest.storage) == 1) then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "The chest is empty.")
            return true
        end
       
        local bag = player:addItem(1987, 1)
        for i = 1, #chest.items do
            local targetItem = chest.items[1]
            bag:addItem(targetItem[1], targetItem[2] targetItem[3] or 1)
        end
        player:setStorageValue(chest.storage, 1)
    end
    return true
end

Copy that, unless I miseed something it will work.
About the 9 chests, just add the items and the new arrays to the chests array.
Added storage to the chest array aswell, so if the storage is the same, the player can only take one of those with that storage value.
 
Thanks tough but ehm it gives me a bag but bag is empty xD

Really weard it gives me from the uniqueid [9150] 2 strong health potions id 7588 supposed to be 1 but when i test the uniqueid 9149 and 9148 it gives me an empty bag?
 
Last edited:
Code:
local chests = {
    [9148] = { storage = 1000, items = { {2469, 1}, {2492, 1}, {2496, 1} } },
    [9149] = { storage = 1000, items = { {2494, 1}, {2495, 1}, {2496, 1} } },
    [9150] = { storage = 1000, items = { {7588, 1}, {7589, 1} } }
}

function onUse(player, item, fromPosition, target, toPosition)
    local chest = chests[item.uid]
    if(chest) then
        if(player:getStorageValue(chest.storage) == 1) then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "The chest is empty.")
            return true
        end
       
        local bag = player:addItem(1987, 1)
        for i = 1, #chest.items do
            local targetItem = chest.items[i]
            bag:addItem(targetItem[1], targetItem[2] targetItem[3] or 1)
        end
        player:setStorageValue(chest.storage, 1)
    end
    return true
end

Wrote 1 insted of the letter i xD
 
haha lol xD FINALLY IT WORKS thanks so much @WibbenZ last piece i need to finally start making monsters etc. is (not sure if i may ask you it like this probably not so answer if i cant then i edit this post :/ ) but it is a TFS 1.1 version of this script maybe u could make me 1 if you have the time ofc. but i desperetly need it T_T but i dont feel like saying that since u helpd me already so much. that script is from some1 here on otland and i used it on my 8.6 server credits go to the maker of that not me at all.
Code:
local exhaust = createConditionObject(CONDITION_EXHAUST)
setConditionParam(exhaust, CONDITION_PARAM_TICKS, 0)
function onUse(cid, item, fromPosition, itemEx, toPosition)
    local healthAdd = {
    ["Sorcerer"]={math.random(1675, 1800), math.random(18000,20000), math.random(43500, 45000), math.random(88000, 90000), math.random(147000, 149000), math.random(221200, 223200), math.random(310000, 312000), math.random(310000, 312000)}, ["Druid"]={math.random(1675, 1800), math.random(18000,20000), math.random(43500, 45000), math.random(88000, 90000), math.random(147000, 149000), math.random(221200, 223200), math.random(310000, 312000), math.random(310000, 312000)}, ["Paladin"]={math.random(1675, 1800), math.random(18000,20000), math.random(43500, 45000), math.random(88000, 90000), math.random(147000, 149000), math.random(221200, 223200), math.random(310000, 312000), math.random(310000, 312000)}, ["Knight"]={math.random(1675, 1800), math.random(18000,20000), math.random(43500, 45000), math.random(88000, 90000), math.random(147000, 149000), math.random(221200, 223200), math.random(310000, 312000), math.random(310000, 312000)},
    ["Master Sorcerer"]={math.random(400, 450), math.random(400, 450), math.random(400, 450), math.random(400, 450), math.random(400, 450), math.random(400, 450), math.random(400, 450), math.random(400, 450)}, ["Elder Druid"]={math.random(400, 450), math.random(400, 450), math.random(400, 450), math.random(400, 450), math.random(400, 450), math.random(400, 450), math.random(400, 450), math.random(400, 450)}, ["Royal Paladin"]={math.random(1115, 1300), math.random(1315, 1500), math.random(2000, 2300), math.random(2000, 2300), math.random(2000, 2300), math.random(2000, 2300), math.random(2000, 2300), math.random(2000, 2300)}, ["Elite Knight"]={math.random(1675, 1800), math.random(1800,2200), math.random(2600, 3000), math.random(2600, 3000), math.random(2600, 3000), math.random(2600, 3000), math.random(2600, 3000), math.random(2600, 3000)}
    }
    if(isPlayer(itemEx.uid) == TRUE) then
        if(hasCondition(itemEx.uid, CONDITION_EXHAUST) == FALSE) then
            if(getPlayerLevel(itemEx.uid) < 500) then
              doCreatureAddHealth(itemEx.uid, healthAdd[getPlayerVocationName(itemEx.uid)][1])
            elseif(getPlayerLevel(itemEx.uid) >= 600) and (getPlayerLevel(itemEx.uid) < 700) then
              doCreatureAddHealth(itemEx.uid, healthAdd[getPlayerVocationName(itemEx.uid)][2])
            elseif(getPlayerLevel(itemEx.uid) >= 700) and (getPlayerLevel(itemEx.uid) < 800) then
              doCreatureAddHealth(itemEx.uid, healthAdd[getPlayerVocationName(itemEx.uid)][3])
            elseif(getPlayerLevel(itemEx.uid) >= 800) and (getPlayerLevel(itemEx.uid) < 900) then
              doCreatureAddHealth(itemEx.uid, healthAdd[getPlayerVocationName(itemEx.uid)][4])
            elseif(getPlayerLevel(itemEx.uid) >= 900) and (getPlayerLevel(itemEx.uid) < 1000) then
              doCreatureAddHealth(itemEx.uid, healthAdd[getPlayerVocationName(itemEx.uid)][5])
            elseif(getPlayerLevel(itemEx.uid) >= 1000) and (getPlayerLevel(itemEx.uid) < 1100) then
              doCreatureAddHealth(itemEx.uid, healthAdd[getPlayerVocationName(itemEx.uid)][6])
            elseif(getPlayerLevel(itemEx.uid) >= 1100) and (getPlayerLevel(itemEx.uid) < 1200) then
              doCreatureAddHealth(itemEx.uid, healthAdd[getPlayerVocationName(itemEx.uid)][7])
        else
              doCreatureAddHealth(itemEx.uid, healthAdd[getPlayerVocationName(itemEx.uid)][8])
            end
              doAddCondition(itemEx.uid, exhaust)
              doSendMagicEffect(getThingPos(itemEx.uid), CONST_ME_MAGIC_BLUE)
              doSendAnimatedText(getCreaturePosition(itemEx.uid), "yum.YUMY!", TEXTCOLOR_DARKYELLOW)
        else
          doPlayerSendDefaultCancel(cid, RETURNVALUE_YOUAREEXHAUSTED)
          return TRUE
        end
    else
      return FALSE
    end
end
 
Last edited:
Back
Top