Little rough, I'm tired... but it works enjoy
//===== Script =========================================================================
//= Quizzer
//===== Made by: =======================================================================
//= Z3R0
//===== Current Version: ===============================================================
//= Version: 1.0
//===== Description: ===================================================================
//= rAthena Script Request
//= https://rathena.org/board/topic/112260-quest-npc-w-question-answer
//===== Additional Comments: ===========================================================
//= version 1.0: Initial Attempt
//======================================================================================
prontera,158,173,4 script Quizzer 92,{ doevent "quizzer_core::OnClick"; }
- script quizzer_core -1,{
// Function Declarations
function MesItem;
function ChkItem;
function ChkAnswer;
OnInit:
// ---------------------------------
// Configurable Settings
// ---------------------------------
// NPC Name to Display
set(.npc$, "[Quizzer]");
// Fee to Pay to Begin Quiz
set(.fee, 5000000);
// Show # of Question Player is On and Total number of questions?
set(.ShowQuestionProgress, 1);
// Number of Answers to Pass Quiz
set(.NumRightToPass, 8);
// Required Items Array (Pair: Item_ID, Item_Amount)
setarray(.required_items[0], 2256, 5); // Here you can setup multiple items in pairs.. (item_id, amount)
// Array of Questions (Each question must have a corresponding answer)
setarray(.questions$[0],
"What is the special source of energy used by ninjas ?",
"What is the name of the special eye of the Uchiha clan ?",
"What is the name of the secret village of the country of Fire ?",
"What is the prefered jutsu of Naruto ?",
"How many villages are there in total ?",
"What is the name of the 'star looking' weapon of the ninjas ?",
"What is the name of the ultimate warrior/ninja in a particular village ?",
"What is the name of Kiba's dog ?",
"Who is the master of Naruto, Sasuke and Sakura ?",
"What is the name of the nine-tailed demon fox ?"
);
// Array of Answers (Each Answer must have a corresponding Question)
setarray(.answers$[0],
"Chakra",
"Sharingan",
"Konoha",
"Kage bunshin no jutsu",
"10",
"Shuriken",
"Kage",
"Akamaru",
"Kakashi",
"Kurama"
);
// Array of Reward Item ID's
setarray(.rewards[0], 501, 502, 503, 504, 505, 506);
setarray(.rewards_effects$[0], "+10 STR HP", "+10 AGI HP", "+10 INT HP", "+10 LUK HP", "+10 VIT HP", "+10 DEX HP");
// STOP!!! DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING!!!!
// check .ShowQuestionProgress
if (.ShowQuestionProgress > 1) set(.ShowQuestionProgress, 1);
// Check .required_items
if (getarraysize(.required_items) % 2 != 0) {
set(.error, 1);
announce(strnpcinfo(0) + ": [ERROR] Invalid Number of Items in .required_items", bc_all, C_YELLOW); end();
}
if (getarraysize(.questions$) != getarraysize(.answers$)) {
set(.error, 1);
announce(strnpcinfo(0) + ": [ERROR] Invalid Number of Questions to Answers", bc_all, C_YELLOW); end();
}
if (getarraysize(.rewards) != getarraysize(.rewards_effects$)) {
set(.error, 1);
announce(strnpcinfo(0) + ": [ERROR] Invalid Number of Rewards to Reward Effects", bc_all, C_YELLOW); end();
}
set(.error, 0);
end();
// Player clicks the initial NPC
OnClick:
if (.error) {
mes("There was an error loading this script. Please contact your server administrator");
close();
}
if (quizzer & 8) {
mes("You have already completed this trial.");
close();
}
else if (quizzer & 4) doevent("quizzer_core::OnComplete");
else if (quizzer & 2) doevent("quizzer_core::OnQuiz");
else if (quizzer & 1) doevent("quizzer_core::OnHunt");
else doevent("quizzer_core::OnStart");
end();
OnStart:
mes(.npc$);
if (.fee) {
mes("You will need " + .fee + " zeny to start this trial.");
mes("Are you ready to proceed?");
next();
switch(select("Yes:No")) {
case 1:
if (Zeny < .fee) {
mes("You do not have enough zeny to start this trial.");
close();
}
set(Zeny, Zeny - .fee);
set(quizzer, 1);
mes("I need you to gather these items:");
for(.@i = 0; .@i < getarraysize(.required_items); .@i+=2) {
mes( MesItem(.required_items, .@i) );
}
mes("I await your return");
close();
case 2:
default:
mes("I knew you weren't capable!");
close();
}
}
OnHunt:
mes(.npc$);
// Determine if they have completed all the required items...
mes("Checking Requirement Status:");
for(.@i = 0; .@i < getarraysize(.required_items); .@i+=2) {
mes(MesItem(.required_items, .@i) + " - " + ChkItem(.required_items[.@i], .required_items[.@i+1]));
}
if (@quizzer_no_items == 1) {
mes("You do not have enough items... You fail!");
set(@quizzer_no_items, 0);
close();
}
// Passed let's remove the items
for(.@i = 0; .@i < getarraysize(.required_items); .@i+=2) {
delitem .required_items[.@i], .required_items[.@i+1];
}
mes("Success! You may now start the quiz!");
next();
set(quizzer, quizzer^2);
doevent("quizzer_core::OnQuiz");
end();
OnQuiz:
mes(.npc$);
.@num_right = 0;
for(.@i = 0; .@i < getarraysize(.questions$); .@i++) {
if (.ShowQuestionProgress) {
mes("Question #" + (.@i+1) + " / " + getarraysize(.questions$));
}
mes(.questions$[.@i]);
input .player_answers$[.@i];
// Let's compare the answer :D
.@num_right += ChkAnswer(.answers$[.@i], .player_answers$[.@i]);
mes("Answer Recorded. Next Question");
next();
}
if (.@num_right >= .NumRightToPass) {
set(quizzer, quizzer^4);
mes("You have passed the quiz!");
next();
doevent("quizzer_core::OnComplete");
end();
}
mes("You did not pass the quiz!");
close();
OnComplete:
mes(.npc$);
mes("Well Done Old Chap!");
mes("Please select from the following rewards");
set(.@menu$, "");
for(.@i = 0; .@i < getarraysize(.rewards); .@i++) {
set(.@menu$, .@menu$ + getitemname(.rewards[.@i]) + " (" + .rewards_effects$[.@i] + "):");
}
getitem .rewards[select(.@menu$) - 1], 1;
set(quizzer, quizzer^8);
mes("Thank you for participating");
close();
// getarg(0) = Array
// getarg(1) = Index
function MesItem {
.@item_id = getelementofarray(getarg(0), getarg(1));
.@item_amount = getelementofarray(getarg(0), getarg(1) + 1);
return .@item_amount + ( .@item_amount > 1 ? "x" : "") + " " + getitemname(.@item_id);
}
// getarg(0) = item_id
// getarg(1) = amount required
function ChkItem {
.@has = countitem(getarg(0));
if (.@has >= getarg(1)) {
return "^000000" + .@has + "^000000/^000000" + getarg(1) + "^000000";
}
set(@quizzer_no_items, 1);
return "^FF0000" + .@has + "^000000/^000000" + getarg(1) + "^000000";
}
// getarg(0) = Answer
// getarg(1) = Player Answer
function ChkAnswer {
if (getarg(0) == getarg(1)) return 1;
else if (strtoupper(getarg(0)) == getarg(1)) return 1;
else if (strtolower(getarg(0)) == getarg(1)) return 1;
else return 0;
}
}