summaryrefslogtreecommitdiff
path: root/npc/functions
diff options
context:
space:
mode:
authorJesusaves <cpntb1@ymail.com>2018-12-29 00:25:41 -0200
committerJesusaves <cpntb1@ymail.com>2018-12-29 00:25:41 -0200
commit7158527c6dd52434bf72157b03cfc68a7a911439 (patch)
tree1c93606d9338f7b1a83e3b27f622366a3aea30ec /npc/functions
parentbd24967a5b00c323288fcda573e7b703301f3208 (diff)
downloadserverdata-7158527c6dd52434bf72157b03cfc68a7a911439.tar.gz
serverdata-7158527c6dd52434bf72157b03cfc68a7a911439.tar.bz2
serverdata-7158527c6dd52434bf72157b03cfc68a7a911439.tar.xz
serverdata-7158527c6dd52434bf72157b03cfc68a7a911439.zip
Minor rewrite to Riddle System
Diffstat (limited to 'npc/functions')
-rw-r--r--npc/functions/riddle.txt35
1 files changed, 15 insertions, 20 deletions
diff --git a/npc/functions/riddle.txt b/npc/functions/riddle.txt
index fb503e3b3..4ccde67d8 100644
--- a/npc/functions/riddle.txt
+++ b/npc/functions/riddle.txt
@@ -12,9 +12,9 @@
// TODO: levenshtein(), similar_text(), and maybe even soundex()
function script riddlevalidation {
- .@answer$ = strtolower(getarg(0));
- .@good$ = strtolower(getarg(1));
- .@good_translated$ = strtolower(getarg(2));
+ .@answer$ = strip(strtolower(getarg(0)));
+ .@good$ = strip(strtolower(getarg(1)));
+ .@good_translated$ = strip(strtolower(getarg(2)));
.@size_answer = getstrlen(.@answer$);
.@size_good = getstrlen(.@good$);
@@ -23,14 +23,15 @@ function script riddlevalidation {
.@max = max(.@size_answer, .@size_good_translated, .@size_good);
// Input is too long.
- if (.@max > 20)
- {
+ if (.@max > 30) {
return false;
}
- .@size_good *= 70;
- .@size_good_translated *= 70;
+ // if 90% of the word is correct
+ .@size_good *= 90;
+ .@size_good_translated *= 90;
+ freeloop(true);
for (.@i = 0; .@i < .@max; .@i++)
{
.@correct = 0;
@@ -38,24 +39,17 @@ function script riddlevalidation {
for (.@k = .@k_translated = .@j = .@i; .@j < .@max; .@j++)
{
- if (charat(.@answer$, .@j) == charat(.@good$, .@k))
- {
+ if (charat(.@answer$, .@j) == charat(.@good$, .@k)) {
.@correct++;
.@k++;
- }
- else
- {
+ } else {
.@correct--;
}
- if (charat(.@answer$, .@j) ==
- charat(.@good_translated$, .@k_translated))
- {
+ if (charat(.@answer$, .@j) == charat(.@good_translated$, .@k_translated)) {
.@correct_translated++;
.@k_translated++;
- }
- else
- {
+ } else {
.@correct_translated--;
}
}
@@ -64,11 +58,12 @@ function script riddlevalidation {
.@correct_translated *= 100;
if (.@correct >= .@size_good ||
- .@correct_translated >= .@size_good_translated)
- {
+ .@correct_translated >= .@size_good_translated) {
+ freeloop(false);
return true;
}
}
+ freeloop(false);
return false;
}