require 'lib.moonloader'
function main()
while not isSampAvailable() do wait(0) end
while true do
wait(0)
if isKeyJustPressed(VK_B) then
if getClosestPlayerId() ~= -1 or nil then
sampSendChat('/wi ' .. getClosestPlayerId())
else
return false
end
end
end
end
function getClosestPlayerId()
local closestId = -1
mydist = 30
local x, y, z = getCharCoordinates(PLAYER_PED)
for i = 0, 999 do
local streamed, pedID = sampGetCharHandleBySampPlayerId(i)
if streamed and getCharHealth(pedID) > 0 and not sampIsPlayerPaused(pedID) then
local xi, yi, zi = getCharCoordinates(pedID)
local dist = getDistanceBetweenCoords3d(x, y, z, xi, yi, zi)
if dist <= mydist then
mydist = dist
closestId = i
end
end
end
return closestId
end