Files
2026-05-29 15:11:31 +07:00

48 lines
1.7 KiB
Lua

--[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
local ____exports = {}
local ____entity_radius = require("utils.entity_radius")
local findAllByClassnameInRadius = ____entity_radius.findAllByClassnameInRadius
CustomGameEventManager:RegisterListener(
"autopickup_ctrl_pressed",
function(_source, event)
local playerID = event.PlayerID
local player = PlayerResource:GetPlayer(playerID)
if not player then
return
end
local hero = player:GetAssignedHero()
if not hero or not hero:IsRealHero() then
return
end
local heroPos = hero:GetAbsOrigin()
local detectionRadius = 400
local nearbyItems = findAllByClassnameInRadius("dota_item_drop", heroPos, detectionRadius)
local closestItem
local minDist = detectionRadius + 1
for ____, item in ipairs(nearbyItems) do
do
if not IsValidEntity(item) then
goto __continue5
end
local itemEntity = item
local itemPos = itemEntity:GetAbsOrigin()
local dist = (heroPos - itemPos):Length2D()
if dist < minDist then
minDist = dist
closestItem = itemEntity
end
end
::__continue5::
end
if closestItem then
ExecuteOrderFromTable({
UnitIndex = hero:entindex(),
OrderType = DOTA_UNIT_ORDER_PICKUP_ITEM,
TargetIndex = closestItem:entindex(),
Queue = false
})
end
end
)
return ____exports