Ir para conteúdo

Featured Replies

Postado
  Em 25/10/2015 em 18:02, Tricoder disse:
SCREENSHOT


______________________________________________

COMANDOS


!autoloot add, itemId ou name -- Adicionando um item na lista
!autoloot remove, itemId or name -- Remover um item da lista
!autoloot show -- Mostrar a lista do autoLoot
!autoloot clear -- Limpar a lista do autoLoot
______________________________________________
SCRIPT

data/global.lua


-- AutoLoot config
    AUTO_LOOT_MAX_ITEMS = 5

    -- Reserved storage
    AUTOLOOT_STORAGE_START = 10000
    AUTOLOOT_STORAGE_END = AUTOLOOT_STORAGE_START + AUTO_LOOT_MAX_ITEMS
-- AutoLoot config end

talkactions/talkactions.xml


<talkaction words="!autoloot" separator=" " script="autoloot.lua"/>

talkactions/scripts/autoloot.lua


function onSay(player, words, param)
    local split = param:split(",")

    local action = split[1]
    if action == "add" then
        local item = split[2]:gsub("%s+", "", 1)
        local itemType = ItemType(item)
        if itemType:getId() == 0 then
            itemType = ItemType(tonumber(item))
            if itemType:getId() == 0 then
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "There is no item with that id or name.")
                return false
            end
        end

        local itemName = tonumber(split[2]) and itemType:getName() or item
        local size = 0
        for i = AUTOLOOT_STORAGE_START, AUTOLOOT_STORAGE_END do
            local storage = player:getStorageValue(i)
            if size == AUTO_LOOT_MAX_ITEMS then
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "The list is full, please remove from the list to make some room.")
                break
            end

            if storage == itemType:getId() then
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, itemName .." is already in the list.")
                break
            end

            if storage <= 0 then
                player:setStorageValue(i, itemType:getId())
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, itemName .." has been added to the list.")
                break
            end

            size = size + 1
        end
    elseif action == "remove" then
        local item = split[2]:gsub("%s+", "", 1)
        local itemType = ItemType(item)
        if itemType:getId() == 0 then
            itemType = ItemType(tonumber(item))
            if itemType:getId() == 0 then
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "There is no item with that id or name.")
                return false
            end
        end

        local itemName = tonumber(split[2]) and itemType:getName() or item
        for i = AUTOLOOT_STORAGE_START, AUTOLOOT_STORAGE_END do
            if player:getStorageValue(i) == itemType:getId() then
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, itemName .." has been removed from the list.")
                player:setStorageValue(i, 0)
                return false
            end
        end

        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, itemName .." was not founded in the list.")
    elseif action == "show" then
        local text = "-- Auto Loot List --\n"
        local count = 1
        for i = AUTOLOOT_STORAGE_START, AUTOLOOT_STORAGE_END do
            local storage = player:getStorageValue(i)
            if storage > 0 then
                text = string.format("%s%d. %s\n", text, count, ItemType(storage):getName())
                count = count + 1
            end
        end

        if text == "" then
            text = "Empty"
        end
   
        player:showTextDialog(1950, text, false)
    elseif action == "clear" then
        for i = AUTOLOOT_STORAGE_START, AUTOLOOT_STORAGE_END do
            player:setStorageValue(i, 0)
        end

        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "The autoloot list has been cleared.")
    else
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Use the commands: !autoloot {add, remove, show, clear}")
    end

    return false
end

creaturescripts/creaturescripts.xml


<event type="kill" name="AutoLoot" script="autoloot.lua" />

creaturescripts/scripts/autoloot.lua


local function scanContainer(cid, position)
    local player = Player(cid)
    if not player then
        return
    end

    local corpse = Tile(position):getTopDownItem()
    if not corpse then
        return
    end

    if corpse:getType():isCorpse() and corpse:getAttribute(ITEM_ATTRIBUTE_CORPSEOWNER) == cid then
        for i = corpse:getSize() - 1, 0, -1 do
            local containerItem = corpse:getItem(i)
            if containerItem then
                for i = AUTOLOOT_STORAGE_START, AUTOLOOT_STORAGE_END do
                    if player:getStorageValue(i) == containerItem:getId() then
                        containerItem:moveTo(player)
                    end
                end
            end
        end
    end
end

function onKill(player, target)
    if not target:isMonster() then
        return true
    end

    addEvent(scanContainer, 100, player:getId(), target:getPosition())
    return true
end

creaturescripts/scripts/login.lua


player:registerEvent("AutoLoot")
______________________________________________

CRÉDITOS

  • Printer

desculpe reviver o topico, como deixo o comando !autoloot pra ativar o sistema e o restante pra gerenciar pelo (manager loot containers) Meu é tfs 1.3 versao 12.3 

  • Respostas 29
  • Visualizações 13.9k
  • Created
  • Última resposta

Top Posters In This Topic

Most Popular Posts

  • vou testar... no meu ot é assim   -- Events     for i = 1, #events do         player:registerEvent(events)         player:registerEvent("AutoLoot")     end     não

Postado
  Em 11/10/2020 em 03:26, feipedorp disse:

desculpe reviver o topico, como deixo o comando !autoloot pra ativar o sistema e o restante pra gerenciar pelo (manager loot containers) Meu é tfs 1.3 versao 12.3 

 

vc quer um comando que ativa o autoloot? exemplo !autoloot on/off?

vodkart_logo.png

[*Ninguém será digno do sucesso se não usar suas derrotas para conquistá-lo.*]

 

DISCORDvodkart#6090

 

Postado
  Em 11/10/2020 em 03:33, Vodkart disse:

 

vc quer um comando que ativa o autoloot? exemplo !autoloot on/off?

Eu quero deixar o sistema como atual igual global, para gerenciamento de backpackys e itens, porem o meu autoloot não pega o loot sozinho tem que abrir o bixo, gostaria que somente ao matar coletasse sozinho o loot.

  • 10 months later...
Postado

Pra quem ainda utiliza esse script venho trazer a solução para o erro tanto do GetSize quanto do Container.

 

O meu pensamento foi bem simples, eu sabia que o script estava funcionando quase "perfeitamente" se não fosse esse erro, eu testei inumeras vezes e não acontecia o erro, porém quando outras pessoas pelo mapa estavam caçando, as vezes aparecia.

Então eu tive que começar a pensar em identificar em que circunstância isso acontecia, então eu pensei na possibilidade de ser um monstro específico ou alguma característica.

Coloquei pra printar o monstro e o player toda vez que o autoloot fosse acionado e deu certo, descobri que quando as pessoas matavam por exemplo a Snake, que não tem como abrir, o script dava esse erro.

 

A solução foi o seguinte, 

 

 

Arquivo: creaturescripts/scripts/autoloot.lua

        local container = Container(corpse.uid)
	
		-- verificação se o corpo possui ou não container
        if not container then
              return
        end

 

Coloquei essa verificação para identificar se o monstro em questão possuia container antes de executar a função do autoloot.

 

Sendo assim, se ele identificar que o corpo não possui container (não da pra abrir) ele mata o script e não da o erro.

 

Espero que funcione pra vocês também!

 

Scripts final ficou assim:

 

local function scanContainer(cid, position)
    local player = Player(cid)
    if not player then
        return
    end

    local corpse = Tile(position):getTopDownItem()
    if not corpse then
        return
    end

    if corpse:getType():isCorpse() and corpse:getAttribute(ITEM_ATTRIBUTE_CORPSEOWNER) == cid then


        local container = Container(corpse.uid)

        if not container then
              return
        end

        for i = 0, container:getSize()-1 do
            local containerItem = container:getItem(i)
            if containerItem then
                for i = AUTOLOOT_STORAGE_START, AUTOLOOT_STORAGE_END do
                    if player:getStorageValue(i) == containerItem:getId() then
                        containerItem:moveTo(player)
                    end
                end
            end
        end
    end
end

function onKill(player, target)
    if not target:isMonster() then
        return true
    end

    addEvent(scanContainer, 100, player:getId(), target:getPosition())
    return true
end

 

 

Editado por tavares7 (veja o histórico de edições)

  • 1 year later...
Postado

Salve galera desculpa revier o topico mais estou com mesmo erro do cara ali de 2017, eu testei numa tfs1.5 do nekiro downgrades 8.60 
ele funciona tudo certinho adiciona na lista e remove e ver a lista porém ele não coleta o item e não aparece erro no log


Alguem pode ajudar

Participe da conversa

Você pode postar agora e se cadastrar mais tarde. Se você tem uma conta, faça o login para postar com sua conta.

Visitante
Responder

Quem Está Navegando 0

  • Nenhum usuário registrado visualizando esta página.

Conteúdo Similar

Estatísticas dos Fóruns

  • Tópicos 96.9k
  • Posts 519.6k

Informação Importante

Confirmação de Termo