summaryrefslogtreecommitdiff
path: root/npc/functions/input.txt
diff options
context:
space:
mode:
authorJesusaves <cpntb1@ymail.com>2021-04-10 03:00:20 -0300
committerJesusaves <cpntb1@ymail.com>2021-04-10 03:00:20 -0300
commitba1e827b6b4c17c35a163e6b55be8c122de632b8 (patch)
tree819f93d0ffee3697e336471710afb9681f0b8d86 /npc/functions/input.txt
parent6e7f3113c0faad9edd4367d100ba9dd77e8d3130 (diff)
downloadserverdata-ba1e827b6b4c17c35a163e6b55be8c122de632b8.tar.gz
serverdata-ba1e827b6b4c17c35a163e6b55be8c122de632b8.tar.bz2
serverdata-ba1e827b6b4c17c35a163e6b55be8c122de632b8.tar.xz
serverdata-ba1e827b6b4c17c35a163e6b55be8c122de632b8.zip
Add several convenience functions. Fix some bugs regarding misuse of readparam()
Diffstat (limited to 'npc/functions/input.txt')
-rw-r--r--npc/functions/input.txt110
1 files changed, 110 insertions, 0 deletions
diff --git a/npc/functions/input.txt b/npc/functions/input.txt
new file mode 100644
index 00000000..0a510b74
--- /dev/null
+++ b/npc/functions/input.txt
@@ -0,0 +1,110 @@
+// Evol functions.
+// Author:
+// 4144
+// Jesusalva
+// Description:
+// Input utility functions
+// Variables:
+// none
+
+function script menuint {
+ deletearray .@vals;
+ .@menustr$ = "";
+ .@cnt = 0;
+
+ for (.@f = 0; .@f < getargcount(); .@f = .@f + 2)
+ {
+ if (getarg(.@f) != "")
+ {
+ .@menustr$ = .@menustr$ + getarg(.@f) + ":";
+ .@vals[.@cnt] = getarg(.@f + 1);
+ .@cnt ++;
+ }
+ }
+
+ .@vals[.@cnt] = -1;
+ @menu = 255;
+ @menuret = -1;
+ select(.@menustr$);
+ if (@menu == 255)
+ return -1;
+
+ @menu --;
+ if (@menu < 0 || @menu >= getarraysize(.@vals) - 1)
+ return -1;
+
+ @menuret = .@vals[@menu];
+ return @menuret;
+}
+
+function script menustr {
+ deletearray .@vals$;
+ .@menustr$ = "";
+ .@cnt = 0;
+
+ for (.@f = 0; .@f < getargcount(); .@f = .@f + 2)
+ {
+ if (getarg(.@f) != "")
+ {
+ .@menustr$ = .@menustr$ + getarg(.@f) + ":";
+ .@vals$[.@cnt] = getarg(.@f + 1);
+ .@cnt ++;
+ }
+ }
+
+ @menu = 255;
+ @menuret = -1;
+ select(.@menustr$);
+ if (@menu == 255)
+ return "";
+
+ @menu --;
+ if (@menu < 0 || @menu >= getarraysize(.@vals$))
+ return "";
+
+ @menuret$ = .@vals$[@menu];
+ return @menuret$;
+}
+
+// menuint2(<array>)
+function script menuint2 {
+ .@menustr$="";
+
+ if (!(getdatatype(getarg(0)) & DATATYPE_VAR))
+ Exception("Inadequate argument type - Must be var", RB_DEFAULT|RB_ISFATAL);
+
+ copyarray(.@ar$, getarg(0), getarraysize(getarg(0)));
+
+ if (getarraysize(.@ar$) % 2 != 0)
+ Exception("Invalid array size: "+getarraysize(.@ar$), RB_DEFAULT|RB_ISFATAL);
+
+ freeloop(true);
+ for (.@f=0; .@f < getarraysize(.@ar$); .@f++) {
+ // String vs Int
+ if (.@f % 2 == 0) {
+ .@menustr$+=.@ar$[.@f]+":";
+ } else {
+ array_push(.@vals, atoi(.@ar$[.@f]));
+ }
+ }
+ freeloop(false);
+
+ // Do the request
+ // We have: .@vals and .@menustr$
+ @menu = 255;
+ @menuret = -1;
+ select(.@menustr$);
+ //debugmes "Option %d", @menu;
+ //debugmes "Array size %d", getarraysize(.@vals);
+
+ if (@menu == 255)
+ return -1;
+
+ @menu-=1;
+ if (@menu < 0 || @menu > getarraysize(.@vals) - 1)
+ return -1;
+
+ @menuret = .@vals[@menu];
+ return @menuret;
+}
+