• 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!
  • If you're using Gesior 2012 or MyAAC, please review this thread for information about a serious security vulnerability and a fix.

[TFS 1.3] Small Autoloot

OP
OP
Sarah Wesker

Sarah Wesker

ค∂vαηcε รүηтαx ❤
Support Team
Joined
Mar 16, 2017
Messages
1,185
Solutions
128
Reaction score
1,459
Location
London
GitHub
MillhioreBT
Twitch
millhiore_bt
the auto deposit works perfect.

I was going crazy, trying the new script with !autoloot, and nothing happened, there were no errors in the console lol
and then I saw that the command was !autoloottest 😂😂😂😂😂

by the way, we never reported to you that the !autoloot clear command doesn't work, It only works !autoloot remove.

How can I activate the currencyToBank at first login, What storage should I assign to the player or the account?

thanks for your scripts and contributions, they are very helpful.
Check the post again, I have fixed the problem with clear and added a new edit function
 

beenii

Active Member
Joined
Jul 26, 2010
Messages
531
Solutions
1
Reaction score
41
Check the post again, I have fixed the problem with clear and added a new edit function
wow the edit and the whole system is wonderful, works fine.

Something very strange is happening to me, I've been testing for a couple of hours
I'm just not sure what's going on, if it's the auto loot, or it's a problem with my tfs 1.5 downgrade 8.6

I start hunting with test players, and the loot flows normally, for example:
a cyclops only gives x1 short sword.

and suddenly 3 short swords start to come out in a cyclops, gold x3, and items loot of all monsters triplicate.

but I'm still not sure if it's my source code, or if it's a problem with autoloot, I'll keep testing.

im using:
 
OP
OP
Sarah Wesker

Sarah Wesker

ค∂vαηcε รүηтαx ❤
Support Team
Joined
Mar 16, 2017
Messages
1,185
Solutions
128
Reaction score
1,459
Location
London
GitHub
MillhioreBT
Twitch
millhiore_bt
wow the edit and the whole system is wonderful, works fine.

Something very strange is happening to me, I've been testing for a couple of hours
I'm just not sure what's going on, if it's the auto loot, or it's a problem with my tfs 1.5 downgrade 8.6

I start hunting with test players, and the loot flows normally, for example:
a cyclops only gives x1 short sword.

and suddenly 3 short swords start to come out in a cyclops, gold x3, and items loot of all monsters triplicate.

but I'm still not sure if it's my source code, or if it's a problem with autoloot, I'll keep testing.

im using:
do a search in your entire data/events/monster.lua or data/scripts/ folder and look for the scripts that are related to the onDropLoot event, I am more than sure that you have some strange script that does its job wrong

in case you don't have any loot related script and you are only using mine then the problem is the engine you use as this script is tested in TFS master and it works great

Note: This script doesn't create or clone objects, it just tries to move them from the corpse to the player, in case of coins these are remove and will go to the bank balance
 

beenii

Active Member
Joined
Jul 26, 2010
Messages
531
Solutions
1
Reaction score
41
do a search in your entire data/events/monster.lua or data/scripts/ folder and look for the scripts that are related to the onDropLoot event, I am more than sure that you have some strange script that does its job wrong

in case you don't have any loot related script and you are only using mine then the problem is the engine you use as this script is tested in TFS master and it works great

Note: This script doesn't create or clone objects, it just tries to move them from the corpse to the player, in case of coins these are remove and will go to the bank balance
i already tried for several days, and that triple loot problem never happened to me, it only happens to me when I activate the autoloot system but I don't know exactly when, since the loot starts normally and out of nowhere over time some begin to triple items, I restart the server and it's back to normal.

what a weird problem.

I will have to try later with the official version of tfs 1.5

I can't edit my last answer, I finally figured out what was going on, regarding my duplicate loot.

apparently it is when doing /reload scripts

I still can't figure out if it's a code error of some callback event, or if it's my source code.

because sometimes that happens, that I give reload scripts and an custom eventcallback onlook function duplicates the display.

I will feel comfortable to use your system for my project, since the reload scripts are not used in production of an online server :D
 

Fabi Marzan

Member
Joined
Aug 31, 2020
Messages
61
Solutions
1
Reaction score
12
@Sarah Wesker

I have problems with the system, saying !autoloot gives me debug. The client closes completely and no error occurs... another problem is that when I say !autoloot add, I get this error:

IS TFS 1.5 NEKIRO
Screenshot_17.png
 

VagosClubTM

Member
Joined
Aug 16, 2019
Messages
168
Reaction score
22
Location
Chile
Hello, here is a small, totally local autoloot system that is easy to configure ;)

Required version: TFS 1.5 last version

data/scripts/small_autoloot.lua
Here I will leave the version with money to the bank:
These small changes are required: A new way to manage player storages
Lua:
local autoloot = {
    talkaction = "!autoloottest",
    storageBase = 50000,
    freeAccountLimit = 10,
    premiumAccountLimit = 20,
    currencyToBank = true
}

local currencyItems = {}
if autoloot.currencyToBank then
    for index, item in pairs(Game.getCurrencyItems()) do
        currencyItems[item:getId()] = true
    end
end

local autolootCache = {}
local textEditRequests = {}

local function getPlayerLimit(player)
    return player:isPremium() and autoloot.premiumAccountLimit or autoloot.freeAccountLimit
end

local function getPlayerAutolootItems(player)
    local limits = getPlayerLimit(player)
    local guid = player:getGuid()
    local itemsCache = autolootCache[guid]
    if itemsCache then
        if #itemsCache > limits then
            local newChache = {unpack(itemsCache, 1, limits)}
            autolootCache[guid] = newChache
            return newChache
        end
        return itemsCache
    end

    local items = {}
    for i = 1, limits do
        local itemType = ItemType(math.max(player.storage[autoloot.storageBase + i], 0))
        if itemType and itemType:getId() ~= 0 then
            items[#items +1] = itemType:getId()
        end
    end

    autolootCache[guid] = items
    return items
end

local function setPlayerAutolootItems(player, newItems)
    local items = getPlayerAutolootItems(player)
    for i = getPlayerLimit(player), 1, -1 do
        local itemId = newItems[i]
        if itemId then
            player.storage[autoloot.storageBase + i] = itemId
            items[i] = itemId
        else
            player.storage[autoloot.storageBase + i] = -1
            table.remove(items, i)
        end
    end
    return true
end

local function addPlayerAutolootItem(player, itemId)
    local items = getPlayerAutolootItems(player)
    for _, id in pairs(items) do
        if itemId == id then
            return false
        end
    end
    items[#items +1] = itemId
    return setPlayerAutolootItems(player, items)
end

local function removePlayerAutolootItem(player, itemId)
    local items = getPlayerAutolootItems(player)
    for i, id in pairs(items) do
        if itemId == id then
            table.remove(items, i)
            return setPlayerAutolootItems(player, items)
        end
    end
    return false
end

local function hasPlayerAutolootItem(player, itemId)
    for _, id in pairs(getPlayerAutolootItems(player)) do
        if itemId == id then
            return true
        end
    end
    return false
end

local ec = EventCallback

function ec.onDropLoot(monster, corpse)
    if not corpse:getType():isContainer() then
        return
    end

    local corpseOwner = Player(corpse:getCorpseOwner())
    local items = corpse:getItems()
    local warningCapacity = false
    for _, item in pairs(items) do
        local itemId = item:getId()
        if hasPlayerAutolootItem(corpseOwner, itemId) then
            if currencyItems[itemId] then
                local worth = item:getWorth()
                corpseOwner:setBankBalance(corpseOwner:getBankBalance() + worth)
                corpseOwner:sendTextMessage(MESSAGE_STATUS_SMALL, string.format("Your balance increases by %d gold coins.", worth))
                item:remove()
            elseif not item:moveTo(corpseOwner) then
                warningCapacity = true
            end
        end
    end

    if warningCapacity then
        corpseOwner:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You no have capacity.")
    end
end

ec:register(3)

local talkAction = TalkAction(autoloot.talkaction)

function talkAction.onSay(player, words, param, type)
    local split = param:splitTrimmed(",")
    local action = split[1]
    if not action then
        player:showTextDialog(2160, string.format("Examples of use:\n%s add,gold coin\n%s remove,gold coin\n%s clear\n%s show\n%s edit\n\n~Available slots~\nfreeAccount: %d\npremiumAccount: %d\ncurrency to bank: %s", words, words, words, words, words, autoloot.freeAccountLimit, autoloot.premiumAccountLimit, autoloot.currencyToBank and "yes" or "no"), false)
        return false
    end

    if action == "clear" then
        setPlayerAutolootItems(player, {})
        player:sendCancelMessage("Autoloot list cleaned.")
        return false
    elseif action == "show" then
        local items = getPlayerAutolootItems(player)
        local description = {string.format('~ Your autoloot list, capacity: %d/%d ~\n', #items, getPlayerLimit(player))}
        for i, itemId in pairs(items) do
            description[#description +1] = string.format("%d) %s", i, ItemType(itemId):getName())
        end
        player:showTextDialog(2160, table.concat(description, '\n'), false)
        return false
    elseif action == "edit" then
        local items = getPlayerAutolootItems(player)
        if #items == 0 then
            -- Example
            items = {2160,2672,2432}
        end
        local description = {}
        for i, itemId in pairs(items) do
            description[#description +1] = ItemType(itemId):getName()
        end
        player:registerEvent("autolootTextEdit")
        player:showTextDialog(1948, string.format("To add articles you just have to write their IDs or names on each line\nfor example:\n\n%s", table.concat(description, '\n')), true, 666)
        textEditRequests[player:getGuid()] = true
        return false
    end

    local function getItemType()
        local itemType = ItemType(split[2])
        if not itemType or itemType:getId() == 0 then
            itemType = ItemType(math.max(tonumber(split[2]) or 0), 0)
            if not itemType or itemType:getId() == 0 then
                player:sendCancelMessage(string.format("The item %s does not exists!", split[2]))
                return false
            end
        end
        return itemType
    end

    if action == "add" then
        local itemType = getItemType()
        if itemType then
            local limits = getPlayerLimit(player)
            if #getPlayerAutolootItems(player) >= limits then
                player:sendCancelMessage(string.format("Your auto loot only allows you to add %d items.", limits))
                return false
            end

            if addPlayerAutolootItem(player, itemType:getId()) then
                player:sendCancelMessage(string.format("Perfect you have added to the list: %s", itemType:getName()))
            else
                player:sendCancelMessage(string.format("The item %s already exists!", itemType:getName()))
            end
        end
        return false
    elseif action == "remove" then
        local itemType = getItemType()
        if itemType then
            if removePlayerAutolootItem(player, itemType:getId()) then
                player:sendCancelMessage(string.format("Perfect you have removed to the list the article: %s", itemType:getName()))
            else
                player:sendCancelMessage(string.format("The item %s does not exists in the list.", itemType:getName()))
            end
        end
        return false
    end

    return false
end

talkAction:separator(" ")
talkAction:register()

local creatureEvent = CreatureEvent("autolootCleanCache")

function creatureEvent.onLogout(player)
    setPlayerAutolootItems(player, getPlayerAutolootItems(player))
    autolootCache[player:getGuid()] = nil
    return true
end

creatureEvent:register()

creatureEvent = CreatureEvent("autolootTextEdit")

function creatureEvent.onTextEdit(player, item, text)
    player:unregisterEvent("autolootTextEdit")

    local split = text:splitTrimmed("\n")
    local items = {}
    for index, name in pairs(split) do repeat
        local itemType = ItemType(name)
        if not itemType or itemType:getId() == 0 then
            itemType = ItemType(tonumber(name))
            if not itemType or itemType:getId() == 0 then
                break
            end

            break
        end

        items[#items +1] = itemType:getId()
    until true end
    setPlayerAutolootItems(player, items)
    player:sendCancelMessage(string.format("Perfect, you have modified the list of articles manually."))
    return true
end

creatureEvent:register()

Note: Fixed the issues I was having clear and added a new command: !autoloot edit this works for manually editing the item list
View attachment 65760
For example, if I have a VIP user system, how can I make it so that instead of taking the default premmy of the game, use the remaining VIP days to recognize if you are a VIP or not and so the system would work with the VIP one and not with the Premmy one? predetermined
 
OP
OP
Sarah Wesker

Sarah Wesker

ค∂vαηcε รүηтαx ❤
Support Team
Joined
Mar 16, 2017
Messages
1,185
Solutions
128
Reaction score
1,459
Location
London
GitHub
MillhioreBT
Twitch
millhiore_bt

ralke

(҂ ͠❛ ෴ ͡❛)ᕤ
Joined
Dec 17, 2011
Messages
1,171
Solutions
27
Reaction score
636
Location
Santiago - Chile
GitHub
ralke23
Twitch
ralke23
Hi again @Sarah Wesker!
I'm getting more tests of the script, and found this

1655861584384.png

Any idea of what is about? Thanks in advance!
Solved. Added
Lua:
local corpseOwner = Player(corpse:getCorpseOwner())  
if not corpseOwner then       
return  
end
 
Last edited:

AncientAngelus

New Member
Joined
Dec 13, 2009
Messages
25
Reaction score
3
Hello! thank you for the reply, I appreciate it. I did the changes in the code and compiled it and opened it and still gives me the same thing.
But now is from gold_converter.lua in data/scripts/actions/tools about the getCurrencyItems a nil value and also from the small autoloot.lua also getcurrencyitems a nil value :/
 

AncientAngelus

New Member
Joined
Dec 13, 2009
Messages
25
Reaction score
3
Well, now I got it by having to redo all over the server lol. But now, I get an error for attempt to index field 'storage' a nil value. I am using tfs 1.4 but still did the changes to the compat file for the player storages although also shows about monster.lua file for the ondroploot.

tfs1.4 monster loot.PNG
 
Top