This is a code to detect every tile in 8 directions in range of X tiles from TILE :
func getneighbours(TILE,X) :
var surroundingtiles = []
for a in range(-X,X):
for b in range(-X,X):
var currenttile = Vector2(a,b)
if not surroundingtiles.has(currenttile) and not currenttile = TILE :
surroundingtiles.append(currenttile)
return surroundingtiles
I made it on the go, it might have some inaccuracy