instance_find_friend
- instance_find_friend(object)
- Returns the nearest instance of an object whose local variable "team" has the same value as the calling instance, or noone if no instance is found.
COPY/// @func instance_find_friend(object)
///
/// @desc Returns the nearest instance of an object whose local
/// variable "team" has the same value as the calling instance,
/// or noone if no instance is found.
///
/// @param {object} object object to look for (or all)
///
/// @return {instance} nearest friend instance, or noone
///
/// GMLscripts.com/license
function instance_find_friend(object)
{
var ds = ds_priority_create();
ds_priority_add(ds, noone, 100000000);
with (object) {
if (team == other.team && id != other.id) {
ds_priority_add(ds, id, point_distance(x, y, other.x, other.y));
}
}
var selected = ds_priority_find_min(ds);
ds_priority_destroy(ds);
return selected;
}
Contributors: xot
GitHub: View · Commits · Blame · Raw