summaryrefslogtreecommitdiff
path: root/npc/functions/npcmove.txt
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-05-02 19:22:31 +0300
committerAndrei Karas <akaras@inbox.ru>2015-05-02 19:24:53 +0300
commite5534b4202c5b68d6b0fd0e2f01fae073aa7c8e7 (patch)
treeb90dc0943c241568d4072875d59ff0d1da5719e4 /npc/functions/npcmove.txt
parenta9775a5447d35ef2b31e573a8e2e1dfe2d50bb9b (diff)
downloadserverdata-e5534b4202c5b68d6b0fd0e2f01fae073aa7c8e7.tar.gz
serverdata-e5534b4202c5b68d6b0fd0e2f01fae073aa7c8e7.tar.bz2
serverdata-e5534b4202c5b68d6b0fd0e2f01fae073aa7c8e7.tar.xz
serverdata-e5534b4202c5b68d6b0fd0e2f01fae073aa7c8e7.zip
Add functions and example npc for simple npc moving program.
For now npc AI support moving, changing direction, waiting.
Diffstat (limited to 'npc/functions/npcmove.txt')
-rw-r--r--npc/functions/npcmove.txt84
1 files changed, 84 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));
+}