BUILDIN(getmapusersid) // Returns array
{
struct map_session_data *pl_sd = NULL;
struct s_mapiterator *iter = NULL;
char map_name[MAP_NAME_LENGTH_EXT] = "";
int16 m = -1;
int i = 0;
if (script_hasdata(st, 2)) { // Retrieving and validating input
if (script_isstringtype(st, 2)) { // Data string must be a map name
const char *mymap = script_getstr(st,4);
safestrncpy(map_name,mymap,MAP_NAME_LENGTH_EXT);
m = (map_id = map->mapname2mapid(map_name));
if ( m < 0 ) {
ShowWarning("getmapusersid: Invalid map specified.\n");
script_pushint(st, 0); // There are no users in an invalid map
}
}
else {
ShowWarning("getmapusersid: retrieved argument was not string type. Defaulting to all maps.\n");
script_pushint(st, 0); // There are no users in an invalid map
}
}
iter = mapit_getallusers(); // Get all users and filter for maps
for (pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter)) {
if ( m >= 0 && pl_sd->bl.m != map_id ) {
continue;
}
mapreg->setreg(reference_uid(script->add_str(".@user_ids"), i),pl_sd->bl.id);
i++;
}
script_pushint(st, i);
}
BUILDIN_DEF(getmapusersid,"?"),