[tfs1.x] AutoLoot System

kaleudd
em Globalevents e Spells

kaleudd

avatar
Conde
Conde

INFOS

Grupo: CondeRegistrado: 15/06/15Posts: 729

créditos:

Printer

 

 

imagens:

 

 

 

Zwo99Sdx.png

 

oG_cwli8u.png

 

 

 

 

Comandos:

!autoloot add, itemId or name -- Adicionando um item à lista
!autoloot remove, itemId or name -- Remoção de um item da lista
!autoloot show -- Mostrar a lista autoLoot
!autoloot clear -- Limpa a lista autoLoot

vá em data/global.lua e cole isso:

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

vá em talkactions/talkactions.xml e cole essa linha:

<talkaction words="!autoloot" separator=" " script="autoloot.lua"/>
Depois disso vá para vá em talkactions/scripts e crie uma nova lua e nomeie para autoloot.lua e cole este código:
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

agora,vá em creaturescripts/creaturescripts.xml e cole essa linha:

<event type="kill" name="AutoLoot" script="autoloot.lua" />
Depois disso vá para vá em creaturescripts/scripts e crie uma nova lua e nomeie para autoloot.lua e cole este código:
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 a = corpse:getSize() - 1, 0, -1 do
            local containerItem = corpse:getItem(a)
            if containerItem then
                for b = AUTOLOOT_STORAGE_START, AUTOLOOT_STORAGE_END do
                    if player:getStorageValue(b) == 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

agora vá em creaturescripts/scripts e abra login.lua e registre:

player:registerEvent("AutoLoot")

Administrador

xTibia 2017
avatar
Administrador
Administrador

INFOS

Grupo: AdministradorRegistrado: 09/07/05Posts: 5780Gênero: Outro

Já vi e usei esse sistema em um OT global, é muito legal hehe

DICA

Utilize botão @UP, no início de seu tópico, para atualizar o destaque de seu tópico em "Tópicos Recentes" na index, fará com que mais pessoas o vejam.

 

 

Lucas1504

avatar
Campones
Campones

INFOS

Grupo: CamponesRegistrado: 08/11/12Posts: 12Char no Tibia: Furiuz UPF

Meu servidor não tem o arquivo "global.lua"

dalvorsn

õ/
avatar
Conde
Conde

INFOS

Grupo: CondeRegistrado: 21/12/11Posts: 750Gênero: Masculino
9 hours ago, Lucas1504 said:

Meu servidor não tem o arquivo "global.lua"

Tem uma tag enorme bem no titulo dizendo: "[tfs1.x]".

 

"A covardia coloca a questão: É seguro? O comodismo coloca a questão: É popular? A etiqueta coloca a questão: é elegante? Mas a consciência coloca a questão, É correto? E chega uma altura em que temos de tomar uma posição que não é segura, não é elegante, não é popular, mas o temos de fazer porque a nossa consciência nos diz que é essa a atitude correta."

(Martin Luther King)

straydamian

avatar
Campones
Campones

INFOS

Grupo: CamponesRegistrado: 22/12/12Posts: 1


nice scrip, but i have a question




how I can do this just work in premium account?




 




 




Bom scrip, mas eu tenho uma pergunta




Como posso fazer isso apenas trabalho em conta premium?


Ninlin

avatar
Campones
Campones

INFOS

Grupo: CamponesRegistrado: 10/06/20Posts: 18

@kaleudd teira como fazer para que não funcione utilizando os comandos? Ex:estaria sempre ON e pegando todos os loots.