diff options
-rw-r--r-- | doc/script_commands.txt | 19 | ||||
-rw-r--r-- | src/map/script.c | 69 |
2 files changed, 88 insertions, 0 deletions
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 {<name>}; + +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 {<name>,} <direction>; + +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"), |