Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.81 KB | None | 0 0
  1. function CreateBushContainer(name, bush)
  2. local cont = Containers:CreateContainer({
  3. layout = {3,3},
  4. --skins = {"Hourglass"},
  5. headerText = name,
  6. buttons = {"Grab All"},
  7. position="entity", --"mouse",--"900px 200px 0px",
  8. draggable = false,
  9. closeOnOrder= true,
  10. items = {},
  11. entity = bush,
  12. range = DEFAULT_TRANSFER_RANGE,
  13. OnDragWorld = true,
  14.  
  15. OnLeftClick = function(playerID, container, unit, item, slot)
  16.  
  17. if ContainerTransferItem(container, bush, unit, item) then
  18. unit:StartGesture(ACT_DOTA_ATTACK)
  19. unit:EmitSound("bush.rustle")
  20. else
  21. SendErrorMessage(playerID, "#error_inventory_full")
  22. end
  23.  
  24. if container:GetNumItems() == 0 then RemoveBushGlow(bush) end
  25. end,
  26.  
  27. OnRightClick = function(playerID, container, unit, item, slot)
  28. if ContainerTransferItem(container, bush, unit, item) then
  29. unit:StartGesture(ACT_DOTA_ATTACK)
  30. unit:EmitSound("bush.rustle")
  31. else
  32. SendErrorMessage(playerID, "#error_inventory_full")
  33. end
  34.  
  35. if container:GetNumItems() == 0 then RemoveBushGlow(bush) end
  36. end,
  37.  
  38. OnButtonPressed = function(playerID, container, unit, button, buttonName)
  39. if button == 1 then
  40. local items = container:GetAllItems()
  41. unit:StartGesture(ACT_DOTA_ATTACK)
  42. unit:EmitSound("bush.rustle")
  43. local got_atleast_one = false
  44. local atleast_one_left = false
  45. local stack_full = false
  46. local stack
  47. local max_stack
  48. local inventory_space = GetNumItemsInInventory(unit)
  49.  
  50. for _,item in ipairs(items) do
  51. local cantake = CanTakeItem(unit, item)
  52. if cantake then -- Truthy
  53. if (cantake == true and inventory_space < 6) or (cantake ~= true and not stack_full) then
  54. if cantake == true then -- Inventory has space
  55. inventory_space = inventory_space + 1
  56. else -- Item in question can stack
  57. if not stack then
  58. stack = cantake:GetCurrentCharges()
  59. max_stack = GameRules.ItemKV[cantake:GetAbilityName()]["MaxStacks"]
  60. end
  61.  
  62. local grab_stack = item:GetCurrentCharges()
  63. if stack + grab_stack >= max_stack then
  64. stack_full = true
  65. else
  66. stack = stack + grab_stack
  67. end
  68. end
  69.  
  70. got_atleast_one = true
  71.  
  72. ContainerTransferItem(container, bush, unit, item)
  73. if unit:HasModifier("modifier_telegather") then
  74. local didTeleport = TeleportItem(unit,item)
  75. elseif unit:HasModifier("modifier_herbtelegather") then
  76. local didTeleport = TeleportItemHerb(unit,item)
  77. end
  78. end
  79. else
  80. atleast_one_left = true
  81. end
  82. end
  83.  
  84. if not got_atleast_one then
  85. if not atleast_one_left then
  86. SendErrorMessage(playerID, "#error_bush_empty")
  87. else
  88. SendErrorMessage(playerID, "#error_inventory_full")
  89. end
  90. end
  91.  
  92. container:Close(playerID)
  93.  
  94. if atleast_one_left then
  95. RemoveBushGlow(bush)
  96. end
  97. end
  98. end,
  99.  
  100. OnEntityOrder = function(playerID, container, unit, target)
  101. --[[if (bush:GetUnitName() == "npc_bush_scout" and unit:GetClassname() ~= "npc_dota_hero_lion") then
  102. SendErrorMessage(playerID, "#error_scout_only_bush")
  103. return --exits if bush is used by anything other than a scout
  104. end
  105.  
  106. if (bush:GetUnitName() == "npc_bush_thief" and unit:GetClassname() ~= "npc_dota_hero_riki") then
  107. SendErrorMessage(playerID, "#error_thief_only_bush")
  108. return --exits if bush is used by anything other than a thief
  109. end]]
  110.  
  111. print("ORDER ACTION loot box: ", playerID)
  112. container:Open(playerID)
  113. unit:Stop()
  114. unit:Hold()
  115. end,
  116. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement