adrianoswatt

AutoLoot MOD

Oct 21st, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XML 9.20 KB | None | 0 0
  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <mod name="Loot System" version="1.0" author="Vodkart, Mkalo and Adriano Swatt'" contact="none.com" enabled="yes">
  3.  
  4. <config name="Loot_func"><![CDATA[
  5. info = {
  6.     OnlyPremium = false,
  7.     AutomaticDeposit = true,
  8.     limitList = 10,
  9.     BlockMonsters = {},
  10.     BlockItemsList = {2123, 2515}
  11. }
  12.  
  13. function setPlayerStorageTable(cid, storage, tab)
  14.     local tabstr = "&"
  15.     for i, x in pairs(tab) do
  16.         tabstr = tabstr .. i .. "," .. x .. ";"
  17.     end
  18.     setPlayerStorageValue(cid, storage, tabstr:sub(1, #tabstr-1))
  19. end
  20.  
  21. function getPlayerStorageTable(cid, storage)
  22.    local tabstr = getPlayerStorageValue(cid, storage)
  23.    local tab = {}
  24.    if type(tabstr) ~= "string" then
  25.         return {}
  26.    end
  27.    if tabstr:sub(1,1) ~= "&" then
  28.         return {}
  29.    end
  30.    local tabstr = tabstr:sub(2, #tabstr)
  31.    local a = string.explode(tabstr, ";")
  32.    for i,x in pairs(a) do
  33.         local b = string.explode(x, ",")
  34.         tab[tonumber(b[1]) or b[1]] = tonumber(b[2]) or b[2]
  35.    end
  36.    return tab
  37. end
  38.  
  39.  
  40. function isInTable(cid, item)
  41.     for _,i in pairs(getPlayerStorageTable(cid, 27000))do
  42.         if tonumber(i) == tonumber(item) then
  43.             return true
  44.         end
  45.     end
  46. return false
  47. end
  48.  
  49. function addItemTable(cid, item)
  50.     local x = {}
  51.     getQtdd = getPlayerStorageTable(cid, 27000)
  52.     for i = 1, #getQtdd do
  53.         if #getQtdd < info.limitList then
  54.             table.insert(x, getQtdd[i])
  55.         else
  56.             doPlayerSendCancel(cid, "You have reached the limit from AutoLoot List ["..#getQtdd.."/"..info.limitList.."].")
  57.             return true
  58.         end
  59.     end
  60.     if x ~= 0 then
  61.         table.insert(x,tonumber(item))
  62.         setPlayerStorageTable(cid, 27000, x)
  63.     else
  64.         setPlayerStorageTable(cid, 27000, {item})
  65.     end
  66.     doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You added the "..getItemNameById(item).." from your AutoLoot List sucessfully.")
  67. end
  68.  
  69. function removeItemTable(cid, item)
  70.     local x = {}
  71.     for i = 1, #getPlayerStorageTable(cid, 27000) do
  72.         table.insert(x,getPlayerStorageTable(cid, 27000)[i])
  73.     end
  74.     for i, v in ipairs(x) do
  75.         if tonumber(v) == tonumber(item) then
  76.             table.remove(x,i)
  77.         end
  78.     end
  79.     doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "You removed the "..getItemNameById(item).." from your AutoLoot List sucessfully.")
  80.     return setPlayerStorageTable(cid, 27000, x)
  81. end
  82.  
  83. function ShowItemsTabble(cid)
  84.     local str, n = "-- My Loot List --\n\n",0
  85.     for i = 1, #getPlayerStorageTable(cid, 27000) do
  86.         n = n + 1
  87.         str = str..""..n.." - "..getItemNameById(getPlayerStorageTable(cid, 27000)[i]).."\n"
  88.     end
  89. return doShowTextDialog(cid, 2529, str)
  90. end
  91.  
  92. function getContainerItems(containeruid)
  93.     if not isContainer(containeruid) then
  94.         return true
  95.     end
  96.     local items = {}
  97.     local containers = {}
  98.         if type(getContainerSize(containeruid)) ~= "number" then
  99.         return false
  100.     end
  101.     for slot = 0, getContainerSize(containeruid)-1 do
  102.         local item = getContainerItem(containeruid, slot)
  103.         if item.itemid == 0 then
  104.             break
  105.         end
  106.         if isContainer(item.uid) then
  107.             table.insert(containers, item.uid)
  108.         end
  109.         table.insert(items, item)
  110.     end
  111.     if #containers > 0 then
  112.         for i, x in ipairs(getContainerItems(containers[1])) do
  113.             table.insert(items, x)
  114.         end
  115.         table.remove(containers, 1)
  116.     end
  117.     return items
  118. end
  119.  
  120. function getItemsInContainerById(container, itemid) -- Function By Kydrai
  121.     local items = {}
  122.     if isContainer(container) and getContainerSize(container) > 0 then
  123.         for slot = 0, (getContainerSize(container)-1) do
  124.             local item = getContainerItem(container, slot)
  125.             if isContainer(item.uid) then
  126.                 local itemsbag = getItemsInContainerById(item.uid, itemid)
  127.                 for i = 0, #itemsbag do
  128.                     table.insert(items, itemsbag[i])
  129.                 end
  130.             else
  131.                 if itemid == item.itemid then
  132.                     table.insert(items, item.uid)
  133.                 end
  134.             end
  135.         end
  136.     end
  137.     return items
  138. end
  139.  
  140. function doPlayerAddItemStacking(cid, itemid, quant) -- by Mkalo
  141.     local item = getItemsInContainerById(getPlayerSlotItem(cid, 3).uid, itemid)
  142.     local piles = 0
  143.     if #item > 0 then
  144.         for i, x in pairs(item) do
  145.             if getThing(x).type < 100 then
  146.                 local it = getThing(x)
  147.                 doTransformItem(it.uid, itemid, it.type+quant)
  148.                 if it.type+quant > 100 then
  149.                     doPlayerAddItem(cid, itemid, it.type+quant-100)
  150.                 end
  151.             else
  152.                 piles = piles+1
  153.             end
  154.         end
  155.     else
  156.         return doPlayerAddItem(cid, itemid, quant)
  157.     end
  158.     if piles == #item then
  159.         doPlayerAddItem(cid, itemid, quant)
  160.     end
  161. end
  162.  
  163. function AutomaticDeposit(cid, item, n)
  164. local deposit = item == tonumber(2160) and (n*10000) or tonumber(item) == 2152 and (n*100) or (n*1)
  165.     return doPlayerDepositMoney(cid, deposit)
  166. end
  167.  
  168. function corpseRetireItems(cid, corpseID, corpsePos) -- Aperfeiçoada por Adriano Swatt'
  169. pid = getPlayerByNameWildcard(cid)
  170.     if isPlayer(pid) then
  171.         checkCorpse = getTileItemById(corpsePos, corpseID)
  172.         if checkCorpse.uid > 0 and isContainer(checkCorpse.uid) then
  173.             local items = getContainerItems(checkCorpse.uid)
  174.             for i, x in pairs(items) do
  175.                 if isInArray(getPlayerStorageTable(pid, 27000), tonumber(x.itemid)) then
  176.                     if doRemoveItem(x.uid) then
  177.                         if isItemStackable(x.itemid) then
  178.                             doPlayerAddItemStacking(pid, x.itemid, x.type)
  179.                             if info.AutomaticDeposit == true and isInArray({"2148","2152","2160"}, tonumber(x.itemid)) then
  180.                                 AutomaticDeposit(pid, x.itemid, x.type)
  181.                                 if x.type == 1 then
  182.                                     doPlayerSendTextMessage(pid, MESSAGE_STATUS_CONSOLE_BLUE, ""..x.type.." gold coin was automatically transferred to the bank of your account by AutoLoot Script.")
  183.                                 else
  184.                                     doPlayerSendTextMessage(pid, MESSAGE_STATUS_CONSOLE_BLUE, ""..x.type.." gold coins were automatically transferred to the bank of your account by AutoLoot Script.")
  185.                                 end
  186.                             else
  187.                                 doPlayerSendTextMessage(pid, MESSAGE_STATUS_CONSOLE_BLUE, "You take "..x.type.." "..getItemNameById(x.itemid).." from AutoLoot script.")
  188.                             end
  189.                         else
  190.                             doPlayerAddItem(pid, x.itemid)
  191.                             doPlayerSendTextMessage(pid, MESSAGE_STATUS_CONSOLE_BLUE, "You take "..getItemNameById(x.itemid).." from AutoLoot script.")
  192.                         end
  193.                     end
  194.                 end
  195.             end
  196.         end
  197.     end
  198. end]]></config>
  199.  
  200. <event type="login" name="LootLogin" event="script"><![CDATA[
  201. function onLogin(cid)
  202.     registerCreatureEvent(cid, "MonsterAttack")
  203. return true
  204. end]]></event>
  205.  
  206. <event type="death" name="LootEventDeath" event="script"><![CDATA[
  207. domodlib('Loot_func')
  208. function onDeath(cid, corpse, deathList) -- Aperfeiçoada por Adriano Swatt'
  209.     if isCreature(cid) and isCreature(deathList[1]) then
  210.         local getMostDmgTab = {}
  211.         local getMostDmgCID = {}
  212.         local pos = getThingPos(cid)
  213.         local corpseID = corpse.itemid
  214.         for z = 1, #deathList do
  215.             killer = deathList[z]
  216.             if not isPlayer(killer) then       
  217.                 killer = getCreatureMaster(deathList[z])
  218.                 if isPlayer(killer) then
  219.                 else
  220.                     return true
  221.                 end
  222.             end
  223.             getOldExp = getPlayerStorageValue(killer, 25666)
  224.             resultExp = getPlayerExperience(killer) - getOldExp
  225.             if getMostDmgTab[1] ~= nil and resultExp >= getMostDmgTab[1] then
  226.                 table.insert(getMostDmgTab, 1, resultExp)
  227.                 table.insert(getMostDmgCID, 1, killer)
  228.             else
  229.                 table.insert(getMostDmgTab, resultExp)
  230.                 table.insert(getMostDmgCID, killer)
  231.             end
  232.             if z+1 > #deathList then -- FIM DA CHECAGEM DE MAIOR DANO
  233.                 addEvent(corpseRetireItems, 1, getCreatureName(getMostDmgCID[1]), corpseID, pos)
  234.             end
  235.         end
  236.     end
  237. return true
  238. end]]></event>
  239.  
  240. <event type="combat" name="MonsterAttack" event="script"><![CDATA[
  241. domodlib('Loot_func')
  242. if isPlayer(cid) and isMonster(target) and not isInArray(info.BlockMonsters,string.lower(getCreatureName(target))) then
  243.     setPlayerStorageValue(cid, 25666, getPlayerExperience(cid))
  244.     registerCreatureEvent(target, "LootEventDeath")
  245. end
  246. return true]]></event>
  247.  
  248. <talkaction words="!autoloot;/autoloot" event="buffer"><![CDATA[
  249. domodlib('Loot_func')
  250.     local t = string.explode(string.lower(param), ",")
  251.     if info.OnlyPremium == true and not isPremium(cid) then
  252.         doPlayerSendCancel(cid, "you must be a premium account.") return true
  253.     elseif not t[1] then
  254.         ShowItemsTabble(cid) return true
  255.     elseif tonumber(t[1]) or tonumber(t[2]) then
  256.         doPlayerSendCancel(cid, "Say !autoloot add, item name or !autoloot remove, item name") return true
  257.     elseif tostring(t[1]) == "add" then
  258.         local item = getItemIdByName(tostring(t[2]), false)
  259.         if not item then
  260.             doPlayerSendCancel(cid, "This item does not exist [Say !autoloot add, item name].") return true
  261.         elseif isInArray(info.BlockItemsList, item) then
  262.             doPlayerSendCancel(cid, "You can not add this item in the list!") return true
  263.         elseif isInTable(cid, item) then
  264.             doPlayerSendCancel(cid, "This item already in your list.") return true
  265.         end
  266.         addItemTable(cid, item)
  267.     elseif tostring(t[1]) == "remove" then
  268.         local item = getItemIdByName(tostring(t[2]), false)
  269.         if not item then
  270.             doPlayerSendCancel(cid, "This item does not exist [Say !autoloot remove, item name or !autoloot clean].") return true
  271.         elseif not isInTable(cid, item) then
  272.             doPlayerSendCancel(cid, "This item isn't in your list.") return true
  273.         end
  274.         removeItemTable(cid, item)
  275.     elseif tostring(t[1]) == "clean" then
  276.         setPlayerStorageValue(cid, 27000, -1)
  277.         doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "AutoLoot List cleaned sucessfully.") return true
  278.     end
  279. return true]]></talkaction>
  280. </mod>
Add Comment
Please, Sign In to add comment