Advertisement
VodkartTK

TFS Autoloot onDeath

Oct 12th, 2020 (edited)
2,890
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XML 14.49 KB | None | 0 0
  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <mod name="Perfect Auto Loot" version="1.0" author="Vodkart" contact="none.com" enabled="yes">
  3. <config name="Loot_func"><![CDATA[
  4.  
  5.  
  6. info = {
  7.    distro = 1, -- 1 = TFS // 2 = talk modificada
  8.     directory = "data/logs/autoloot",
  9.     Warn_Bp_Slots = 5, -- quando tiver 5 ou menos slots na BP vai avisar o jogador
  10.     Talkaction_delay = 5, -- em segundos // delay para remover e adicionar item
  11.     BlockMonsters = {},
  12.     BlockItemsList = {2123,2515},
  13.     Money_ids = {2148, 2152, 2160}, -- id das moedas do ot
  14.     Max_Slots = {free = 3, premium = 5},
  15.     Storages = {988801, 988802, 988803, 988804, 988805, 988806, 988807}
  16. }
  17.  
  18. Color_Loot = {
  19.           [0] = {MESSAGE_EVENT_ORANGE, "Orange"},
  20.           [1] = {MESSAGE_STATUS_CONSOLE_BLUE, "Blue"},
  21.           [2] = {MESSAGE_INFO_DESCR, "Green"},
  22.           [3] = {MESSAGE_STATUS_CONSOLE_RED, "Red"},
  23.           [4] = {MESSAGE_STATUS_SMALL, "White"}
  24. }
  25.  
  26.  
  27. function getPlayerColorLootMessage(cid)
  28.     return getPlayerStorageValue(cid, info.Storages[5]) <= 0 and 0 or getPlayerStorageValue(cid, info.Storages[5])
  29. end
  30. function isInTable(cid, item)
  31.     for _,i in pairs(getItensFromAutoloot(cid)) do
  32.         if tonumber(i) == tonumber(item) then
  33.             return true
  34.         end
  35.     end
  36.     return false
  37. end
  38. function doremoveItemFromAutoloot(cid, itemid)
  39.    local file, fileContent = io.open(info.directory.."/"..getCreatureName(cid)..".txt", 'r'),{}
  40.    for line in file:lines() do
  41.      if line ~= "" and tonumber(line) ~= tonumber(itemid) then
  42.             fileContent[#fileContent + 1] = line
  43.         end
  44.    end
  45.    io.close(file)
  46.    file = io.open(info.directory.."/"..getCreatureName(cid)..".txt", 'w')
  47.    for index, value in ipairs(fileContent) do
  48.    file:write(value..'\n')
  49.    end
  50.    io.close(file)
  51. end
  52. function doAddItemFromAutoloot(cid, itemid)
  53.         if not existsAutoloot(cid) then
  54.            doCreateLootUserName(cid, itemid) return true
  55.         end
  56.          local file = io.open(info.directory.."/"..getCreatureName(cid)..".txt", "a+")                         
  57.         file:write('\n'..itemid)
  58.         file:close()
  59. end
  60. function existsAutoloot(cid)
  61.  local f = io.open(info.directory.."/"..getCreatureName(cid)..".txt", "rb")
  62.  if f then f:close() end
  63.  return f ~= nil
  64. end
  65. function doCreateLootUserName(cid, itemid)
  66.    newFile = io.open(info.directory.."/"..getCreatureName(cid)..".txt", "w+" )
  67.    newFile:write(itemid)
  68.    newFile:close()
  69. end
  70. function getItensFromAutoloot(cid)
  71.  if not existsAutoloot(cid) then return {} end
  72.  lines = {}
  73.  for line in io.lines(info.directory.."/"..getCreatureName(cid)..".txt") do
  74.       if line ~= "" then
  75.             lines[#lines + 1] = tonumber(line)
  76.       end
  77.  end
  78.  return lines
  79. end
  80. function doCleanAutoloot(cid)
  81. return os.remove(info.directory.."/"..getCreatureName(cid)..".txt")
  82. end
  83. function ShowItemsTabble(cid)
  84.     local auto_list = getItensFromAutoloot(cid)
  85.     local n,str = 0,"[+] Auto Loot Commands [+]\n\n!autoloot item name --> To add ou Remove item from list.\n!autoloot money --> To collect gold automatically.\n!autoloot clear --> To clear the list.\n!autoloot on/off --> To enable or disable the collecting of items in the system.\n!autoloot message --> To enable or disable message from Collect items.\n!autoloot color --> To change Color message in Auto Loot Collect.\n!autoloot warn --> To enable or disable message warning of "..info.Warn_Bp_Slots.." or less slots in the backpack.\n!autoloot deposit --> To enable or disable automatic money deposit at the bank.\n\n[+] Auto Loot Info [+]\n\nSystem: "..(getPlayerStorageValue(cid, info.Storages[1]) <= 0 and "Activated" or "Disabled")..".\nGold Collecting: "..(getPlayerStorageValue(cid, info.Storages[2]) > 0 and "Activated" or "Disabled")..".\nMessage: "..(getPlayerStorageValue(cid, info.Storages[6]) <= 0 and "Activated" or "Disabled")..".\nColor Message: "..Color_Loot[getPlayerColorLootMessage(cid)][2]..".\nWarn Backpack: "..(getPlayerStorageValue(cid, info.Storages[3]) <= 0 and "Activated" or "Disabled")..".\nAutomatic Gold Deposit: "..(getPlayerStorageValue(cid, info.Storages[4]) > 0 and "Activated" or "Disabled")..".\nTotal Bank Balance: ["..getPlayerBalance(cid).."]\nMaximum Slots: ["..#auto_list.."/"..(isPremium(cid) and info.Max_Slots.premium or info.Max_Slots.free).."]\n\n[+] Auto Loot Slots [+]\n\n"
  86.     if #auto_list > 0 then
  87.         for i = 1, #auto_list do
  88.             n = n + 1
  89.             str = str.."Slot "..n.." - "..getItemNameById(auto_list[i]).."\n"
  90.         end
  91.     end
  92.     return doPlayerPopupFYI(cid, str)
  93. end
  94. function getContainerItems(container, array, haveCap)
  95.    array = array or {}
  96.    haveCap = haveCap or false
  97.    if not isContainer(container.uid) or getContainerSize(container.uid) == 0 then
  98.        array[#array +1] = container
  99.    else
  100.        local size = getContainerSize(container.uid)
  101.        haveCap = (getContainerCap(container.uid) -size) > 0
  102.        for slot = 0, (size -1) do
  103.            local item = getContainerItem(container.uid, slot)
  104.            if item.itemid > 1 then
  105.                getContainerItems(item, array, haveCap)
  106.            end
  107.        end
  108.    end
  109.    return #array >= 1 and array, haveCap
  110. end
  111. function getContainerItemsById(container, itemid)
  112.    local founds = {}
  113.    local items = not container.uid and container or getContainerItems(container)
  114.    for index, item in pairs(items) do
  115.        if item.itemid == itemid then
  116.            founds[#founds +1] = item
  117.        end
  118.    end
  119.    return #founds >= 1 and founds
  120. end
  121. function AutomaticDeposit(cid, item, n)
  122.     local deposit = item == tonumber(2160) and (n*10000) or tonumber(item) == 2152 and (n*100) or (n)
  123.     return doPlayerDepositMoney(cid, deposit)
  124. end
  125. function getAllContainerFree(container) -- by vodka
  126.     local containers,soma = {},0
  127.     for i = 0, getContainerSize(container)-1 do
  128.         local item = getContainerItem(container, i)
  129.         if isContainer(item.uid) then
  130.             table.insert(containers, item.uid)
  131.         end
  132.     end
  133.     for _, check in pairs(containers) do
  134.         soma = soma + getContainerSlotsFree(check) 
  135.     end
  136.     return (soma + getContainerSlotsFree(container))
  137. end
  138. function getContainerSlotsFree(container) -- by vodka
  139.         return getContainerCap(container)-getContainerSize(container)
  140. end
  141. function doPlayerAddItemStackable(cid, itemid, count)
  142.    local container = getPlayerSlotItem(cid, CONST_SLOT_BACKPACK)
  143.    if container.itemid > 1 then
  144.        local items = getContainerItemsById(container, itemid)
  145.        if not items then
  146.            return doPlayerAddItem(cid, itemid, count)
  147.        else
  148.            local piles = #items
  149.            for index, item in pairs(items) do
  150.                if item.type < 100 then
  151.                    local sum = item.type + count
  152.                    local result = doTransformItem(item.uid, itemid, sum)
  153.                    if sum <= 100 then
  154.                        return result
  155.                    else
  156.                        return doPlayerAddItem(cid, itemid, sum - 100)
  157.                    end
  158.                else
  159.                    piles = piles - 1
  160.                    if piles == 0 then
  161.                        return doPlayerAddItem(cid, itemid, count)
  162.                    end
  163.                end
  164.            end
  165.        end
  166.    end
  167.    return false
  168. end
  169. function corpseRetireItems(cid, pos)
  170.     local check, slots = false, 0
  171.     for i = 0, 255 do
  172.         pos.stackpos = i
  173.         tile = getTileThingByPos(pos)
  174.         if tile.uid > 0 and isCorpse(tile.uid) then
  175.             check = true break
  176.         end
  177.     end
  178.     if check == true then
  179.         local str, var = "", getContainerItems(tile)
  180.         if var then
  181.             local list = getItensFromAutoloot(cid)
  182.             for _, item in pairs(var) do
  183.                 local id = item.itemid
  184.                 if #list > 0 and isInArray(list, id) or getPlayerStorageValue(cid, info.Storages[2]) > 0 and isInArray(info.Money_ids, id) then
  185.                     local info = getItemInfo(id)
  186.                     local amount = isItemStackable(id) and item.type or 1
  187.                     local total_cap = getItemWeight(item.uid)*amount
  188.                     if getPlayerSlotItem(cid, 3).itemid ~= 0 then
  189.                         slots = getAllContainerFree(getPlayerSlotItem(cid, 3).uid)
  190.                     end
  191.                     if slots > 0 and getPlayerFreeCap(cid) >= total_cap then
  192.                         if isItemStackable(id) then
  193.                             str = str.." "..amount.." "..(amount > 1 and info.plural or info.name)..","
  194.                             doPlayerAddItemStackable(cid, id, amount)
  195.                             if isInArray(info.Money_ids, id) and getPlayerStorageValue(cid, info.Storages[4]) > 0 then
  196.                                 AutomaticDeposit(cid, id, amount)
  197.                             end
  198.                         else
  199.                             str = str.." ".. info.article.." " .. info.name ..","
  200.                             doPlayerAddItem(cid, id)
  201.                         end
  202.                         doRemoveItem(item.uid) 
  203.                     end
  204.                 end
  205.             end
  206.             if str ~= "" and getPlayerStorageValue(cid, info.Storages[6]) <= 0 then
  207.                 doPlayerSendTextMessage(cid, Color_Loot[getPlayerColorLootMessage(cid)][1],"[Auto Loot Collect]:"..string.sub(str, 1, -2)..".")
  208.             end
  209.             if getPlayerStorageValue(cid, info.Storages[3]) <= 0 and slots > 0 and slots <= info.Warn_Bp_Slots then
  210.                 doPlayerSendTextMessage(cid,18,"[Auto Loot Warn] You only have "..slots.." slots free in your backpack!")
  211.             end
  212.         end
  213.     end
  214. end
  215. function ExistItemByName(name) -- by vodka
  216.    local items = io.open("data/items/items.xml", "r"):read("*all")
  217.    local get = items:lower():match('name="' .. name:lower() ..'"')
  218.    if get == nil or get == "" then
  219.        return false
  220.    end
  221. return true
  222. end
  223. ]]></config>
  224. <event type="login" name="LootLogin" event="script"><![CDATA[
  225. domodlib('Loot_func')
  226. function onLogin(cid)
  227.     registerCreatureEvent(cid, "RegisterMonsterAutoloot")
  228.     if isPremium(cid) and getPlayerStorageValue(cid, 853608) <= 0 then
  229.         setPlayerStorageValue(cid, 853608, 1)
  230.     elseif getPlayerStorageValue(cid, 853608) > 0 and not isPremium(cid) then
  231.         doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "[Auto Loot] You premium is Over, Start a new list!")
  232.         setPlayerStorageValue(cid, 853608, -1)
  233.         doCleanAutoloot(cid)
  234.     end
  235.     return true
  236. end]]></event>
  237. <event type="combat" name="RegisterMonsterAutoloot" event="script"><![CDATA[
  238. domodlib('Loot_func')
  239. if isPlayer(cid) and isMonster(target) and not isInArray(info.BlockMonsters, getCreatureName(target):lower()) then
  240.     registerCreatureEvent(target, "LootEventKIll")
  241. end
  242. return true
  243. ]]></event>
  244. <event type="death" name="LootEventKIll" event="script"><![CDATA[
  245. domodlib('Loot_func')
  246. function onDeath(cid, corpse, deathList)
  247.     if isMonster(cid) and isPlayer(deathList[1]) and getPlayerStorageValue(deathList[1], info.Storages[1]) <= 0 then   
  248.             addEvent(corpseRetireItems, 0, deathList[1] , getThingPos(cid))
  249.     end
  250.     return true
  251. end]]></event>
  252. <talkaction words="!autoloot;/autoloot" event="buffer"><![CDATA[
  253. domodlib('Loot_func')
  254. local param, slots = param:lower(), isPremium(cid) and info.Max_Slots.premium or info.Max_Slots.free
  255. if not param or param == "" then
  256.     ShowItemsTabble(cid) return true
  257. elseif tonumber(param) then
  258.     doPlayerSendCancel(cid, "enter commands: !autoloot item name [+] !autoloot clean [+] !autoloot money [+] !autoloot on/off") return true
  259. elseif isInArray({"clean","limpar", "clear"}, param) then
  260.     if existsAutoloot(cid) then doCleanAutoloot(cid) end
  261.     doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE,"[Auto Loot] Your list has been cleaned.") return true
  262. elseif isInArray({"start","stop","on","off"}, param) then
  263.     setPlayerStorageValue(cid, info.Storages[1], getPlayerStorageValue(cid, info.Storages[1]) <= 0 and 1 or 0)
  264.     doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE,"Auto Loot "..(getPlayerStorageValue(cid, info.Storages[1]) > 0 and "Stopped" or "Started")..".") return true
  265. elseif isInArray({"warn","aviso"}, param) then
  266.     setPlayerStorageValue(cid, info.Storages[3], getPlayerStorageValue(cid, info.Storages[3]) <= 0 and 1 or 0)
  267.     doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE,"Auto Loot Backpack Warn "..(getPlayerStorageValue(cid, info.Storages[3]) > 0 and "disabled" or "Activated")..".") return true
  268. elseif isInArray({"mensagem","message","mensagen","msg"}, param) then
  269.     setPlayerStorageValue(cid, info.Storages[6], getPlayerStorageValue(cid, info.Storages[6]) <= 0 and 1 or 0)
  270.     doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE,"Auto Loot Message "..(getPlayerStorageValue(cid, info.Storages[6]) > 0 and "disabled" or "Activated")..".") return true
  271. elseif isInArray({"cor","color","type"}, param) then
  272.     setPlayerStorageValue(cid, info.Storages[5], getPlayerColorLootMessage(cid) == #Color_Loot and 0 or getPlayerColorLootMessage(cid)+1)
  273.     doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE,"Auto Loot Message Color Changed to "..Color_Loot[getPlayerColorLootMessage(cid)][2]..".") return true
  274. elseif isInArray({"money","gold","gps","dinheiro"}, param) then
  275.     setPlayerStorageValue(cid, info.Storages[2], getPlayerStorageValue(cid, info.Storages[2]) <= 0 and 1 or 0)
  276.     doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE,"Auto Loot Gold Colleting "..(getPlayerStorageValue(cid, info.Storages[2]) > 0 and "Activated" or "disabled")..".") return true
  277. elseif isInArray({"deposito","bank","gbank","deposit","autodeposit"}, param) then
  278.     setPlayerStorageValue(cid, info.Storages[4], getPlayerStorageValue(cid, info.Storages[4]) <= 0 and 1 or 0)
  279.     doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE,"[Auto Loot] Automatic Gold Bank "..(getPlayerStorageValue(cid, info.Storages[4]) > 0 and "Activated" or "disabled")..".") return true
  280. end
  281. if info.distro ~= 1 then
  282.     item = ExistItemByName(tostring(param))
  283.     if not item then
  284.         doPlayerSendCancel(cid, "This item does not exist.") return true
  285.     end
  286.     item = getItemIdByName(tostring(param))
  287. else
  288.     item = getItemIdByName(param, false)
  289.     if not item then
  290.         doPlayerSendCancel(cid, "This item does not exist.") return true
  291.     end
  292. end
  293. local var = isInTable(cid, item)
  294. if isInArray(info.Money_ids, item) then
  295.     doPlayerSendTextMessage(cid, MESSAGE_FIRST, "Enter !autoloot money to add money in your list!") return true
  296. elseif isInArray(info.BlockItemsList, item) then
  297.     doPlayerSendCancel(cid, "You can not add this item in the list!") return true
  298. elseif not var and #getItensFromAutoloot(cid) >= slots then
  299.     doPlayerSendCancel(cid, "max "..slots.." from auto loot") return true
  300. elseif getPlayerStorageValue(cid, info.Storages[7]) - os.time() > 0 then
  301.         doPlayerSendCancel(cid, "wait a second to use this command again") return true
  302. end
  303. if not var then
  304.     doAddItemFromAutoloot(cid, item)
  305. else
  306.     doremoveItemFromAutoloot(cid, item)
  307. end
  308. setPlayerStorageValue(cid, info.Storages[7], os.time()+info.Talkaction_delay)
  309. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE,not var and "you added the item "..param.." in the list" or "you removed the item "..param.." from the list, please wait 5 seconds to save the directory.")
  310. return true]]></talkaction>
  311. </mod>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement