From e5471b1890bae50c36ccf8a8c7e1fee868c156b1 Mon Sep 17 00:00:00 2001 From: mekolat Date: Sat, 28 Mar 2015 16:06:29 -0400 Subject: add getnpcx and getnpcy --- src/map/script-fun.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src') diff --git a/src/map/script-fun.cpp b/src/map/script-fun.cpp index 8c25266..eea8797 100644 --- a/src/map/script-fun.cpp +++ b/src/map/script-fun.cpp @@ -2984,6 +2984,30 @@ void builtin_getmap(ScriptState *st) push_str(st->stack, sd->bl_m->name_); } +/*============================ + * Gets the NPC's x pos + *---------------------------- + */ +static +void builtin_getnpcx(ScriptState *st) +{ + dumb_ptr nd = map_id_is_npc(st->oid); + + push_int(st->stack, nd->bl_x); +} + +/*============================ + * Gets the NPC's y pos + *---------------------------- + */ +static +void builtin_getnpcy(ScriptState *st) +{ + dumb_ptr nd = map_id_is_npc(st->oid); + + push_int(st->stack, nd->bl_y); +} + static void builtin_mapexit(ScriptState *) { @@ -3112,6 +3136,8 @@ BuiltinFunction builtin_functions[] = BUILTIN(fakenpcname, "ssi"_s, '\0'), BUILTIN(getx, ""_s, 'i'), BUILTIN(gety, ""_s, 'i'), + BUILTIN(getnpcx, ""_s, 'i'), + BUILTIN(getnpcy, ""_s, 'i'), BUILTIN(getmap, ""_s, 's'), BUILTIN(mapexit, ""_s, '\0'), BUILTIN(freeloop, "i"_s, '\0'), -- cgit v1.2.3-70-g09d2 From a630bc2d97148e8a32769a5f1e0e2df475d4720a Mon Sep 17 00:00:00 2001 From: mekolat Date: Sat, 28 Mar 2015 16:20:20 -0400 Subject: add strnpcinfo --- src/map/script-fun.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src') diff --git a/src/map/script-fun.cpp b/src/map/script-fun.cpp index eea8797..25c7736 100644 --- a/src/map/script-fun.cpp +++ b/src/map/script-fun.cpp @@ -2984,6 +2984,35 @@ void builtin_getmap(ScriptState *st) push_str(st->stack, sd->bl_m->name_); } +/* + * Get the NPC's info + */ +static +void builtin_strnpcinfo(ScriptState *st) +{ + dumb_ptr nd = map_id_is_npc(st->oid); + int num = conv_num(st, &AARG(0)); + RString name; + + switch(num) + { + case 0: + name = nd->name; + break; + case 1: + name = nd->name.xislice_h(std::find(nd->name.begin(), nd->name.end(), '#')); + break; + case 2: + name = nd->name.xislice_t(std::find(nd->name.begin(), nd->name.end(), '#')); + break; + case 3: + name = nd->bl_m->name_; + break; + } + + push_str(st->stack, name); +} + /*============================ * Gets the NPC's x pos *---------------------------- @@ -3138,6 +3167,7 @@ BuiltinFunction builtin_functions[] = BUILTIN(gety, ""_s, 'i'), BUILTIN(getnpcx, ""_s, 'i'), BUILTIN(getnpcy, ""_s, 'i'), + BUILTIN(strnpcinfo, "i"_s, 's'), BUILTIN(getmap, ""_s, 's'), BUILTIN(mapexit, ""_s, '\0'), BUILTIN(freeloop, "i"_s, '\0'), -- cgit v1.2.3-70-g09d2 From f59a33c4796c0e5106776d1c595d19b8feeac9cd Mon Sep 17 00:00:00 2001 From: mekolat Date: Sat, 4 Apr 2015 11:00:46 -0400 Subject: allow to specify npc --- src/map/script-fun.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/map/script-fun.cpp b/src/map/script-fun.cpp index 25c7736..8fa4ea4 100644 --- a/src/map/script-fun.cpp +++ b/src/map/script-fun.cpp @@ -2990,9 +2990,21 @@ void builtin_getmap(ScriptState *st) static void builtin_strnpcinfo(ScriptState *st) { - dumb_ptr nd = map_id_is_npc(st->oid); int num = conv_num(st, &AARG(0)); RString name; + dumb_ptr nd; + + if(HARG(1)){ + NpcName npc = stringish(ZString(conv_str(st, &AARG(1)))); + nd = npc_name2id(npc); + if (!nd) + { + PRINTF("builtin_strnpcinfo: no such npc: %s\n"_fmt, npc); + return; + } + } else { + nd = map_id_is_npc(st->oid); + } switch(num) { @@ -3020,7 +3032,19 @@ void builtin_strnpcinfo(ScriptState *st) static void builtin_getnpcx(ScriptState *st) { - dumb_ptr nd = map_id_is_npc(st->oid); + dumb_ptr nd; + + if(HARG(0)){ + NpcName name = stringish(ZString(conv_str(st, &AARG(0)))); + nd = npc_name2id(name); + if (!nd) + { + PRINTF("builtin_getnpcx: no such npc: %s\n"_fmt, name); + return; + } + } else { + nd = map_id_is_npc(st->oid); + } push_int(st->stack, nd->bl_x); } @@ -3032,7 +3056,19 @@ void builtin_getnpcx(ScriptState *st) static void builtin_getnpcy(ScriptState *st) { - dumb_ptr nd = map_id_is_npc(st->oid); + dumb_ptr nd; + + if(HARG(0)){ + NpcName name = stringish(ZString(conv_str(st, &AARG(0)))); + nd = npc_name2id(name); + if (!nd) + { + PRINTF("builtin_getnpcy: no such npc: %s\n"_fmt, name); + return; + } + } else { + nd = map_id_is_npc(st->oid); + } push_int(st->stack, nd->bl_y); } @@ -3165,9 +3201,9 @@ BuiltinFunction builtin_functions[] = BUILTIN(fakenpcname, "ssi"_s, '\0'), BUILTIN(getx, ""_s, 'i'), BUILTIN(gety, ""_s, 'i'), - BUILTIN(getnpcx, ""_s, 'i'), - BUILTIN(getnpcy, ""_s, 'i'), - BUILTIN(strnpcinfo, "i"_s, 's'), + BUILTIN(getnpcx, "?"_s, 'i'), + BUILTIN(getnpcy, "?"_s, 'i'), + BUILTIN(strnpcinfo, "i?"_s, 's'), BUILTIN(getmap, ""_s, 's'), BUILTIN(mapexit, ""_s, '\0'), BUILTIN(freeloop, "i"_s, '\0'), -- cgit v1.2.3-70-g09d2