Advertisement
Snowsz

Untitled

Feb 19th, 2015
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. local stor, limit = 7575, 5 --storage, limit to add.
  2.  
  3. local allow_container = false --empty! not looted with items, atleast for now.
  4.  
  5. function onSay(cid, words, param)
  6. local expl = param:explode(':')
  7. local action, rst = expl[1], expl[2]
  8. if (action == 'check') then
  9. local infos, list = getPlayerStorageValue(cid, stor), {}
  10. if (infos ~= -1) then
  11. list = tostring(infos):explode(',')
  12. end
  13. local txt = 'Autoloot List:\n'
  14. if (#list > 0) then
  15. for k, id in ipairs(list) do
  16. id = id:gsub('_', '')
  17. if tonumber(id) then
  18. txt = txt .. getItemNameById(tonumber(id)) .. ((k < #list) and '\n' or '')
  19. end
  20. end
  21. else
  22. txt = 'Empty'
  23. end
  24. doPlayerPopupFYI(cid, txt)
  25. elseif (action == 'add') then
  26. local infos, list = getPlayerStorageValue(cid, stor), {}
  27. if (infos ~= -1) then
  28. list = tostring(infos):gsub('_', ''):explode(',')
  29. end
  30. if (#list >= limit) then
  31. return doPlayerSendCancel(cid, 'You already have ' .. limit .. ' autolooting items.')
  32. end
  33. local item = tonumber(rst)
  34. if not item then
  35. item = getItemIdByName(rst, false)
  36. if not item then
  37. return doPlayerSendCancel(cid, 'not valid item.')
  38. end
  39. end
  40. if not allow_container and isItemContainer(item) then
  41. return doPlayerSendCancel(cid, 'this item can not be autolooted.')
  42. end
  43. local attrs = getItemInfo(item)
  44. if not attrs then
  45. return doPlayerSendCancel(cid, 'not valid item.')
  46. elseif not attrs.movable or not attrs.pickupable then
  47. return doPlayerSendCancel(cid, 'this item can not be autolooted.')
  48. end
  49. if isInArray(list, item) then
  50. return doPlayerSendCancel(cid, 'already added.')
  51. end
  52. table.insert(list, tostring(item))
  53. local new = ''
  54. for v, id in ipairs(list) do
  55. new = new .. '_' .. id:gsub('_' ,'') .. ((v < #list) and ',' or '')
  56. end
  57. doPlayerSetStorageValue(cid, stor, tostring(new))
  58. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'Item >>' .. getItemNameById(item) .. '<< has been added to the autoloot list.')
  59. elseif (action == 'remove') then
  60. local infos, list = getPlayerStorageValue(cid, stor), {}
  61. if (infos ~= -1) then
  62. list = tostring(infos):gsub('_', ''):explode(',')
  63. end
  64. if (#list == 0) then
  65. return doPlayerSendCancel(cid, 'You dont have any item added.')
  66. end
  67. if (#list >= limit) then
  68. return doPlayerSendCancel(cid, 'You already have ' .. limit .. ' autolooting items.')
  69. end
  70. local item = tonumber(rst)
  71. if not item then
  72. item = getItemIdByName(rst, false)
  73. if not item then
  74. return doPlayerSendCancel(cid, 'not valid item.')
  75. end
  76. end
  77. if not isInArray(list, item) then
  78. return doPlayerSendCancel(cid, 'This item is not in the list.')
  79. end
  80. local new = ''
  81. for v, id in ipairs(list) do
  82. if (tonumber(id) ~= item) then
  83. new = new .. '_' .. id:gsub('_' ,'') .. ((v < #list) and ',' or '')
  84. end
  85. end
  86. doPlayerSetStorageValue(cid, stor, tostring(new))
  87. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'Item >>' .. getItemNameById(item) .. '<< removed from the autoloot list.')
  88. end
  89. return true
  90. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement