From 7158527c6dd52434bf72157b03cfc68a7a911439 Mon Sep 17 00:00:00 2001 From: Jesusaves Date: Sat, 29 Dec 2018 00:25:41 -0200 Subject: Minor rewrite to Riddle System --- npc/functions/riddle.txt | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) (limited to 'npc/functions') 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; } -- cgit v1.2.3-70-g09d2