Is there a better function that does that this does more efficiently?
Check if theres a player in range of the given tilex and tiley (with sometimes a given range but not always).
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
function InPlayerRange(tilex, tiley, range)
if range == 0 then range = CONFIG.SPAWNDISTANCE end
for _, id in pairs(player(0, 'tableliving')) do
local x, y, dist
x = (PLAYERS[id].Cords.Tile[1] - tilex) ^ 2
y = (PLAYERS[id].Cords.Tile[2] - tiley) ^ 2
dist = math.sqrt(x + y)
if dist <= range then
return true
end
end
return false
end
Help would be highly appreciated!