Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function CreateBushContainer(name, bush)
- local cont = Containers:CreateContainer({
- layout = {3,3},
- --skins = {"Hourglass"},
- headerText = name,
- buttons = {"Grab All"},
- position="entity", --"mouse",--"900px 200px 0px",
- draggable = false,
- closeOnOrder= true,
- items = {},
- entity = bush,
- range = DEFAULT_TRANSFER_RANGE,
- OnDragWorld = true,
- OnLeftClick = function(playerID, container, unit, item, slot)
- if ContainerTransferItem(container, bush, unit, item) then
- unit:StartGesture(ACT_DOTA_ATTACK)
- unit:EmitSound("bush.rustle")
- else
- SendErrorMessage(playerID, "#error_inventory_full")
- end
- if container:GetNumItems() == 0 then RemoveBushGlow(bush) end
- end,
- OnRightClick = function(playerID, container, unit, item, slot)
- if ContainerTransferItem(container, bush, unit, item) then
- unit:StartGesture(ACT_DOTA_ATTACK)
- unit:EmitSound("bush.rustle")
- else
- SendErrorMessage(playerID, "#error_inventory_full")
- end
- if container:GetNumItems() == 0 then RemoveBushGlow(bush) end
- end,
- OnButtonPressed = function(playerID, container, unit, button, buttonName)
- if button == 1 then
- local items = container:GetAllItems()
- unit:StartGesture(ACT_DOTA_ATTACK)
- unit:EmitSound("bush.rustle")
- local got_atleast_one = false
- local atleast_one_left = false
- local stack_full = false
- local stack
- local max_stack
- local inventory_space = GetNumItemsInInventory(unit)
- for _,item in ipairs(items) do
- local cantake = CanTakeItem(unit, item)
- if cantake then -- Truthy
- if (cantake == true and inventory_space < 6) or (cantake ~= true and not stack_full) then
- if cantake == true then -- Inventory has space
- inventory_space = inventory_space + 1
- else -- Item in question can stack
- if not stack then
- stack = cantake:GetCurrentCharges()
- max_stack = GameRules.ItemKV[cantake:GetAbilityName()]["MaxStacks"]
- end
- local grab_stack = item:GetCurrentCharges()
- if stack + grab_stack >= max_stack then
- stack_full = true
- else
- stack = stack + grab_stack
- end
- end
- got_atleast_one = true
- ContainerTransferItem(container, bush, unit, item)
- if unit:HasModifier("modifier_telegather") then
- local didTeleport = TeleportItem(unit,item)
- elseif unit:HasModifier("modifier_herbtelegather") then
- local didTeleport = TeleportItemHerb(unit,item)
- end
- end
- else
- atleast_one_left = true
- end
- end
- if not got_atleast_one then
- if not atleast_one_left then
- SendErrorMessage(playerID, "#error_bush_empty")
- else
- SendErrorMessage(playerID, "#error_inventory_full")
- end
- end
- container:Close(playerID)
- if atleast_one_left then
- RemoveBushGlow(bush)
- end
- end
- end,
- OnEntityOrder = function(playerID, container, unit, target)
- --[[if (bush:GetUnitName() == "npc_bush_scout" and unit:GetClassname() ~= "npc_dota_hero_lion") then
- SendErrorMessage(playerID, "#error_scout_only_bush")
- return --exits if bush is used by anything other than a scout
- end
- if (bush:GetUnitName() == "npc_bush_thief" and unit:GetClassname() ~= "npc_dota_hero_riki") then
- SendErrorMessage(playerID, "#error_thief_only_bush")
- return --exits if bush is used by anything other than a thief
- end]]
- print("ORDER ACTION loot box: ", playerID)
- container:Open(playerID)
- unit:Stop()
- unit:Hold()
- end,
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement