summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--npc/functions/npcmove.txt84
-rw-r--r--npc/scripts.conf1
-rw-r--r--npc/test/_import.txt1
-rw-r--r--npc/test/npc4.txt26
4 files changed, 112 insertions, 0 deletions
diff --git a/npc/functions/npcmove.txt b/npc/functions/npcmove.txt
new file mode 100644
index 00000000..783539a9
--- /dev/null
+++ b/npc/functions/npcmove.txt
@@ -0,0 +1,84 @@
+// Evol functions.
+// Authors:
+// 4144
+// Description:
+// Moving npc utility functions
+// Variables:
+// none
+
+function script initpath {
+ deletearray getvariableofnpc(.movepathcmd$, strnpcinfo(3));
+ deletearray getvariableofnpc(.movepathy, strnpcinfo(3));
+ deletearray getvariableofnpc(.movepathx, strnpcinfo(3));
+ .@cnt = 0;
+
+ for (.@f = 0; .@f < getargcount(); .@f = .@f + 3)
+ {
+ set getvariableofnpc(.movepathcmd$[.@cnt], strnpcinfo(3)), getarg(.@f);
+ set getvariableofnpc(.movepathx[.@cnt], strnpcinfo(3)), getarg(.@f + 1);
+ set getvariableofnpc(.movepathy[.@cnt], strnpcinfo(3)), getarg(.@f + 2);
+ .@cnt ++;
+ }
+ //debugmes "array size: " + str(getarraysize(getvariableofnpc(.movepath, strnpcinfo(3))));
+ return;
+}
+
+function script domoveaction {
+ //debugmes "domoveaction: " + str(getvariableofnpc(.movepos, strnpcinfo(3)));
+ .@pos = getvariableofnpc(.movepos, strnpcinfo(3));
+ if (.@pos >= getarraysize(getvariableofnpc(.movepathx, strnpcinfo(3))) || .@pos < 0)
+ return;
+ //debugmes "walking";
+ .@cmd$ = getvariableofnpc(.movepathcmd$[.@pos], strnpcinfo(3));
+ //debugmes "cmd: " + .@cmd$;
+
+ if (.@cmd$ == "move")
+ {
+ npcwalkto getvariableofnpc(.movepathx[.@pos], strnpcinfo(3)), getvariableofnpc(.movepathy[.@pos], strnpcinfo(3));
+ }
+ else if (.@cmd$ == "dir")
+ {
+ setnpcdir getvariableofnpc(.movepathx[.@pos], strnpcinfo(3));
+ }
+ else if (.@cmd$ == "wait")
+ {
+ set getvariableofnpc(.waitticks, strnpcinfo(3)), getvariableofnpc(.movepathx[.@pos], strnpcinfo(3));
+ }
+ return 1;
+}
+
+function script movetonextpos {
+ .@pos = getvariableofnpc(.movepos, strnpcinfo(3));
+ //debugmes "movetonextpos: " + str(.@pos);
+ .@wait = getvariableofnpc(.waitticks, strnpcinfo(3));
+ if (.@wait > 0)
+ {
+ .@wait --;
+ //debugmes "wait";
+ set getvariableofnpc(.waitticks, strnpcinfo(3)), .@wait;
+ return;
+ }
+ .@res = domoveaction(.@pos);
+ if (.@res)
+ {
+ .@pos++;
+ if (.@pos >= getarraysize(getvariableofnpc(.movepathx, strnpcinfo(3))))
+ .@pos = 0;
+ set getvariableofnpc(.movepos, strnpcinfo(3)), .@pos;
+ }
+ return;
+}
+
+function script initialmove {
+ set getvariableofnpc(.movepos, strnpcinfo(3)), 0;
+ set getvariableofnpc(.waitticks, strnpcinfo(3)), -1;
+ movetonextpos;
+ return;
+}
+
+function script getmovecmd {
+ .@pos = getvariableofnpc(.movepos, strnpcinfo(3));
+ if (.@pos >= getarraysize(getvariableofnpc(.movepathx, strnpcinfo(3))) || .@pos < 0)
+ return "";
+ return getvariableofnpc(.movepathcmd$[.@pos], strnpcinfo(3));
+}
diff --git a/npc/scripts.conf b/npc/scripts.conf
index c5b3a457..e191a5a0 100644
--- a/npc/scripts.conf
+++ b/npc/scripts.conf
@@ -12,6 +12,7 @@ npc: npc/functions/hammocks.txt
npc: npc/functions/harbours.txt
npc: npc/functions/input.txt
npc: npc/functions/inventoryplace.txt
+npc: npc/functions/npcmove.txt
npc: npc/functions/goodbye.txt
npc: npc/functions/sailordialogue.txt
npc: npc/functions/savepoint.txt
diff --git a/npc/test/_import.txt b/npc/test/_import.txt
index 17a3a5cc..95322f03 100644
--- a/npc/test/_import.txt
+++ b/npc/test/_import.txt
@@ -4,3 +4,4 @@ npc: npc/test/_warps.txt
npc: npc/test/npc1.txt
npc: npc/test/npc2.txt
npc: npc/test/npc3.txt
+npc: npc/test/npc4.txt
diff --git a/npc/test/npc4.txt b/npc/test/npc4.txt
new file mode 100644
index 00000000..78103667
--- /dev/null
+++ b/npc/test/npc4.txt
@@ -0,0 +1,26 @@
+// Evol scripts.
+// Authors:
+// 4144
+// Description:
+// test npc4
+
+test,25,20,0 script npc4 801,{
+ close;
+OnTimer1000:
+ if (isunitwalking())
+ {
+ initnpctimer;
+ end;
+ }
+ movetonextpos;
+ initnpctimer;
+ end;
+OnInit:
+ initpath "move", 20, 20,
+ "dir", 6, 0,
+ "move", 25, 20,
+ "wait", 3, 0,
+ "move", 22, 10;
+ initialmove;
+ initnpctimer;
+}