09-17-2021, 04:32 PM
PICKUP AMMO FROM A CONTAINER ON FLOOR
keywords: refill ammo, refill arrow, refill bolts, pickup ammo, pickup arrow, pickup bolts, take bolts, take ammo, take arrow, container, backpack, bp
local MINIMUM_CAP = 100 -- The minimum amount of capacity that you want to have.
local AMMO = 'bolt' -- Ammo NAME or ID
local AMMO_OZ = 0.8 -- Ammo unit weight.
local AMMO_MAX_AMOUNT = 10 -- Max. amount that you wanna carry.
local AMMO_GROUND_CONTAINER = 'bag' -- Ammo's container on FLOOR.
local AMMO_GROUND_LOCATION = { X = 12345, Y = 12345, Z = 7 } -- Ammo's location on FLOOR.
local AMMO_CONTAINER = 'red backpack' -- Container that AMMO will be moved to.
local pickup_count = math.max(0, (AMMO_MAX_AMOUNT - itemcount(AMMO, AMMO_CONTAINER, true)))
if pickup_count > 0 then
local max_capacity = math.floor((cap - MINIMUM_CAP) / AMMO_OZ)
if pickup_count > max_capacity then
pickup_count = max_capacity
end
if pickup_count > 100 then
pickup_count = 100
end
if pickup_count > 0 then
local AMMO_ID = itemid(AMMO)
for i = 1, 3 do
local WINDOW_CONTAINER_BEFORE = windowcount(AMMO_GROUND_CONTAINER)
openitem(AMMO_GROUND_CONTAINER, ground(AMMO_GROUND_LOCATION.X, AMMO_GROUND_LOCATION.Y, AMMO_GROUND_LOCATION.Z))
wait(1000)
local WINDOW_CONTAINER_AFTER = windowcount(AMMO_GROUND_CONTAINER)
if WINDOW_CONTAINER_AFTER > WINDOW_CONTAINER_BEFORE then
while pickup_count > 0 and itemcount(AMMO, AMMO_GROUND_CONTAINER) > 0 do
moveitems(AMMO_ID, AMMO_CONTAINER, AMMO_GROUND_CONTAINER, pickup_count) then
wait(1000)
pickup_count = math.max(0, (AMMO_MAX_AMOUNT - itemcount(AMMO, AMMO_CONTAINER, true)))
max_capacity = math.floor((cap - MINIMUM_CAP) / AMMO_OZ)
if pickup_count > max_capacity then
pickup_count = max_capacity
end
if pickup_count > 100 then
pickup_count = 100
end
end
break
end
end
end
end
keywords: refill ammo, refill arrow, refill bolts, pickup ammo, pickup arrow, pickup bolts, take bolts, take ammo, take arrow, container, backpack, bp