From 058dabd69eb190f507e56747e5f25f68b935ec69 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 4 Dec 2014 01:18:28 +0300 Subject: Add script command to set npc click/activate instance. New script command: setnpcdistance N Where N is distance in tiles from where npc can be clicked. Add setnpcdistance into docs. --- doc/script_commands.txt | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'doc') diff --git a/doc/script_commands.txt b/doc/script_commands.txt index 3467a5366..36b52988b 100644 --- a/doc/script_commands.txt +++ b/doc/script_commands.txt @@ -7558,6 +7558,17 @@ config, and will not work properly if the NPC has a mob sprite. --------------------------------------- +*setnpcdistance + +This command can reduce distance from where npc can be clicked. +Usefull to use from OnInit event. + + // Set distance to one tile on server load + OnInit: + setnpcdistance 1; + +--------------------------------------- + *day; *night; -- cgit v1.2.3-70-g09d2 From b681deae9fdee3a219ddf43b76a553c57733f237 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 6 Dec 2014 20:51:57 +0300 Subject: Add getnpcdir and setnpcdir functions. --- doc/script_commands.txt | 19 ++++++++++++++ src/map/script.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) (limited to 'doc') diff --git a/doc/script_commands.txt b/doc/script_commands.txt index 36b52988b..642b67fe3 100644 --- a/doc/script_commands.txt +++ b/doc/script_commands.txt @@ -7569,6 +7569,25 @@ Usefull to use from OnInit event. --------------------------------------- +*getnpcdir {}; + +Return current npc direction for parameter "name" or for attached npc +if it missing. If name missing and not attached npc, return -1. + +Example: + .@dir = getnpcdir(); + +--------------------------------------- + +*setnpcdir {,} ; + +Set npc direction. If npc name missing, will be used attached npc. + +Example: + setnpcdir 2; + +--------------------------------------- + *day; *night; diff --git a/src/map/script.c b/src/map/script.c index 5be4347ec..5d9220297 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -13311,6 +13311,7 @@ BUILDIN(npcstop) { return true; } +// set click npc distance [4144] BUILDIN(setnpcdistance) { struct npc_data *nd = (struct npc_data *) map->id2bl (st->oid); if (!nd) @@ -13321,6 +13322,72 @@ BUILDIN(setnpcdistance) { return true; } +// return current npc direction [4144] +BUILDIN(getnpcdir) +{ + struct npc_data *nd = 0; + + if (script_hasdata(st, 2)) + { + nd = npc->name2id (script_getstr(st, 2)); + } + if (!nd && !st->oid) + { + script_pushint(st, -1); + return true; + } + + if (!nd) + nd = (struct npc_data *) map->id2bl (st->oid); + + if (!nd) + { + script_pushint(st, -1); + return true; + } + + script_pushint(st, (int)nd->dir); + + return true; +} + +// set npc direction [4144] +BUILDIN(setnpcdir) +{ + int newdir; + struct npc_data *nd = 0; + + if (script_hasdata(st, 3)) + { + nd = npc->name2id (script_getstr(st, 2)); + newdir = script_getnum(st, 3); + } + else if (script_hasdata(st, 2)) + { + if (!st->oid) + return false; + + nd = (struct npc_data *) map->id2bl (st->oid); + newdir = script_getnum(st, 2); + } + if (!nd) + return false; + + if (newdir < 0) + newdir = 0; + else if (newdir > 7) + newdir = 7; + + nd->dir = newdir; + if (nd->ud) + nd->ud->dir = newdir; + + clif->clearunit_area(&nd->bl, CLR_OUTSIGHT); + clif->spawn(&nd->bl); + + return true; +} + /*========================================== * getlook char info. getlook(arg) @@ -19389,6 +19456,8 @@ void script_parse_builtin(void) { BUILDIN_DEF(npcwalkto,"ii"), // [Valaris] BUILDIN_DEF(npcstop,""), // [Valaris] BUILDIN_DEF(setnpcdistance,"i"), // [4144] + BUILDIN_DEF(getnpcdir,"?"), // [4144] + BUILDIN_DEF(setnpcdir,"*"), // [4144] BUILDIN_DEF(getmapxy,"rrri?"), //by Lorky [Lupus] BUILDIN_DEF(checkoption1,"i"), BUILDIN_DEF(checkoption2,"i"), -- cgit v1.2.3-70-g09d2 From ac4a461a4054eb814ff3df089d9caa96a4343a3d Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 6 Dec 2014 21:09:27 +0300 Subject: Add script command getnpcclass. --- doc/script_commands.txt | 10 ++++++++++ src/map/script.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) (limited to 'doc') diff --git a/doc/script_commands.txt b/doc/script_commands.txt index 642b67fe3..fb4c2530d 100644 --- a/doc/script_commands.txt +++ b/doc/script_commands.txt @@ -7588,6 +7588,16 @@ Example: --------------------------------------- +*getnpcclass {}; + +Return npc class/sprite id for npc with given name or for attached npc. +If name missing and no attached npc, return -1. + +Example: + .@class = getnpcclass(); + +--------------------------------------- + *day; *night; diff --git a/src/map/script.c b/src/map/script.c index 5d9220297..84179a64e 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -13388,6 +13388,35 @@ BUILDIN(setnpcdir) return true; } +// return npc class [4144] +BUILDIN(getnpcclass) +{ + struct npc_data *nd = 0; + + if (script_hasdata(st, 2)) + { + nd = npc->name2id (script_getstr(st, 2)); + } + if (!nd && !st->oid) + { + script_pushint(st, -1); + return false; + } + + if (!nd) + nd = (struct npc_data *) map->id2bl(st->oid); + + if (!nd) + { + script_pushint(st, -1); + return false; + } + + script_pushint(st, (int)nd->class_); + + return true; +} + /*========================================== * getlook char info. getlook(arg) @@ -19458,6 +19487,7 @@ void script_parse_builtin(void) { BUILDIN_DEF(setnpcdistance,"i"), // [4144] BUILDIN_DEF(getnpcdir,"?"), // [4144] BUILDIN_DEF(setnpcdir,"*"), // [4144] + BUILDIN_DEF(getnpcclass,"?"), // [4144] BUILDIN_DEF(getmapxy,"rrri?"), //by Lorky [Lupus] BUILDIN_DEF(checkoption1,"i"), BUILDIN_DEF(checkoption2,"i"), -- cgit v1.2.3-70-g09d2 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(-) (limited to 'doc') 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 From 4e546bb97afdc3d4a0a29325b88942873ed676a3 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 7 Dec 2014 19:42:37 +0300 Subject: Add OnUnTouch event/label into scripts documentation. --- doc/script_commands.txt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'doc') diff --git a/doc/script_commands.txt b/doc/script_commands.txt index 4909699c3..3c99afcf1 100644 --- a/doc/script_commands.txt +++ b/doc/script_commands.txt @@ -259,7 +259,8 @@ direction across Y. Walking into that area will trigger the NPC. If no 'OnTouch:' special label is present in the NPC code, the execution will start from the beginning of the script, otherwise, it will start from the 'OnTouch:' label. Monsters can also trigger the NPC, though the label -'OnTouchNPC:' is used in this case. +'OnTouchNPC:' is used in this case. If player left area npc will called +if present label 'OnUnTouch'. The code part is the script code that will execute whenever the NPC is triggered. It may contain commands and function calls, descriptions of @@ -1040,6 +1041,12 @@ OnTouch_: Similar to OnTouch, but will only run one instance. Another character is chosen once the triggering character leaves the area. +OnUnTouch: + +This label will be executed if plater leave trigger area is defined for the NPC +object it's in. If it isn't present, nothing will happend. +The RID of the triggering character object will be attached. + OnPCLoginEvent: OnPCLogoutEvent: OnPCBaseLvUpEvent: -- cgit v1.2.3-70-g09d2