summaryrefslogtreecommitdiff
path: root/npc/functions/riddle.txt
diff options
context:
space:
mode:
authorSaulc <lucashelaine14@gmail.com>2018-01-13 20:50:42 +0100
committerSaulc <lucashelaine14@gmail.com>2018-01-13 20:50:42 +0100
commit20df2abc1aca00d6aa5dc78347133890f36b32f3 (patch)
tree4ad4a8bb8b0605473a702e314799a4626347721a /npc/functions/riddle.txt
downloadserverdata-20df2abc1aca00d6aa5dc78347133890f36b32f3.tar.gz
serverdata-20df2abc1aca00d6aa5dc78347133890f36b32f3.tar.bz2
serverdata-20df2abc1aca00d6aa5dc78347133890f36b32f3.tar.xz
serverdata-20df2abc1aca00d6aa5dc78347133890f36b32f3.zip
Initial commit
Diffstat (limited to 'npc/functions/riddle.txt')
-rw-r--r--npc/functions/riddle.txt74
1 files changed, 74 insertions, 0 deletions
diff --git a/npc/functions/riddle.txt b/npc/functions/riddle.txt
new file mode 100644
index 000000000..fb503e3b3
--- /dev/null
+++ b/npc/functions/riddle.txt
@@ -0,0 +1,74 @@
+// Evol functions.
+// Author:
+// Reid
+// Description:
+// Riddle enigma validator
+//
+// Arguments
+// 0 PC answer
+// 1 English correct answer
+// 2 Translated correct answer
+
+// TODO: levenshtein(), similar_text(), and maybe even soundex()
+
+function script riddlevalidation {
+ .@answer$ = strtolower(getarg(0));
+ .@good$ = strtolower(getarg(1));
+ .@good_translated$ = strtolower(getarg(2));
+
+ .@size_answer = getstrlen(.@answer$);
+ .@size_good = getstrlen(.@good$);
+ .@size_good_translated = getstrlen(.@good_translated$);
+
+ .@max = max(.@size_answer, .@size_good_translated, .@size_good);
+
+ // Input is too long.
+ if (.@max > 20)
+ {
+ return false;
+ }
+
+ .@size_good *= 70;
+ .@size_good_translated *= 70;
+
+ for (.@i = 0; .@i < .@max; .@i++)
+ {
+ .@correct = 0;
+ .@correct_translated = 0;
+
+ for (.@k = .@k_translated = .@j = .@i; .@j < .@max; .@j++)
+ {
+ if (charat(.@answer$, .@j) == charat(.@good$, .@k))
+ {
+ .@correct++;
+ .@k++;
+ }
+ else
+ {
+ .@correct--;
+ }
+
+ if (charat(.@answer$, .@j) ==
+ charat(.@good_translated$, .@k_translated))
+ {
+ .@correct_translated++;
+ .@k_translated++;
+ }
+ else
+ {
+ .@correct_translated--;
+ }
+ }
+ // if 70% of the word is correct
+ .@correct *= 100;
+ .@correct_translated *= 100;
+
+ if (.@correct >= .@size_good ||
+ .@correct_translated >= .@size_good_translated)
+ {
+ return true;
+ }
+ }
+
+ return false;
+}