diff options
author | mekolat <mekolat@gmail.com> | 2015-01-25 12:44:19 -0500 |
---|---|---|
committer | mekolat <mekolat@gmail.com> | 2015-01-27 10:13:26 -0500 |
commit | e4bb0bf8863c08d8a8e2aa640003cc175e7d56a9 (patch) | |
tree | 5a02c7606ff44351ede15ce3594b08aeabe17511 /world | |
parent | fe8d009bbd05a8d856a33d149cf7647facf448a8 (diff) | |
download | serverdata-e4bb0bf8863c08d8a8e2aa640003cc175e7d56a9.tar.gz serverdata-e4bb0bf8863c08d8a8e2aa640003cc175e7d56a9.tar.bz2 serverdata-e4bb0bf8863c08d8a8e2aa640003cc175e7d56a9.tar.xz serverdata-e4bb0bf8863c08d8a8e2aa640003cc175e7d56a9.zip |
add Quiz and MultiQuiz
Diffstat (limited to 'world')
-rw-r--r-- | world/map/npc/functions/quiz.txt | 93 | ||||
-rw-r--r-- | world/map/npc/scripts.conf | 1 |
2 files changed, 94 insertions, 0 deletions
diff --git a/world/map/npc/functions/quiz.txt b/world/map/npc/functions/quiz.txt new file mode 100644 index 00000000..ea10a3c4 --- /dev/null +++ b/world/map/npc/functions/quiz.txt @@ -0,0 +1,93 @@ +function|script|MultiQuiz +{ + if((getarraysize(@quiz_answers$) != getarraysize(@quiz_questions$)) || + (@quiz_answers$[0] == "") || (@quiz_questions$[0] == "")) goto L_ArrayError; + set @setindex, 1; + set @index, rand(0,(getarraysize(@quiz_answers$) - 1)); + set @question$, @quiz_questions$[@index]; + mes "\""+ @question$ + "\""; + next; + mes "Pick the correct answer."; + callfunc "Quiz"; + return; + +L_ArrayError: + if(@quiz_answers$[0] == "") debugmes "@quiz_answers$ is empty"; + if(@quiz_questions$[0] == "") debugmes "@quiz_questions$ is empty"; + if(getarraysize(@quiz_answers$) != getarraysize(@quiz_questions$)) debugmes "Size of @quiz_answers$ is not equal to size of @quiz_questions$"; + mapexit; +} + +function|script|Quiz +{ + if((@choices_nr < 1) || (@choices_nr > 8)) set @choices_nr, 3; + if(@choices_nr > getarraysize(@quiz_answers$)) set @choices_nr, getarraysize(@quiz_answers$); + if(@quiz_answers$[0] == "") goto L_ArrayError; + set @success, 0; + if(@setindex < 1) set @index, @answer; + set @good, rand(0,(@choices_nr - 1)); + setarray @choices$, ""; + cleararray @choices$, "", getarraysize(@choices$); + set @loop, 0; + goto L_Shuffle; + +L_Shuffle: + set @nindex, rand(0,(getarraysize(@quiz_answers$) - 1)); + if(@nindex == @index) goto L_Shuffle; // do not get the good definition + set @loop2, 0; + goto L_Search; + +L_Search: + if(@choices$[@loop2] == @quiz_answers$[@nindex]) goto L_Shuffle; // array is already populated with this choice + if(@loop2 >= (@choices_nr - 1)) goto L_Shuffle2; + set @loop2, @loop2 + 1; + goto L_Search; + +L_Shuffle2: + set @choices$[@loop], @quiz_answers$[@nindex]; + if(@loop >= (@choices_nr - 1)) goto L_Answer; + set @loop, @loop + 1; + goto L_Shuffle; + +L_Answer: + set @choices$[@good], @quiz_answers$[@index]; // set the good definition + menu + @choices$[0], L_Enter, + @choices$[1], L_Enter, + @choices$[2], L_Enter, + @choices$[3], L_Enter, + @choices$[4], L_Enter, + @choices$[5], L_Enter, + @choices$[6], L_Enter, + @choices$[7], L_Enter; + +L_Enter: + if(@menu != (@good + 1)) goto L_Shift; + set @success, 1; + goto L_Shift; + +L_Shift: + if(@shift < @index) set @shift, @index; + + if(@shift == @index) set @quiz_answers$[@index], ""; // do not allow twice the same question + + if((@quiz_questions$[0] != "") && (@shift == @index)) set @quiz_questions$[@index], ""; + if((@quiz_questions$[0] != "") && (@quiz_questions$[(@shift + 1)] != "")) set @quiz_questions$[@shift], @quiz_questions$[(@shift + 1)]; + if((@quiz_questions$[0] != "") && (@quiz_questions$[(@shift + 1)] != "")) set @quiz_questions$[(@shift + 1)], ""; + + if(@quiz_answers$[(@shift + 1)] != "") set @quiz_answers$[@shift], @quiz_answers$[(@shift + 1)]; + if(@quiz_answers$[(@shift + 1)] != "") set @quiz_answers$[(@shift + 1)], ""; + + set @shift, @shift + 1; + if(@quiz_answers$[(@shift + 1)] != "") goto L_Shift; + set @shift, 0; + goto L_Close; + +L_Close: + set @answer, 0; + return; + +L_ArrayError: + if(@quiz_answers$[0] == "") debugmes "@quiz_answers$ is empty"; + mapexit; +} diff --git a/world/map/npc/scripts.conf b/world/map/npc/scripts.conf index 77e9c8a8..4be8d229 100644 --- a/world/map/npc/scripts.conf +++ b/world/map/npc/scripts.conf @@ -25,6 +25,7 @@ npc: npc/functions/undead_debug.txt npc: npc/functions/headstyles.txt npc: npc/functions/global_event_handler.txt npc: npc/functions/stat_reset.txt +npc: npc/functions/quiz.txt // Item Functions npc: npc/items/magic_gm_top_hat.txt |