From 8d9fe31ed15fb9ce681d6cfe783fd9c4af646d16 Mon Sep 17 00:00:00 2001 From: No Name Date: Sun, 4 Apr 2010 05:24:55 -0700 Subject: Add npcwarp script function to allow an NPC to warp to a new position on its map. This patch models its behavior partly on that of movenpc and the atcommand npcmove. --- src/map/script.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/map/script.c b/src/map/script.c index 0ede96c..5bf6fa5 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -300,6 +300,7 @@ int buildin_specialeffect2 (struct script_state *st); // special effect script int buildin_nude (struct script_state *st); // nude [Valaris] int buildin_gmcommand (struct script_state *st); // [MouseJstr] int buildin_movenpc (struct script_state *st); // [MouseJstr] +int buildin_npcwarp (struct script_state *st); // [remoitnane] int buildin_message (struct script_state *st); // [MouseJstr] int buildin_npctalk (struct script_state *st); // [Valaris] int buildin_hasitems (struct script_state *st); // [Valaris] @@ -701,6 +702,8 @@ struct { buildin_gmcommand, "gmcommand", "*"}, // [MouseJstr] // {buildin_movenpc,"movenpc","siis"}, // [MouseJstr] + { + buildin_npcwarp, "npcwarp", "iis"}, // [remoitnane] { buildin_message, "message", "s*"}, // [MouseJstr] { @@ -6801,6 +6804,41 @@ int buildin_movenpc (struct script_state *st) return 0; } +/*========================================== + * npcwarp [remoitnane] + * Move NPC to a new position on the same map. + *------------------------------------------ + */ +int buildin_npcwarp (struct script_state *st) +{ + int x, y; + char *npc; + struct npc_data *nd = NULL; + + x = conv_num (st, &(st->stack->stack_data[st->start + 2])); + y = conv_num (st, &(st->stack->stack_data[st->start + 3])); + npc = conv_str (st, &(st->stack->stack_data[st->start + 4])); + nd = npc_name2id (npc); + + if (!nd) + return -1; + + short m = nd->bl.m; + + /* Crude sanity checks. */ + if (m < 0 || !nd->bl.prev + || x < 0 || x > map[m].xs -1 + || y < 0 || y > map[m].ys - 1) + return -1; + + npc_enable (npc, 0); + nd->bl.x = x; + nd->bl.y = y; + npc_enable (npc, 1); + + return 0; +} + /*========================================== * message [MouseJstr] *------------------------------------------ -- cgit v1.2.3-70-g09d2