• 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 0.X Remove items of list from position

Mr.Caffeine

Active Member
Joined
Nov 4, 2018
Messages
79
Reaction score
43
Hello, I need this npc script to be able to check and remove items from position.
I can make it work with a single item, but if I add more items to the array it doesn't work. what I want is the npc recognize multiple item ids that can be removed if the item is on the tile. The tile only accepts one item at a time, there is no problem with conflicts and it is not necessary to create an event for this. I just want the npc to recognize more than one item id that can be removed.

Code:
local config = {
    items = {2388,2390,2424,2438,2450,7379,7424,7438,7450,7454,8856,8858,8926,12609,12610,12796,12797,12798,12805,12812,12818}
}

local thing = getTileItemById(pos, config.items).uid

if thing > 0 then
    
    doRemoveItem(thing,1)
    selfSay('worked!', cid)
    else
    selfSay('not worked!', cid)
    
end
 
Solution
with a loop:
example:
Lua:
local config = {
    items = {2388,2390,2424,2438,2450,7379,7424,7438,7450,7454,8856,8858,8926,12609,12610,12796,12797,12798,12805,12812,12818}
}
for _, itemId in pairs(config.items) do
    local thing = getTileItemById(pos, itemId).uid
    if thing > 0 then
        doRemoveItem(thing, 1)
        selfSay('worked!', cid)
    else
        selfSay('not worked!', cid)
    end
end
with a loop:
example:
Lua:
local config = {
    items = {2388,2390,2424,2438,2450,7379,7424,7438,7450,7454,8856,8858,8926,12609,12610,12796,12797,12798,12805,12812,12818}
}
for _, itemId in pairs(config.items) do
    local thing = getTileItemById(pos, itemId).uid
    if thing > 0 then
        doRemoveItem(thing, 1)
        selfSay('worked!', cid)
    else
        selfSay('not worked!', cid)
    end
end
 
Solution
with a loop:
example:
Lua:
local config = {
    items = {2388,2390,2424,2438,2450,7379,7424,7438,7450,7454,8856,8858,8926,12609,12610,12796,12797,12798,12805,12812,12818}
}
for _, itemId in pairs(config.items) do
    local thing = getTileItemById(pos, itemId).uid
    if thing > 0 then
        doRemoveItem(thing, 1)
        selfSay('worked!', cid)
    else
        selfSay('not worked!', cid)
    end
end

Thanks :D
 
Back
Top