function getPlayersInRange(playerSource, range) local x, y, z = getElementPosition(playerSource) local playersInRange = {} local count = 0 for _, player in ipairs(getElementsByType("player")) do if player ~= playerSource then local px, py, pz = getElementPosition(player) if getDistanceBetweenPoints3D(x, y, z, px, py, pz) <= range then count = count + 1 table.insert(playersInRange, player) end end end return count > 0 and playersInRange or false end
function mostrarJugadoresCercanos(source) local players_in_range = getPlayersInRange(source, 4) for _, player in ipairs(players_in_range) do outputChatBox(getPlayerName(player), source) end end addCommandHandler("cercanos", mostrarJugadoresCercanos)
Curso Programacion en LUA para MTA
Aprende a programar desde 0 hasta avanzado
con ejercicios practicos para mejorar tus habilidades