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

Lua Please Convert to tfs 1.2

silveralol

Advanced OT User
Joined
Mar 16, 2010
Messages
1,484
Solutions
9
Reaction score
217
Hi, I see it in another forum and like it
the script can be configurable to drop any item inside of backpack bag in a monster...
its nice!!!
but I don't know the version of tfs that he was maked... So, please somebody convert this script to tfs 1.2
Code:
local bag = xxx                        -- ID  backpack
local itens ={xxx, xxx, xxx}          -- ID of itens that will be droped and put into a backpack
 dropados.functionLoot(mName, mPosition)
    local items ={}
    for i = getTileInfo(mPosition).items,1,-1 do
        mPosition.stackpos = i
        table.insert(items, getThingFromPos(mPosition))
    end
    if#items == 0 then
        return true
    end
    local corpse =-1
    for _, item in ipairs(items) do
        local name = getItemName(item.uid):lower()
        if name:find(mName:lower())then
            corpse = item.uid
            break
        end
    end
    if not isContainer(corpse) then
        return true
    end
    if corpse ==-1then
        return true
    end
    for i =0, getContainerSize(corpse)-1 do
        local item = getContainerItem(corpse, i)
        if isInArray(itens, item.itemid)then
            doAddContainerItem(doAddContainerItem(corpse, bag,1), item.itemid, item.type)
            doRemoveItem(item.uid)
        end
    endendfunction onKill(cid, target)
    if isMonster(target)then
        addEvent(Loot,5, getCreatureName(target), getThingPos(target))
    end
    return true 
end
function onLogin(cid)
    registerCreatureEvent(cid,"lootItem")
    return true
end
 
ok, Will try and back here.
here the error:
Code:
Lua Script Error: [CreatureScript Interface] 
data/creaturescripts/scripts/others/bag.lua:onKill
data/lib/compat/compat.lua:830: attempt to compare number with userdata
stack traceback:
    [C]: in function '__le'
    data/lib/compat/compat.lua:830: in function 'getThingPos'
    data/creaturescripts/scripts/others/bag.lua:36: in function <data/creaturescripts/scripts/others/bag.lua:34>

Lua Script Error: [CreatureScript Interface] 
data/creaturescripts/scripts/others/bag.lua:onKill
data/lib/compat/compat.lua:830: attempt to compare number with userdata
stack traceback:
    [C]: in function '__le'
    data/lib/compat/compat.lua:830: in function 'getThingPos'
    data/creaturescripts/scripts/others/bag.lua:36: in function <data/creaturescripts/scripts/others/bag.lua:34>
well, need to convert the sintax
 
Last edited:
Code:
local bag = xxx                        -- ID  backpack
local itens ={xxx, xxx, xxx}          -- ID of itens that will be droped and put into a backpack
 dropados.functionLoot(mName, mPosition)
    local items ={}
    for i = getTileInfo(mPosition).items,1,-1 do
        mPosition.stackpos = i
        table.insert(items, getThingFromPos(mPosition))
    end
    if#items == 0 then
        return true
    end
    local corpse =-1
    for _, item in ipairs(items) do
        local name = getItemName(item.uid):lower()
        if name:find(mName:lower())then
            corpse = item.uid
            break
        end
    end
    if not isContainer(corpse) then
        return true
    end
    if corpse ==-1then
        return true
    end
    for i =0, getContainerSize(corpse)-1 do
        local item = getContainerItem(corpse, i)
        if isInArray(itens, item.itemid)then
            doAddContainerItem(doAddContainerItem(corpse, bag,1), item.itemid, item.type)
            doRemoveItem(item.uid)
        end
    endendfunction onKill(cid, target)
    if isMonster(target)then
        addEvent(Loot,5, getCreatureName(target), getThingPos(target))
    end
    return true 
end
function onLogin(cid)
    registerCreatureEvent(cid,"lootItem")
    return true
end
 
Code:
local bag = xxx                        -- ID  backpack
local itens ={xxx, xxx, xxx}          -- ID of itens that will be droped and put into a backpack
dropados.functionLoot(mName, mPosition)
    local items ={}
    for i = getTileInfo(mPosition).items,1,-1 do
        mPosition.stackpos = i
        table.insert(items, getThingFromPos(mPosition))
    end
    if#items == 0 then
        return true
    end
    local corpse =-1
    for _, item in ipairs(items) do
        local name = getItemName(item.uid):lower()
        if name:find(mName:lower())then
            corpse = item.uid
            break
        end
    end
    if not isContainer(corpse) then
        return true
    end
    if corpse ==-1then
        return true
    end
    for i =0, getContainerSize(corpse)-1 do
        local item = getContainerItem(corpse, i)
        if isInArray(itens, item.itemid)then
            doAddContainerItem(doAddContainerItem(corpse, bag,1), item.itemid, item.type)
            doRemoveItem(item.uid)
        end
    endendfunction onKill(cid, target)
    if isMonster(target)then
        addEvent(Loot,5, getCreatureName(target), getThingPos(target))
    end
    return true
end
function onLogin(cid)
    registerCreatureEvent(cid,"lootItem")
    return true
end
Well, I've tested and not work...
not have errors in console, but not do the expected...
I tryed to rewrite:
Code:
local bag = 21518  
local itens = {2158, 2523}
function Loot(mName, mPosition)
    local items ={}
    for i = getTileInfo(mPosition).items,1,-1 do
        mPosition.stackpos = i
        table.insert(items, getThingFromPos(mPosition))
    end
    if#items == 0 then
        return true
    end
    local corpse =-1
    for _, item in ipairs(items) do
        local name = getItemName(item.uid):lower()
        if name:find(mName:lower()) then
            corpse = item.uid
            break
        end
    end
    if not isContainer(corpse) then
        return true
    end
    if corpse == -1 then
        return true
    end
    for i =0, getContainerSize(corpse) -1 do
        local item = getContainerItem(corpse, i)
        if isInArray(itens, item.itemid) then
            doAddContainerItem(doAddContainerItem(corpse, bag, 1), item.itemid, item.type)
            doRemoveItem(item.uid)
        end
    end
end
function onKill(player, target)
    if target:isMonster() then
        addEvent(Loot, 5, target:getName(), target:getPosition())
    end
    return true 
end
 
You should be able to do it yourself via looking in the compat.lua file.
But why do you create a scheduled event for the function Loot()?
Just use:
Code:
Loot(target:getName(), target:getPosition())
 
You should be able to do it yourself via looking in the compat.lua file.
But why do you create a scheduled event for the function Loot()?
Just use:
Code:
Loot(target:getName(), target:getPosition())

It probably wont find corpse without delaying it with scheduled event. The 0 as the delay should work too, cus the first event will be done before executing scheduled one.
 
well, not have error in console ...
here my code;
Code:
local bag = 21518
local itens = {2158, 2523}
function Loot(mName, mPosition)
    local items ={}
    for i = getTileInfo(mPosition).items,1,-1 do
        mPosition.stackpos = i
        table.insert(items, getThingFromPos(mPosition))
    end
    if#items == 0 then
        return true
    end
    local corpse =-1
    for _, item in ipairs(items) do
        local name = getItemName(item.uid):lower()
        if name:find(mName:lower()) then
            corpse = item.uid
            break
        end
    end
    if not isContainer(corpse) then
        return true
    end
    if corpse == -1 then
        return true
    end
    for i =0, getContainerSize(corpse) -1 do
        local item = getContainerItem(corpse, i)
        if isInArray(itens, item.itemid) then
            doAddContainerItem(doAddContainerItem(corpse, bag, 1), item.itemid, item.type)
            doRemoveItem(item.uid)
        end
    end
end
function onKill(player, target)
    if target:isMonster() then
        Loot(target:getName(), target:getPosition())
    end
    return true
end

the function doAddContainerItem(doAddContainerItem(corpse, bag, 1), item.itemid, item.type)
seems wrong to me, but without errors in console :x hard to understand why not work
 
will try, but doAddContainerItem(doAddContainerItem(corpse, bag, 1), item.itemid, item.type) have parameters... and
doAddContainerItem(corpse, item.itemid, item.type) not have, not will be problematic?
 
Do as I said and add some print("1") (change 1 to the next number) and then run it, that way you will see where it stops.

The corpse is most likely a uid value (try to print it) - if that is the case then that is a parameter you can use.
 
I'm sorry for not understand you correctly, how I can put print("1") ... you can edit the code and post here? more easy to me..
and I will return with the result
 
Back
Top