Well, its easy, all you want to do is
ACMD_FUNC(whoat) {
struct map_session_data *pl_sd = NULL;
struct s_mapiterator *iter = NULL;
char player_name[NAME_LENGTH] = "";
int count = 0;
int level = 0;
StringBuf buf;
int display_type = 1;
int map_id = -1;
nullpo_retr(-1, sd);
char map_name[MAP_NAME_LENGTH_EXT] = "";
if (sscanf(message, "%15s", map_name) <= 0 || (map_id = map_mapname2mapid(map_name)) < 0)
level = pc_get_group_level(sd);
StringBuf_Init(&buf);
iter = mapit_getallusers();
for (pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter)) {
if (!(((pc_has_permission(pl_sd, PC_PERM_HIDE_SESSION) || (pl_sd->sc.option & OPTION_INVISIBLE)) && pc_get_group_level(pl_sd) > level)) && (pl_sd->state.autotrade)) { // you can look only lower or same level
if (stristr(pl_sd->status.name, player_name) == NULL // search with no case sensitive
|| (map_id >= 0 && pl_sd->bl.m != map_id))
continue;
if (pc_has_permission(sd, PC_PERM_WHO_DISPLAY_AID))
StringBuf_Printf(&buf, msg_txt(sd,912), pl_sd->status.char_id, pl_sd->status.account_id); // "(CID:%d/AID:%d) "
StringBuf_Printf(&buf, msg_txt(sd,343), pl_sd->status.name); // "Name: %s "
if (pc_get_group_id(pl_sd) > 0) // Player title, if exists
StringBuf_Printf(&buf, msg_txt(sd,344), pc_group_id2name(pc_get_group_id(pl_sd))); // "(%s) "
StringBuf_Printf(&buf, msg_txt(sd,348), mapindex_id2name(pl_sd->mapindex), pl_sd->bl.x, pl_sd->bl.y); // "| Location: %s %d %d"
clif_displaymessage(fd, StringBuf_Value(&buf));
StringBuf_Clear(&buf);
count++;
}
}
mapit_free(iter);
if (map_id < 0) {
if (count == 0)
StringBuf_Printf(&buf, msg_txt(sd,28)); // No player found.
else if (count == 1)
StringBuf_Printf(&buf, msg_txt(sd,29)); // 1 player found.
else
StringBuf_Printf(&buf, msg_txt(sd,30), count); // %d players found.
}
clif_displaymessage(fd, StringBuf_Value(&buf));
StringBuf_Destroy(&buf);
return 0;
}
I didn't tested yet, but that is the idea.