• 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
 
well, I try this hehe
but not have return in screen
see:
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
    print("1")
    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
            print("for...")
       break
        end
    end
    if not isContainer(corpse) then
        return true
    end
    if corpse == -1 then
        return true
    end
    print("2")
    for i =0, getContainerSize(corpse) -1 do
        local item = getContainerItem(corpse, i)
        if isInArray(itens, item.itemid) then
            doAddContainerItem(corpse, item.itemid, item.type)
            doRemoveItem(item.uid)
        end
    end
end
function onKill(player, target)
    if target:isMonster() then
        Loot(target:getName(), target:getPosition())
    end
    print("1")
    return true
end
F0lumkg.png

seems like the creaturescript not are recognized
 
Ye, the script is not loaded.
Check names, login.lua registration aswell as the file path.
 
<event type="kill" name="lootItem" script="others/bag.lua"/>
the register in login
'LootItem' (is the last...)
are all corect
 
and aren't them case sensitive? if so, lootItem and LootItem are two different things, and just to make sure, can you please show us 3 screens of the following: login.lua, folder where the bag.lua script is, and creatures.xml
 
now login: 'lootItem' (I update this)
bag.lua
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
    print("1")
    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
            print("for...")
       break
        end
    end
    if not isContainer(corpse) then
        return true
    end
    if corpse == -1 then
        return true
    end
    print("2")
    for i =0, getContainerSize(corpse) -1 do
        local item = getContainerItem(corpse, i)
        if isInArray(itens, item.itemid) then
            doAddContainerItem(corpse, item.itemid, item.type)
            doRemoveItem(item.uid)
        end
    end
end
function onKill(player, target)
    if target:isMonster() then
        Loot(target:getName(), target:getPosition())
    end
    print("1")
    return true 
end
and xml: <event type="kill" name="lootItem" script="others/bag.lua"/>
 
well, loaded now...
but not work..
have the prints "1" and not have the print "2" and not have the "for..."
in this case the script don't enter in some if and for
 
Add prints after each if statment, that way you see where it stops.
Right now we know it can be one of 4 if statment or a for loop.
 
now I edit the code, put alot of prints
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))
        print("for Function Loot")
    end
    print("just to see the if the function loot run")
    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
            print("second for from loot")
            break
        end
    end
    if not isContainer(corpse) then
        return true
    end
    if corpse == -1 then
        return true
    end
    print("print 2 to teste if are running the function")
    for i = 0, getContainerSize(corpse) -1 do
        local item = getContainerItem(corpse, i)
        if isInArray(itens, item.itemid) then
            doAddContainerItem(corpse, item.itemid, item.type)
            doRemoveItem(item.uid)
            print("third for in the function")
        end
    end
end
function onKill(player, target)
    if target:isMonster() then
        Loot(target:getName(), target:getPosition())
    end
    print("main")
    return true 
end
now I have errors in console..
QIIpCft.png
 
here...
in linux all new...
tfs updated.
my code now!!!
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))
        print("first for of Loot")
    end
    if#items == 0 then
    print("first if of loot")     
    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
            print("second if of loot")
            break
        end
    print("second for of loot")
    end
    if not isContainer(corpse) then
    print("third if of loot")     
    return true
    end
    if corpse == -1 then
    print("fourth if of loot")     
    return true
    end
    for i = 0, getContainerSize(corpse) -1 do
        local item = getContainerItem(corpse, i)
        if isInArray(itens, item.itemid) then
            doAddContainerItem(corpse, item.itemid, item.type)
            doRemoveItem(item.uid)
            print("fifith if of function")
        end
        print("third for of loot")
    end
end
function onKill(player, target)
    if target:isMonster() then
        Loot(target:getName(), target:getPosition())
    end
    print("main")
    return true
end
and a print to see what is printed...
I6bKMPJ.png
 
Last edited:
Use code tags, not a spoiler.

It breaks here:
Code:
local item = getContainerItem(corpse, i)
if isInArray(itens, item.itemid) then
 
Back
Top