viewing paste getmapusersid | Text

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
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,"?"),
Viewed 1164 times, submitted by jaBote.