summaryrefslogtreecommitdiff
path: root/world/map/npc/commands/_procedures.txt
diff options
context:
space:
mode:
authormekolat <mekolat@users.noreply.github.com>2016-04-19 09:42:48 -0400
committermekolat <mekolat@users.noreply.github.com>2016-04-19 09:42:48 -0400
commitea7d999c39ead96efb6d9af7e68794c59290cf60 (patch)
tree771e06363fe2e7609847a0a63a2e499632d3d7a2 /world/map/npc/commands/_procedures.txt
parent9e7f46ac732851c1359a15837c82ebf67ea2be39 (diff)
parent91fe3711fcacdfe83794b4347595e56e90e9d3a7 (diff)
downloadserverdata-ea7d999c39ead96efb6d9af7e68794c59290cf60.tar.gz
serverdata-ea7d999c39ead96efb6d9af7e68794c59290cf60.tar.bz2
serverdata-ea7d999c39ead96efb6d9af7e68794c59290cf60.tar.xz
serverdata-ea7d999c39ead96efb6d9af7e68794c59290cf60.zip
Merge self-fork from mekolat/magic-v3
Magic v3 spells
Diffstat (limited to 'world/map/npc/commands/_procedures.txt')
-rw-r--r--world/map/npc/commands/_procedures.txt53
1 files changed, 53 insertions, 0 deletions
diff --git a/world/map/npc/commands/_procedures.txt b/world/map/npc/commands/_procedures.txt
new file mode 100644
index 00000000..732b496f
--- /dev/null
+++ b/world/map/npc/commands/_procedures.txt
@@ -0,0 +1,53 @@
+// ARGV Splitter
+// takes @args$ and splits it properly so that '@cmd "foo bar" baz' is ['foo bar','baz'] instead of ['"foo','bar"','baz']
+// input: @args$ (string)
+// output: @argv$ (array) and @argv (array)
+function|script|argv_splitter
+{
+ explode .@fragments$, @args$, " ";
+ set .@e, 0;
+ set .@total, getarraysize(.@fragments$);
+ set .@NULL$, chr(3); // HACK: we use .@NULL$ as a workaround because we can't do "\0"
+ goto L_Check;
+
+L_Check:
+ setarray .@check$[0], "", .@NULL$, .@NULL$;
+ explode .@check$, .@fragments$[.@e], "\""; // check if the fragment contains a quote
+ if (.@check$[0] == "" && .@check$[1] != .@NULL$ && .@check$[1] != "" && .@check$[2] == .@NULL$)
+ set .@string$, .@check$[1]; // begin substring
+ elif (.@check$[0] != "" && .@check$[1] == "" && .@check$[2] == .@NULL$)
+ goto L_EndSubString; // end substring
+ elif (.@string$ != "" && .@check$[0] != "" && .@check$[1] == .@NULL$ && .@check$[2] == .@NULL$)
+ set .@string$, .@string$ +" "+ .@check$[0]; // part of the substring
+ elif (.@check$[2] != .@NULL$) goto L_Set2; // the the argument is quoted but there is no space
+ else goto L_Set;
+ goto L_CheckAfter;
+
+L_Set:
+ setarray @argv$[.@t], .@check$[0]; // not in a substring so push right away
+ setarray @argv[.@t], .@check$[0]; // not in a substring so push right away
+ set .@t, .@t + 1;
+ goto L_CheckAfter;
+
+L_Set2:
+ setarray @argv$[.@t], .@check$[1]; // not in a substring so push right away
+ setarray @argv[.@t], .@check$[1]; // not in a substring so push right away
+ set .@t, .@t + 1;
+ goto L_CheckAfter;
+
+L_EndSubString:
+ set .@string$, .@string$ + " " + .@check$[0];
+ setarray @argv$[.@t], .@string$; // push in the array
+ setarray @argv[.@t], .@string$; // push in the array
+ set .@t, .@t + 1;
+ set .@string$, ""; // clean
+ goto L_CheckAfter;
+
+L_CheckAfter:
+ set .@e, .@e + 1;
+ if (.@e > .@total) goto L_Done; // the @argv$ array is built
+ goto L_Check; // not done yet
+
+L_Done:
+ return;
+}