Advertisement
Guest User

Untitled

a guest
Nov 4th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.22 KB | None | 0 0
  1. function call(player, param, param2, tobpid)
  2. player:registerEvent('autoloot')
  3. local title = "Autoloot Helper!"
  4. if param == 'add' then
  5. local lootBlockList = lootBlockListm[player:getGuid()]
  6. local message = "Loots of "..string.gsub(" "..string.lower(lootBlockListn[player:getGuid()]), "%W%l", string.upper):sub(2)..":"
  7. local window = ModalWindow(1001, title, message)
  8. local check, sum = {}, 1
  9. for _, loot in pairs(lootBlockList) do
  10. local status = ''
  11. if player:getAutoLootItem(lootBlockList[sum].itemId) then
  12. status = '*'
  13. end
  14. if not table.contains(check, ItemType(lootBlockList[sum].itemId):getName()) then
  15. table.insert(check, ItemType(lootBlockList[sum].itemId):getName())
  16. local resultId = db.storeQuery('SELECT `cont_id` FROM `player_autoloot_persist` WHERE `player_guid` = ' .. player:getGuid() .. ' AND `item_id` = ' .. lootBlockList[sum].itemId .. '')
  17. if resultId then
  18. local bp_id = result.getNumber(resultId, 'cont_id')
  19. end
  20. local backvinculo
  21. if result.getNumber(resultId, 'cont_id') and result.getNumber(resultId, 'cont_id') > 0 then
  22. backvinculo = '| '..ItemType(result.getNumber(resultId, 'cont_id')):getName()..''
  23. else
  24. backvinculo = ''
  25. end
  26. window:addChoice(sum, "".. string.gsub(" "..status..""..ItemType(lootBlockList[sum].itemId):getName(), "%W%l", string.upper):sub(2, 21) .." | "..lootBlockList[sum].maxCount.." | "..(lootBlockList[sum].chance/1000).."% "..string.gsub(" "..string.lower(backvinculo), "%W%l", string.upper):sub(2).."")
  27. end
  28. sum = sum + 1
  29. end
  30. if autolootBP == 1 then
  31. window:addButton(105, "Backpack")
  32. end
  33. callwindow(window, player, 1)
  34. elseif param == 'remove' then
  35. local message = "You are currently looting the following items:"
  36. local window = ModalWindow(1000, title, message)
  37. local check, sum = player:getAutoLootList(), 1
  38. if check then
  39. table.sort(check, function(a, b) return ItemType(a):getName() < ItemType(b):getName() end)
  40. for _, item in ipairs(check) do
  41. local resultId = db.storeQuery('SELECT `cont_id` FROM `player_autoloot_persist` WHERE `player_guid` = ' .. player:getGuid() .. ' AND `item_id` = ' .. ItemType(check[sum]):getId() .. '')
  42. if resultId then
  43. local bp_id = result.getNumber(resultId, 'cont_id')
  44. end
  45. local backvinculo
  46. if result.getNumber(resultId, 'cont_id') and result.getNumber(resultId, 'cont_id') > 0 then
  47. backvinculo = '| '..ItemType(result.getNumber(resultId, 'cont_id')):getName()..''
  48. else
  49. backvinculo = ''
  50. end
  51. window:addChoice(sum, "".. string.gsub(" "..(ItemType(item)):getName(), "%W%l", string.upper):sub(2, 21) .." "..string.gsub(" "..string.lower(backvinculo), "%W%l", string.upper):sub(2).."")
  52. sum = sum + 1
  53. end
  54. else
  55. player:sendCancelMessage("The list is empty.")
  56. return false
  57. end
  58. if autolootBP == 1 then
  59. window:addButton(106, "Backpack")
  60. end
  61. callwindow(window, player, 2)
  62. elseif param == 'backpack' then
  63. local lootBlockList = lootBlockListm[player:getGuid()]
  64.  
  65. local modalcode
  66. if param2 and param2 == 1001 then
  67. modalcode = 1005
  68. else
  69. modalcode = 1006
  70. end
  71. local message = "Choose a Backpack:"
  72. local window = ModalWindow(modalcode, title, message)
  73. local sum = 1
  74. local container, names = {}, {}
  75. if getContainerSize(getPlayerSlotItem(player, CONST_SLOT_BACKPACK).uid) then
  76. for i = 0, getContainerSize(getPlayerSlotItem(player, CONST_SLOT_BACKPACK).uid) do
  77. local thing = getContainerItem(getPlayerSlotItem(player, CONST_SLOT_BACKPACK).uid, i)
  78. container[i] = getContainerItem(getPlayerSlotItem(player, CONST_SLOT_BACKPACK).uid, i)
  79. if isContainer(container[i].uid) then
  80. if not table.contains(names, container[i].itemId) then
  81. table.insert(names, container[i].itemId)
  82. window:addChoice(sum, ""..string.gsub(" "..string.lower(ItemType(container[i].itemid):getName()), "%W%l", string.upper):sub(2).."")
  83. end
  84. sum = sum + 1
  85. end
  86. end
  87. else
  88. player:sendCancelMessage("Not find main backpack.")
  89. return false
  90. end
  91. if sum == 1 then
  92. player:sendCancelMessage("Not find sub-backpacks.")
  93. return false
  94. end
  95. callwindow(window, player, 3)
  96. end
  97. end
  98.  
  99. function callwindow(window, player, param)
  100. if param == 3 then
  101. window:setDefaultEnterButton(100, "Confirm")
  102. window:addButton(100, "Confirm")
  103. else
  104. window:addButton(100, "Confirm")
  105. window:addButton(102, "Remove")
  106. window:setDefaultEnterButton(106, "Backpack")
  107. if param == 1 then
  108. window:addButton(103, "Add")
  109. window:setDefaultEnterButton(103, "Add")
  110. window:addButton(105, "Backpack")
  111. end
  112. end
  113. window:sendToPlayer(player)
  114. end
  115.  
  116. local creatureevent = CreatureEvent("autoloot")
  117.  
  118. function creatureevent.onModalWindow(player, modalWindowId, buttonId, choiceId)
  119. player:unregisterEvent('autoloot')
  120. local limiteAutoloot = 100
  121. local autolootlist, sum = {}, 1
  122. if buttonId == 102 and modalWindowId == 1000 then
  123. local playerlist = player:getAutoLootList()
  124. if playerlist then
  125. table.sort(playerlist, function(a, b) return ItemType(a):getName() < ItemType(b):getName() end)
  126. for _, item in ipairs(playerlist) do
  127. table.insert(autolootlist, "".. item .."")
  128. end
  129. local itemType = ItemType(tonumber(autolootlist[choiceId]))
  130. player:sendTextMessage(MESSAGE_INFO_DESCR,'Removed '.. string.gsub(" "..ItemType(tonumber(autolootlist[choiceId])):getName(), "%W%l", string.upper):sub(2, 21)..' from autoloot list!')
  131. db.query('DELETE FROM `player_autoloot_persist` WHERE `player_guid` = ' .. player:getGuid() .. ' AND `item_id` = ' .. itemType:getId() .. '')
  132. player:removeAutoLootItem(itemType:getId())
  133. call(player, 'remove')
  134. end
  135. elseif buttonId == 102 and modalWindowId == 1001 or buttonId == 103 then
  136. local lootBlockList = lootBlockListm[player:getGuid()]
  137. if lootBlockList == nil or lootBlockList == -1 then
  138. return false
  139. end
  140. for _, loot in pairs(lootBlockList) do
  141. table.insert(autolootlist, lootBlockList[sum].itemId)
  142. sum = sum + 1
  143. end
  144. local itemType = ItemType(tonumber(autolootlist[choiceId]))
  145. if buttonId == 102 then
  146. player:sendTextMessage(MESSAGE_INFO_DESCR,'Removed '.. string.gsub(" "..ItemType(itemType:getId()):getName(), "%W%l", string.upper):sub(2, 21)..' from autoloot list!')
  147. db.query('DELETE FROM `player_autoloot_persist` WHERE `player_guid` = ' .. player:getGuid() .. ' AND `item_id` = ' .. itemType:getId() .. '')
  148. player:removeAutoLootItem(itemType:getId())
  149. elseif buttonId == 103 then
  150. if player:getAutoLootList() then
  151. local playerlist = player:getAutoLootList()
  152. end
  153. if playerlist then
  154. for _, item in ipairs(playerlist) do
  155. table.insert(autolootlist, "".. item .."")
  156. end
  157. end
  158. if playerlist and #playerlist >= limiteAutoloot then
  159. player:sendCancelMessage("Reached the limit <"..#playerlist..">for itens, first remove using !autoloot or !add <monster>, selecting option remove.")
  160. return false
  161. else
  162. player:sendTextMessage(MESSAGE_INFO_DESCR,'Add '.. string.gsub(" "..ItemType(lootBlockList[choiceId].itemId):getName(), "%W%l", string.upper):sub(2, 21) ..' to autoloot list!')
  163. player:addAutoLootItem(itemType:getId())
  164. end
  165. end
  166. call(player, 'add')
  167. elseif buttonId == 105 then
  168. local lootBlockList = lootBlockListm[player:getGuid()]
  169. if lootBlockList == nil or lootBlockList == -1 then
  170. return false
  171. end
  172. for _, loot in pairs(lootBlockList) do
  173. table.insert(autolootlist, lootBlockList[sum].itemId)
  174. sum = sum + 1
  175. end
  176. local itemType = ItemType(tonumber(autolootlist[choiceId]))
  177. lastitem[player:getGuid()] = lootBlockList[choiceId].itemId
  178. call(player, 'backpack', modalWindowId, lastitem[player:getGuid()])
  179. elseif buttonId == 106 then
  180. local lootBlockList = player:getAutoLootList()
  181. table.sort(lootBlockList, function(a, b) return ItemType(a):getName() < ItemType(b):getName() end)
  182. if lootBlockList == nil or lootBlockList == -1 then
  183. return false
  184. end
  185. for _, loot in pairs(lootBlockList) do
  186. table.insert(autolootlist, lootBlockList[sum])
  187. sum = sum + 1
  188. end
  189. local itemType = ItemType(tonumber(autolootlist[choiceId]))
  190. lastitem[player:getGuid()] = lootBlockList[choiceId]
  191. call(player, 'backpack', modalWindowId, lastitem[player:getGuid()])
  192. elseif buttonId == 100 then
  193. if modalWindowId == 1005 then
  194. local container, bp, sequencer = {}, {}, 1
  195. local bp2 = {}
  196. for i = 0, getContainerSize(getPlayerSlotItem(player, CONST_SLOT_BACKPACK).uid) do
  197. local thing = getContainerItem(getPlayerSlotItem(player, CONST_SLOT_BACKPACK).uid, i)
  198. container[i] = getContainerItem(getPlayerSlotItem(player, CONST_SLOT_BACKPACK).uid, i)
  199. if isContainer(container[i].uid) then
  200. itemtester = Item(container[i].uid)
  201. bp[sequencer] = itemtester
  202. bp2[sequencer] = itemtester:getId()
  203. sequencer = sequencer + 1
  204. end
  205. end
  206. if sequencer > 1 then
  207. if player:getAutoLootItem(lastitem[player:getGuid()]) then
  208. local resultId = db.storeQuery('SELECT `cont_id` FROM `player_autoloot_persist` WHERE `player_guid` = ' .. player:getGuid() .. ' AND `item_id` = ' .. lastitem[player:getGuid()] .. '')
  209. if resultId then
  210. local bp_id = result.getNumber(resultId, 'cont_id')
  211. else
  212. db.query("INSERT INTO `player_autoloot_persist` (`player_guid`, `cont_id`, `item_id`) VALUES (".. player:getGuid() ..", ".. bp2[choiceId] ..", ".. lastitem[player:getGuid()] ..") ON DUPLICATE KEY UPDATE `cont_id` = ".. bp2[choiceId])
  213. end
  214. if result.getNumber(resultId, 'cont_id') and result.getNumber(resultId, 'cont_id') ~= bp2[choiceId] then
  215. db.query('UPDATE `player_autoloot_persist` SET `cont_id` = '..bp2[choiceId]..' WHERE `player_guid` = ' .. player:getGuid() .. ' AND `item_id` = ' .. lastitem[player:getGuid()] .. '')
  216. end
  217. end
  218. end
  219. call(player, 'add')
  220. end
  221. if modalWindowId == 1006 then
  222. local container, bp, sequencer = {}, {}, 1
  223. local bp2 = {}
  224. for i = 0, getContainerSize(getPlayerSlotItem(player, CONST_SLOT_BACKPACK).uid) do
  225. local thing = getContainerItem(getPlayerSlotItem(player, CONST_SLOT_BACKPACK).uid, i)
  226. container[i] = getContainerItem(getPlayerSlotItem(player, CONST_SLOT_BACKPACK).uid, i)
  227. if isContainer(container[i].uid) then
  228. itemtester = Item(container[i].uid)
  229. bp[sequencer] = itemtester
  230. bp2[sequencer] = itemtester:getId()
  231. sequencer = sequencer + 1
  232. end
  233. end
  234. if sequencer > 1 then
  235. local resultId = db.storeQuery('SELECT `cont_id` FROM `player_autoloot_persist` WHERE `player_guid` = ' .. player:getGuid() .. ' AND `item_id` = ' .. lastitem[player:getGuid()] .. '')
  236. if resultId then
  237. local bp_id = result.getNumber(resultId, 'cont_id')
  238. else
  239. db.query("INSERT INTO `player_autoloot_persist` (`player_guid`, `cont_id`, `item_id`) VALUES (".. player:getGuid() ..", ".. bp2[choiceId] ..", ".. lastitem[player:getGuid()] ..") ON DUPLICATE KEY UPDATE `cont_id` = ".. bp2[choiceId])
  240. end
  241. if result.getNumber(resultId, 'cont_id') and result.getNumber(resultId, 'cont_id') ~= bp2[choiceId] then
  242. db.query('UPDATE `player_autoloot_persist` SET `cont_id` = '..bp2[choiceId]..' WHERE `player_guid` = ' .. player:getGuid() .. ' AND `item_id` = ' .. lastitem[player:getGuid()] .. '')
  243. end
  244. end
  245. call(player, 'remove')
  246. end
  247. end
  248. end
  249.  
  250. creatureevent:register()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement