Guest User

Auto Loot - Kill Script

a guest
Feb 7th, 2017
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.30 KB | None | 0 0
  1. local tabela = {}
  2.  
  3. local function getPlayerList(cid)
  4.     local tab = {}
  5.     if getPlayerStorageValue(cid, 0442002) ~= -1 then
  6.         table.insert(tab, getPlayerStorageValue(cid, 0442002))
  7.     end
  8.     if getPlayerStorageValue(cid, 0442003) ~= -1 then
  9.         table.insert(tab, getPlayerStorageValue(cid, 0442003))
  10.     end
  11.     if getPlayerStorageValue(cid, 0442004) ~= -1 then
  12.         table.insert(tab, getPlayerStorageValue(cid, 0442004))
  13.     end
  14.     if getPlayerStorageValue(cid, 0442005) ~= -1 then
  15.         table.insert(tab, getPlayerStorageValue(cid, 0442005))
  16.     end
  17.     if #tab > 0 then
  18.         return tab
  19.     end
  20.     return false
  21. end
  22.  
  23. local function autoLoot(cid, pos)
  24.     local check = false
  25.     local str = ""
  26.     local position = {}
  27.     for i = 1, 255 do
  28.         pos.stackpos = i
  29.         if getThingFromPos(pos).uid and getThingFromPos(pos).uid > 0 and isContainer(getThingFromPos(pos).uid) then
  30.             position = pos
  31.             check = true
  32.             break
  33.         end
  34.     end
  35.     if check then
  36.         local corpse = getContainerItemsInfo(getThingFromPos(position).uid)        
  37.         if corpse then
  38.             for index, info in pairs(corpse) do
  39.                 if index < countTable(corpse) then
  40.                         if tonumber(info.uid) and tonumber(info.itemid) then
  41.                         if isContainer(info.uid) then
  42.                             local bag = getContainerItemsInfo(info.uid)
  43.                             for i = 1, countTable(bag) - 1 do
  44.                                 if isInArray(getPlayerList(cid), bag[i].itemid) then
  45.                                     if bag[i].quant > 1 then
  46.                                         doRemoveItem(bag[i].uid, bag[i].quant)
  47.                                         doPlayerAddItem(cid, bag[i].itemid, bag[i].quant)
  48.                                         str = str.." "..bag[i].quant.." "..getItemNameById(bag[i].itemid)..","
  49.                                     else
  50.                                         doRemoveItem(bag[i].uid)
  51.                                         doPlayerAddItem(cid, bag[i].itemid, 1)
  52.                                         str = str.." 1 "..getItemNameById(bag[i].itemid)..","
  53.                                     end
  54.                                 end
  55.                             end
  56.                         end
  57.                     end
  58.                 end
  59.                 if isInArray(getPlayerList(cid), info.itemid) then
  60.                     if info.quant > 1 then
  61.                         doRemoveItem(info.uid, info.quant)
  62.                         doPlayerAddItem(cid, info.itemid, info.quant)
  63.                         str = str.." "..info.quant.." "..getItemNameById(info.itemid)..","
  64.                     else
  65.                         doRemoveItem(info.uid)
  66.                         doPlayerAddItem(cid, info.itemid, 1)
  67.                         str = str.." 1 "..getItemNameById(info.itemid)..","
  68.                     end
  69.                 end
  70.             end
  71.         end
  72.     end
  73.     tabela[getCreatureName(cid)] = {item = "[Auto Loot System] Coletados: "..str, gold = 0}
  74. end
  75.  
  76. local function autoGold(cid, pos)
  77.     local check = false
  78.     local total = 0
  79.     local position = {}
  80.     for i = 1, 255 do
  81.         pos.stackpos = i
  82.         if getThingFromPos(pos).uid and getThingFromPos(pos).uid > 0 and isContainer(getThingFromPos(pos).uid) then
  83.             position = pos
  84.             check = true
  85.             break
  86.         end
  87.     end
  88.     if check then
  89.         local corpse = getContainerItemsInfo(getThingFromPos(position).uid)
  90.         if corpse then
  91.             for index, info in pairs(corpse) do
  92.                 if info.uid and info.itemid then
  93.                     if index < countTable(corpse) then
  94.                         if isContainer(info.uid) then
  95.                             local bag = getContainerItemsInfo(info.uid)
  96.                             for i = 1, countTable(bag) - 1 do
  97.                                 if isInArray({2148, 2152, 2160}, bag[i].itemid) then
  98.                                     local multiplie = 1
  99.                                     if bag[i].itemid == 2148 then
  100.                                         multiplie = 1
  101.                                     elseif bag[i].itemid == 2152 then
  102.                                         multiplie = 100
  103.                                     elseif bag[i].itemid == 2160 then
  104.                                         multiplie = 10000
  105.                                     end
  106.                                     doRemoveItem(bag[i].uid, bag[i].quant)
  107.                                     doPlayerSetBalance(cid, getPlayerBalance(cid) + (tonumber(bag[i].quant) and tonumber(bag[i].quant) * multiplie or 0))
  108.                                     total = total + (tonumber(bag[i].quant) and tonumber(bag[i].quant) * multiplie or 0)
  109.                                     doPlayerSetStorageValue(cid, 0442102, getPlayerStorageZero(cid, 0442102) + (tonumber(bag[i].quant) and tonumber(bag[i].quant) * multiplie or 0))
  110.                                 end
  111.                             end
  112.                         end
  113.                     end
  114.                     if isInArray({2148, 2152, 2160}, info.itemid) then
  115.                         local multiplie = 1
  116.                         if info.itemid == 2148 then
  117.                             multiplie = 1
  118.                         elseif info.itemid == 2152 then
  119.                             multiplie = 100
  120.                         elseif info.itemid == 2160 then
  121.                             multiplie = 10000
  122.                         end
  123.     doRemoveItem(info.uid, info.quant)
  124.                         doPlayerSetBalance(cid, getPlayerBalance(cid) + (tonumber(info.quant) and tonumber(info.quant) * tonumber(multiplie) or 0))
  125.                         doPlayerSetStorageValue(cid, 0442102, getPlayerStorageZero(cid, 0442102) + (tonumber(info.quant) and tonumber(info.quant) * tonumber(multiplie) or 0))
  126.                         total = total + (tonumber(info.quant) and tonumber(info.quant) * multiplie or 0)
  127.                     end
  128.                 end
  129.             end
  130.         end
  131.     end
  132.     if tabela[getCreatureName(cid)] and tabela[getCreatureName(cid)].gold then
  133.         tabela[getCreatureName(cid)].gold = total
  134.     end
  135. end
  136.  
  137. local function sendMsg(cid)
  138.     if tabela[getCreatureName(cid)] and tabela[getCreatureName(cid)].gold then
  139.         if tabela[getCreatureName(cid)].gold == 0 then
  140.             doPlayerSendTextMessage(cid, 23, tabela[getCreatureName(cid)].item)
  141.         else
  142.             doPlayerSendTextMessage(cid, 23, tabela[getCreatureName(cid)].item.." "..tabela[getCreatureName(cid)].gold.." gold coins.")
  143.         end
  144.         tabela[getCreatureName(cid)] = nil
  145.     end
  146. end
  147.  
  148. function onKill(cid, target, lastHit)
  149.     if isPlayer(cid) and isMonster(target) then
  150.         if getPlayerStorageValue(cid, 0442100) == 1 and getPlayerList(cid) then
  151.             local pos = getCreaturePosition(target)
  152.             addEvent(autoLoot, 500, cid, pos)
  153.         end
  154.         if getPlayerStorageValue(cid, 0442101) == 1 then
  155.             local pos = getCreaturePosition(target)
  156.             addEvent(autoGold, 500, cid, pos)
  157.         end
  158.         if getPlayerStorageValue(cid, 0442100) == 1 or getPlayerStorageValue(cid, 0442101) == 1 then
  159.             addEvent(sendMsg, 540, cid)
  160.         end
  161.     end
  162.     return true
  163. end
Add Comment
Please, Sign In to add comment