Advertisement
Nysman

Untitled

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