From 625ed85b6a3d88587e8927f1f640f1fadd3dc642 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 7 Dec 2014 17:18:45 +0300 Subject: Extend script command getareausers. --- doc/script_commands.txt | 13 +++++++--- src/map/script.c | 69 +++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 66 insertions(+), 16 deletions(-) diff --git a/doc/script_commands.txt b/doc/script_commands.txt index fb4c2530d..4909699c3 100644 --- a/doc/script_commands.txt +++ b/doc/script_commands.txt @@ -3226,15 +3226,22 @@ let you enter. --------------------------------------- -*getareausers("",,,,) +*getareausers({"",}{,,,}) +*getareausers({"",}{}) This function will return the count of connected characters which are -located within the specified area - an x1/y1-x2/y2 square - on the -specified map. +located within the specified area. Area can be x1/y1-x2/y2 square, +or radius from npc position. If map name missing, used attached player map. This is useful for maps that are split into many buildings, such as all the "*_in" maps, due to all the shops and houses. +Examples: + // return players in area npc area on current map. + .@num = getareausers(); + // return players in square (1, 1) - (10, 10) + .@num = "players: " + getareausers(1, 1, 10, 10); + --------------------------------------- *getusersname; diff --git a/src/map/script.c b/src/map/script.c index e59159586..fbfb88de2 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -10093,21 +10093,64 @@ int buildin_getareausers_sub(struct block_list *bl,va_list ap) } BUILDIN(getareausers) { - const char *str; - int16 m,x0,y0,x1,y1; + int16 m = -1, x0, y0, x1, y1; int users = 0; - str=script_getstr(st,2); - x0=script_getnum(st,3); - y0=script_getnum(st,4); - x1=script_getnum(st,5); - y1=script_getnum(st,6); - if( (m=map->mapname2mapid(str))< 0) { - script_pushint(st,-1); - return true; + int idx = 2; + struct npc_data *nd = NULL; + if (script_hasdata(st, 2) && script_isstringtype(st, 2)) { + const char *str = script_getstr(st, 2); + if ((m = map->mapname2mapid(str)) < 0) { + script_pushint(st, -1); + return true; + } + idx = 3; + } + if (m == -1) + { + TBL_PC *sd = NULL; + sd = script->rid2sd(st); + if (!sd) + { + script_pushint(st, -1); + return false; + } + m = sd->bl.m; + } + if (st->oid) + nd = map->id2nd(st->oid); + if (script_hasdata(st, idx + 3)) { + x0 = script_getnum(st, idx + 0); + y0 = script_getnum(st, idx + 1); + x1 = script_getnum(st, idx + 2); + y1 = script_getnum(st, idx + 3); + } else if (script_hasdata(st, idx)) { + if (!nd) + { + script_pushint(st, -1); + return true; + } + int sz = script_getnum(st, idx); + x0 = nd->bl.x - sz; + y0 = nd->bl.y - sz; + x1 = nd->bl.x + sz; + y1 = nd->bl.y + sz; + } else if (st->oid) { + if (!nd || nd->u.scr.xs == -1 || nd->u.scr.ys == -1) + { + script_pushint(st, -1); + return true; + } + x0 = nd->bl.x - nd->u.scr.xs; + y0 = nd->bl.y - nd->u.scr.ys; + x1 = nd->bl.x + nd->u.scr.xs; + y1 = nd->bl.y + nd->u.scr.ys; + } else { + script_pushint(st, -1); + return false; } map->foreachinarea(script->buildin_getareausers_sub, - m,x0,y0,x1,y1,BL_PC,&users); - script_pushint(st,users); + m, x0, y0, x1, y1, BL_PC, &users); + script_pushint(st, users); return true; } @@ -19382,7 +19425,7 @@ void script_parse_builtin(void) { BUILDIN_DEF(getusers,"i"), BUILDIN_DEF(getmapguildusers,"si"), BUILDIN_DEF(getmapusers,"s"), - BUILDIN_DEF(getareausers,"siiii"), + BUILDIN_DEF(getareausers,"*"), BUILDIN_DEF(getareadropitem,"siiiiv"), BUILDIN_DEF(enablenpc,"s"), BUILDIN_DEF(disablenpc,"s"), -- cgit v1.2.3-70-g09d2