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

My Autoloot System for TFS 0.4

Sarah Wesker

ค∂vαηcε รүηтαx ❤
Support Team
Joined
Mar 16, 2017
Messages
1,040
Solutions
105
Reaction score
1,097
Location
London
GitHub
MillhioreBT
I recognize that there are already some systems that deal with the same, but this had been saved for some time and I want to share it with you now more than ever, as I plan to resume my stay as a scriptwriter, so this will be a good start. thanks!

go to their folder "mods" and create a new file "xml" with the name you want and paste the following code:
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>  
<mod name="Autoloot Revolution BT" version="1.0" author="Millhiore BT" contact="none.com" enabled="yes">
<config name="AutolootRevolutionBT">
<![CDATA[
[email protected] You configurations:
autolootConfig = {}
autolootConfig.storageItems = 27000
autolootConfig.blockMonsters = {}
autolootConfig.goldToBank = true
autolootConfig.goldBankAnimation = true
autolootConfig.distanceLooting = 7
autolootConfig.freeSlots = 3
autolootConfig.premiumSlots = 6
autolootConfig.vipStorage = {0,0}
autolootConfig.playerLevel = 8
autolootConfig.corpseEffect = CONST_ME_NONE
autolootConfig.golds = {2148, 2152, 2160}
autolootConfig.tittle = "Welcomen to Autoloot System\nCreate by Millhiore BT\n\nOptions: help, clear, add, remove\n"
autolootConfig.notHaveCapDrop = false
[email protected] getPlayerPremiumEnabled(cid)
--# Return boolean
--# Create by Millhiore BT
function getPlayerPremiumEnabled(cid)
    if getConfigValue("freePremium") then
        return true
    end
    return getPlayerPremiumDays(cid) > 0
end
[email protected] getPlayerAutolootVip(cid)
--# Return boolean
--# Create by Millhiore BT
function getPlayerAutolootVip(cid)
    if autolootConfig.vipStorage[1] > 0 then
        if autolootConfig.vipStorage[2] > 0 then
            return getPlayerStorageValue(cid, autolootConfig.vipStorage[1]) == autolootConfig.vipStorage[2]
        else
            return getPlayerStorageValue(cid, autolootConfig.vipStorage[1]) >= os.time()
        end
    end
    return true
end
[email protected] getPositionDistance(position, positionEx)
--# Return number
--# Create by Millhiore BT
function getPositionDistance(position, positionEx)
    return math.max(math.max(math.abs(position.x - positionEx.x), math.abs(position.y - positionEx.y)), math.abs(position.z - positionEx.z))
end
[email protected] getPositionCorpse(pos [, itemid])
--# Return thing/nil
--# Create by Millhiore BT
function getPositionCorpse(pos, itemid)
    local tile = getTileInfo(pos)
    for index = 0, tile.things do
        pos.stackpos = index
        local corpse = getThingFromPos(pos, false)
        if corpse.itemid > 1 and isCorpse(corpse.uid) then
            local itemid = itemid or corpse.itemid
            if corpse.itemid == itemid then
                return corpse
            end
        end
    end
end
[email protected] getContainerItems(uid [, array])
--# Return array
--# Create by Millhiore BT
function getContainerItems(container, array, haveCap)
    array = array or {}
    haveCap = haveCap or false
    if not isContainer(container.uid) or getContainerSize(container.uid) == 0 then
        array[#array +1] = container
    else
        local size = getContainerSize(container.uid)
        haveCap = (getContainerCap(container.uid) -size) > 0
        for slot = 0, (size -1) do
            local item = getContainerItem(container.uid, slot)
            if item.itemid > 1 then
                getContainerItems(item, array, haveCap)
            end
        end
    end
    return #array >= 1 and array, haveCap
end
[email protected] getContainerItemsById(array/uid, itemid)
--# Return array
--# Create by Millhiore BT
function getContainerItemsById(container, itemid)
    local founds = {}
    local items = not container.uid and container or getContainerItems(container)
    for index, item in pairs(items) do
        if item.itemid == itemid then
            founds[#founds +1] = item
        end
    end
    return #founds >= 1 and founds
end
[email protected] doPlayerAddItemStackable(cid, itemid, count)
--# Return boolean
--# Create by Millhiore BT
function doPlayerAddItemStackable(cid, itemid, count)
    local container = getPlayerSlotItem(cid, CONST_SLOT_BACKPACK)
    if container.itemid > 1 then
        local items = getContainerItemsById(container, itemid)
        if not items then
            return doPlayerAddItem(cid, itemid, count)
        else
            local piles = #items
            for index, item in pairs(items) do
                if item.type < 100 then
                    local sum = item.type + count
                    local result = doTransformItem(item.uid, itemid, sum)
                    if sum <= 100 then
                        return result
                    else
                        return doPlayerAddItem(cid, itemid, sum - 100)
                    end
                else
                    piles = piles - 1
                    if piles == 0 then
                        return doPlayerAddItem(cid, itemid, count)
                    end
                end
            end
        end
    end
    return false
end
[email protected] getContainerMoneys(items)
--# Return array/false
--# Create by Millhiore BT
function getContainerMoneys(items)
    local moneys = {}
    for slot, item in pairs(items) do
        if isInArray(autolootConfig.golds, item.itemid) then
            moneys[#moneys +1] = item
        end
    end
    return #moneys > 0 and moneys
end
[email protected] doCorpseAutoloot(cid, pos itemid)
--# Return boolean/nil
--# Create by Millhiore BT
function doCorpseAutoloot(cid, pos, itemid, moneys)
    if not getPlayerAutolootVip(cid) or getPositionDistance(getThingPosition(cid), pos) > autolootConfig.distanceLooting
    or getPlayerLevel(cid) < autolootConfig.playerLevel then
        return nil
    end
    local corpse = getPositionCorpse(pos, itemid)
    if corpse and isContainer(corpse.uid) then
        local items, haveCap = moneys or getContainerItems(corpse)
        local sendEffect = false
        if items then
            for slot, item in pairs(items) do
                if isInArray(getPlayerAutolootItems(cid), item.itemid) then
                    sendEffect = true
                    local removeIt = false
                    local goldToBank = autolootConfig.goldToBank and isInArray(autolootConfig.golds, item.itemid)
                    if not goldToBank then
                        if not haveCap and autolootConfig.notHaveCapDrop then
                            return doCorpseAutoloot(cid, pos, itemid, getContainerMoneys(items))
                        end
                        if isItemStackable(item.itemid) then
                            removeIt = doPlayerAddItemStackable(cid, item.itemid, item.type)
                        else
                            removeIt = doPlayerAddItem(cid, item.itemid)
                        end
                    else
                        local add = (getItemInfo(item.itemid).worth * item.type)
                        removeIt = doPlayerSetBalance(cid, getPlayerBalance(cid) + add)
                        if autolootConfig.goldBankAnimation then
                            doSendAnimatedText(pos, string.format("+%u gps", add), TEXTCOLOR_YELLOW, cid)
                        end
                    end
                    if removeIt then
                        doRemoveItem(item.uid)
                    end
                end
            end
            if sendEffect then
                doSendMagicEffect(pos, autolootConfig.corpseEffect, cid)
            end
            return true
        end
    end
end
[email protected] getPlayerAutolootItems(cid)
--# Return array
--# Create by Millhiore BT
function getPlayerAutolootItems(cid)
    local array = {}
    local content = tostring(getPlayerStorageValue(cid, autolootConfig.storageItems))
    for itemid in string.gmatch(content, "(%d+):") do
        array[#array +1] = tonumber(itemid)
    end
    return array
end
[email protected] getPlayerAutolootItem(cid, itemid)
--# Return number/nil
--# Create by Millhiore BT
function getPlayerAutolootItem(cid, itemid)
    local autolootItems = getPlayerAutolootItems(cid)
    for index, id in pairs(autolootItems) do
        if itemid == id then
            return index
        end
    end
end
[email protected] setPlayerAutolootItems(cid [, array])
--# Return boolean
--# Create by Millhiore BT
function setPlayerAutolootItems(cid, array)
    local array = array or {}
    local content = "&"
    for index, itemid in pairs(array) do
        content = string.format("%s%u:", content, itemid)
    end
    return setPlayerStorageValue(cid, autolootConfig.storageItems, content)
end
[email protected] addPlayerAutolootItem(cid, itemid)
--# Return boolean
--# Create by Millhiore BT
function addPlayerAutolootItem(cid, itemid)
    local autolootItems = getPlayerAutolootItems(cid)
    local found = getPlayerAutolootItem(cid, itemid)
    if not found then
        autolootItems[#autolootItems +1] = itemid
        return setPlayerAutolootItems(cid, autolootItems)
    end
end
[email protected] removePlayerAutolootItem(cid, itemid)
--# Return boolean/nil
--# Create by Millhiore BT
function removePlayerAutolootItem(cid, itemid)
    local autolootItems = getPlayerAutolootItems(cid)
    local found = getPlayerAutolootItem(cid, itemid)
    if found then
        table.remove(autolootItems, found)
        return setPlayerAutolootItems(cid, autolootItems)
    end
end
[email protected] showPlayerAutoloot(cid)
--# Return boolean
--# Create by Millhiore BT
function showPlayerAutoloot(cid)
    local maxItems = getPlayerPremiumEnabled(cid) and autolootConfig.premiumSlots or autolootConfig.freeSlots
    local content = string.format("%sYou available slots: %u\n\n%s", autolootConfig.tittle, maxItems, "Your autoloot items:\n")
    local autolootItems = getPlayerAutolootItems(cid)
    for index, itemid in pairs(autolootItems) do
        local it = getItemInfo(itemid)
        content = string.format("%s %c %s\n", content, 155, it.name)
    end
    return doShowTextDialog(cid, 2529, content)
end
[email protected] showPlayerAutolootHelp(cid)
--# Return boolean
--# Create by Millhiore BT
function showPlayerAutolootHelp(cid)
    local content = autolootConfig.tittle .. "For you info:\n"
    for key, value in pairs(autolootConfig) do
        if not isInArray({"storageItems", "blockMonsters", "vipStorage", "golds", "tittle"}, key) then
            content = string.format("%s%c %s: %s\n", content, 155, tostring(key), tostring(value))
        end
    end
    return doShowTextDialog(cid, 2529, content)
end
]]>
</config>
<event type="login" name="AutolootRBTLogin" event="script">
<![CDATA[
function onLogin(cid)
    local maxItems = getPlayerPremiumEnabled(cid) and autolootConfig.premiumSlots or autolootConfig.freeSlots
    local autolootItems = getPlayerAutolootItems(cid)
    if #autolootItems > maxItems then
        for index = autolootConfig.premiumSlots, autolootConfig.freeSlots, -1 do
            table.remove(autolootItems, index)
        end
        setPlayerAutolootItems(cid, autolootItems)
        doPlayerSendCancel(cid, "Your list of items overflowed, you should check your list.")
    end
    registerCreatureEvent(cid, "AutolootRBTCombat")
    return true
end
]]>
</event>
<event type="death" name="AutolootRBTDeath" event="script">
<![CDATA[
domodlib("AutolootRevolutionBT")
function onDeath(cid, corpse, deathList)
    local killer = deathList[1]
    local position = getThingPosition(cid)
    if corpse.itemid > 1 then
        addEvent(doCorpseAutoloot, 100, killer, position, corpse.itemid)
    end
    return true
end
]]>
</event>
<event type="combat" name="AutolootRBTCombat" event="script">
<![CDATA[
domodlib("AutolootRevolutionBT")
if isPlayer(cid) and isMonster(target) then
    if not isInArray(autolootConfig.blockMonsters, string.lower(getCreatureName(target))) then
        registerCreatureEvent(target, "AutolootRBTDeath")
    end
end
return true
]]>
</event>
<talkaction words="!autoloot;/autoloot" event="buffer">
<![CDATA[
domodlib("AutolootRevolutionBT")
local split = string.explode(param, ",") or {}
local action = tostring(split[1]):lower()
local name = tostring(split[2])
local itemid = getItemIdByName(name, false)
local it = getItemInfo(itemid and itemid or 0)
local position = getThingPosition(cid)
if action == "add" then
    if not it then
        doPlayerSendCancel(cid, string.format("This item %s does not exist.", name))
    else
        local maxItems = getPlayerPremiumEnabled(cid) and autolootConfig.premiumSlots or autolootConfig.freeSlots
        local autolootItems = getPlayerAutolootItems(cid)
        if #autolootItems > maxItems then
            for index = autolootConfig.premiumSlots, autolootConfig.freeSlots, -1 do
                table.remove(autolootItems, index)
            end
            setPlayerAutolootItems(cid, autolootItems)
            doPlayerSendCancel(cid, "Your list of items overflowed, you should check your list.")
        elseif #autolootItems == maxItems then
            doPlayerSendCancel(cid, string.format("Your maximum limit is %u items, you must eliminate one to add another.", maxItems))
        elseif addPlayerAutolootItem(cid, itemid) then
            doPlayerSendCancel(cid, string.format("You added the item %s in the list.", name))
        else
            doSendMagicEffect(position, CONST_ME_POFF, cid)
            doPlayerSendCancel(cid, string.format("This item %s already in the list.", name))
        end
    end
elseif action == "remove" then
    if not it then
        doPlayerSendCancel(cid, string.format("This item %s does not exist.", name))
    else
        if removePlayerAutolootItem(cid, itemid) then
            doPlayerSendCancel(cid, string.format("You removed the item %s from the list.", name))
        else
            doPlayerSendCancel(cid, string.format("This item %s is not in the list.", name))
        end
    end
elseif action == "help" then
    showPlayerAutolootHelp(cid)
elseif action == "clear" then
    setPlayerAutolootItems(cid)
    doPlayerSendCancel(cid, "The list of items is now empty.")
else
    showPlayerAutoloot(cid)
end
return true
]]>
</talkaction>
</mod>
that's it all!

The command is:
Code:
!autoloot
!autoloot help
!autoloot clear
!autoloot add
!autoloot remove

How to configure it?
in the first lines you will find the following:
Code:
[email protected] You configurations:
autolootConfig = {}
autolootConfig.storageItems = 27000
autolootConfig.blockMonsters = {}
autolootConfig.goldToBank = true
autolootConfig.goldBankAnimation = true
autolootConfig.distanceLooting = 7
autolootConfig.freeSlots = 3
autolootConfig.premiumSlots = 6
autolootConfig.vipStorage = {0,0}
autolootConfig.playerLevel = 8
autolootConfig.corpseEffect = CONST_ME_NONE
autolootConfig.golds = {2148, 2152, 2160}
autolootConfig.tittle = "Welcomen to Autoloot System\nCreate by Millhiore BT\n\nOptions: help, clear, add, remove\n"
autolootConfig.notHaveCapDrop = false

Notes:
  • I'm not sure if it works 100%, but I can assure +/- 99%
  • If you want to help me improve it, you are welcome to do it.
  • The system eliminates the elements that exceed the limit automatically, for example when you lose "premium".
 

GODGollox

New Member
Joined
Apr 9, 2019
Messages
22
Reaction score
0
This mod has errors please update, or some other system!
Post automatically merged:

XML:
[8/6/2020 13:19:26] [Error - TalkAction Interface]
[8/6/2020 13:19:26] local cid = 268476459
[8/6/2020 13:19:26] local words = "!autoloot"
[8/6/2020 13:19:26] local param = ""
[8/6/2020 13:19:26] local channel = 65534
[8/6/2020 13:19:26] domodlib("AutolootRevolutionBT")
[8/6/2020 13:19:26] local split = string.explode(param, ",") or {}
[8/6/2020 13:19:26] local action = tostring(split[1]):lower()
[8/6/2020 13:19:26] local name = tostring(split[2])
[8/6/2020 13:19:26] local itemid = getItemIdByName(name, false)
[8/6/2020 13:19:26] local it = getItemInfo(itemid and itemid or 0)
[8/6/2020 13:19:26] local position = getThingPosition(cid)
[8/6/2020 13:19:27] if action == "add" then
[8/6/2020 13:19:27]     if not it then
[8/6/2020 13:19:27]         doPlayerSendCancel(cid, string.format("This item %s does not exist.", name))
[8/6/2020 13:19:27]     else
[8/6/2020 13:19:27]         local maxItems = getPlayerPremiumEnabled(cid) and autolootConfig.premiumSlots or autolootConfig.freeSlots
[8/6/2020 13:19:27]         local autolootItems = getPlayerAutolootItems(cid)
[8/6/2020 13:19:27]         if #autolootItems > maxItems then
[8/6/2020 13:19:27]             for index = autolootConfig.premiumSlots, autolootConfig.freeSlots, -1 do
[8/6/2020 13:19:27]                 table.remove(autolootItems, index)
[8/6/2020 13:19:27]             end
[8/6/2020 13:19:27]             setPlayerAutolootItems(cid, autolootItems)
[8/6/2020 13:19:27]             doPlayerSendCancel(cid, "Your list of items overflowed, you should check your list.")
[8/6/2020 13:19:27]         elseif #autolootItems == maxItems then
[8/6/2020 13:19:27]             doPlayerSendCancel(cid, string.format("Your maximum limit is %u items, you must eliminate one to add another.", maxItems))
[8/6/2020 13:19:27]         elseif addPlayerAutolootItem(cid, itemid) then
[8/6/2020 13:19:27]             doPlayerSendCancel(cid, string.format("You added the item %s in the list.", name))
[8/6/2020 13:19:27]         else
[8/6/2020 13:19:27]             doSendMagicEffect(position, CONST_ME_POFF, cid)
[8/6/2020 13:19:27]             doPlayerSendCancel(cid, string.format("This item %s already in the list.", name))
[8/6/2020 13:19:27]         end
[8/6/2020 13:19:27]     end
[8/6/2020 13:19:27] elseif action == "remove" then
[8/6/2020 13:19:27]     if not it then
[8/6/2020 13:19:27]         doPlayerSendCancel(cid, string.format("This item %s does not exist.", name))
[8/6/2020 13:19:27]     else
[8/6/2020 13:19:27]         if removePlayerAutolootItem(cid, itemid) then
[8/6/2020 13:19:27]             doPlayerSendCancel(cid, string.format("You removed the item %s from the list.", name))
[8/6/2020 13:19:27]         else
[8/6/2020 13:19:27]             doPlayerSendCancel(cid, string.format("This item %s is not in the list.", name))
[8/6/2020 13:19:27]         end
[8/6/2020 13:19:27]     end
[8/6/2020 13:19:27] elseif action == "help" then
[8/6/2020 13:19:27]     showPlayerAutolootHelp(cid)
[8/6/2020 13:19:27] elseif action == "clear" then
[8/6/2020 13:19:27]     setPlayerAutolootItems(cid)
[8/6/2020 13:19:27]     doPlayerSendCancel(cid, "The list of items is now empty.")
[8/6/2020 13:19:27] else
[8/6/2020 13:19:27]     showPlayerAutoloot(cid)
[8/6/2020 13:19:27] end
[8/6/2020 13:19:27] return true

[8/6/2020 13:19:27] Description:
[8/6/2020 13:19:27] (LuaInterface::luaGetItemIdByName) Item not found
 
Last edited:

jondropss

New Member
Joined
Jul 19, 2020
Messages
41
Reaction score
2
Hello there!
i have a problem
when the autoloot take de loot, the char get debug =(
my client is extended.... maybe thats why?
 

Darbaxa

New Member
Joined
May 1, 2021
Messages
24
Reaction score
4
Location
Egypt
Code:
[3:52:02.026] [Error - CreatureScript Interface]
[3:52:02.026] In a timer event called from:
[3:52:02.026] domodlib("AutolootRevolutionBT")
[3:52:02.026] function onDeath(cid, corpse, deathList)
[3:52:02.026]     local killer = deathList[1]
[3:52:02.026]     local position = getThingPosition(cid)
[3:52:02.026]     if corpse.itemid > 1 then
[3:52:02.026]         addEvent(doCorpseAutoloot, 100, killer, position, corpse.itemid)
[3:52:02.026]     end
[3:52:02.026]     return true
[3:52:02.026] end
[3:52:02.026] :onDeath
[3:52:02.026] Description:
[3:52:02.026] (luaGetThingPosition) Thing not found

[3:52:02.026] [Error - CreatureScript Interface]
[3:52:02.026] In a timer event called from:
[3:52:02.026] domodlib("AutolootRevolutionBT")
[3:52:02.026] function onDeath(cid, corpse, deathList)
[3:52:02.026]     local killer = deathList[1]
[3:52:02.026]     local position = getThingPosition(cid)
[3:52:02.026]     if corpse.itemid > 1 then
[3:52:02.026]         addEvent(doCorpseAutoloot, 100, killer, position, corpse.itemid)
[3:52:02.026]     end
[3:52:02.026]     return true
[3:52:02.026] end
[3:52:02.026] :onDeath
[3:52:02.026] Description:
[3:52:02.026] [string "[email protected] You configurations:..."]:42: attempt to index local 'position' (a boolean value)
[3:52:02.026] stack traceback:
[3:52:02.026]   [string "[email protected] You configurations:..."]:42: in function 'getPositionDistance'
[3:52:02.026]   [string "[email protected] You configurations:..."]:140: in function <[string "[email protected] You configurations:..."]:139>
any idea?
 
OP
OP
Sarah Wesker

Sarah Wesker

ค∂vαηcε รүηтαx ❤
Support Team
Joined
Mar 16, 2017
Messages
1,040
Solutions
105
Reaction score
1,097
Location
London
GitHub
MillhioreBT
Hello there!
i have a problem
when the autoloot take de loot, the char get debug =(
my client is extended.... maybe thats why?
If your custom client doesn't have animated text, that's probably the reason why you debug your client

@kedlei / @Darbaxa
This mod is for TFS 0.4 and possibly also compatible with TFS 0.3.6, but OTX is not on the compatibility list

Use the forum search engine, I am sure you will find some other mod, you can even ask for help by requesting a script in the support board - request
 
Last edited:
Top