PHP Code:
//Scripted by Graal801624 with help from the GraalOnline forums
function getMultiIndex(temp.id) { //Get the index of a multidimensional array
for (temp.i = 0; temp.i < this.playerWins.size(); temp.i ++) {
if (this.playerWins[temp.i][0] == temp.id) {
return temp.i;
}
}
return "no";
}
function onCreated() {
this.x = 30;
this.y = 12;
setshape( 1, 32, 32 ); //set the shape of the npc for triggers
setImg("no-shield.png");
}
function onActionTrivia(temp.question,temp.answer,temp.acc) {
//Ask the question if they say /trivia
temp.answer = temp.answer.lower();
temp.answer = temp.answer.tokenize(",");
showtext(198, 21.6, 17, "Arial", "","Q: " @ temp.question);
showtext(197, 21.6, 17, "Arial", "","");
changeimgzoom(198, .7);
this.answer = temp.answer.trim();
}
function onPlayerChats() {
if(player.chat == "/mult" && player.clientr.isStaff) { //multiplication
temp.rchar1 = int(random(1,30)); //selects random integers for multiplication
temp.rchar2 = int(random(1,30));
temp.question = "Solve: " @temp.rchar1 @ "*" @ temp.rchar2 @ "="; //sets the question
this.answer = {temp.rchar1 * temp.rchar2}; //sets the answer
showtext(198, 21.6, 17, "Arial", "","Q: " @ temp.question);
showtext(197, 21.6, 17, "Arial", "","");
changeimgzoom(198, .7);
this.mode = "";
}
if(player.chat == "/add" && player.clientr.isStaff) {
temp.rchar1 = int(random(1,100)); //selects integers for addition
temp.rchar2 = int(random(1,100));
temp.question = "Solve: " @temp.rchar1 @ "+" @ temp.rchar2 @ "=";
this.answer = {temp.rchar1 + temp.rchar2};
showtext(198, 21.6, 17, "Arial", "","Q: " @ temp.question);
showtext(197, 21.6, 17, "Arial", "","");
changeimgzoom(198, .7);
this.mode = "";
}
if(player.chat == "/guess" && player.clientr.isStaff) { //sets the guessing mode for guessing numbers
temp.rchar = int(random(1,1000)); //random integer from 1-1000
temp.question = "Guess a number 1-1000.";
this.answer = temp.rchar;
showtext(198, 21.6, 17, "Arial", "",temp.question);
showtext(197, 21.6, 17, "Arial", "","");
changeimgzoom(198, .7);
this.mode = "guess";
}
if(player.chat=="/score") { //If they player wants his score
temp.plArr = getMultiIndex(player.account);
DB_Messages.sendNPCPM({findPlayerByCommunityname(player.account)}, "My Score: " @ this.playerWins[temp.plArr][1] @ "/5 win(s)."); //for iOS servers, sending a PM
}
if(player.chat=="/scores" && player.clientr.isStaff) { //If they player wants his score
DB_Messages.sendNPCPM({findPlayerByCommunityname(player.account)}, this.playerWins);
}
if(player.chat=="/resetgame" && player.clientr.isStaff) { //reset the trivia
showtext(198, 21.6, 17, "Arial", "","");
showtext(197, 21.6, 17, "Arial", "","");
changeimgzoom(198, .7);
this.answer = null;
this.mode = null;
}
if(player.chat=="/resetquestion" && player.clientr.isStaff) { //reset the trivia question
showtext(198, 21.6, 17, "Arial", "","");
showtext(197, 21.6, 17, "Arial", "","");
changeimgzoom(198, .7);
this.answer = null;
this.mode = null;
}
if(player.chat=="/kickall" && player.clientr.isStaff) { //Kick all from event
for(temp.pl : allplayers) {
if (temp.pl.level.name != "sky_event-trivia.nw" || temp.pl.clientr.isStaff == 1) continue;
pl.setlevel2("shangri_sky_d05.nw", 57, 37);
}
}
if (player.chat.trim().lower() in this.answer && this.mode != "guess") { //The player got it correct
showtext(198, 21.6, 16.3, "Arial", "", player.nick @ " has won the round.");
showtext(197, 21.6, 17.3, "Arial", "","Answers: " @ this.answer);
changeimgzoom(198, .7);
changeimgzoom(197, .7);
this.answer = null;
playerWon();
}
if (player.chat > this.answer && this.mode == "guess") {
say2("Guess a smaller number!");
}
if (player.chat < this.answer && this.mode == "guess") {
say2("Guess a bigger number!");
}
if (player.chat == this.answer && this.mode == "guess") {
showtext(198, 21.6, 16.3, "Arial", "", player.nick @ " has won the round.");
showtext(197, 21.6, 17.3, "Arial", "","Answer: " @ this.answer);
changeimgzoom(198, .7);
changeimgzoom(197, .7);
this.mode = null;
this.answer = null;
playerWon();
}
}
function playerWon() {
if(getMultiIndex(player.account) == "no") { //If the account is already in the array
this.playerWins.add({player.account, 1});
}
else { //If the account isn't in the array
temp.plArr = getMultiIndex(player.account);
this.playerWins[temp.plArr][1]++;
if(this.playerWins[temp.plArr][1] == 5) { //The player gets five wins
this.playerWins = null;
showtext(198, 21.6, 17, "Arial", "",player.nick @ " has won the Trivia game!");
showtext(197, 21.6, 17, "Arial", "","");
changeimgzoom(198, .7);
player.setLevel2("sky_event-trivia.nw",12,16);
}
}
}
//#CLIENTSIDE
function onPlayerChats() {
if (player.chat=="/trivia" && player.guild=="Events Team") {
showTriviaGUI();
}
}
function showTriviaGUI() { //The trivia GUI
new GuiWindowCtrl("EventTrivia_Window1") {
profile = GuiBlueWindowProfile;
style = $pref::Video::defaultguistyle;
clientrelative = true;
clientextent = "384,164";
canmaximize = false;
canminimize = false;
canmove = true;
canclose = false;
canresize = false;
closequery = false;
destroyonhide = false;
text = "Trivia";
x = (GUIContainer.clientwidth-320)/2;
y = (GUIContainer.clientheight-200)/2;
new GuiTextCtrl("EventTrivia_Text1") {
profile = GuiBlueTextProfile;
height = 20;
text = "Please fill out the text boxes.";
width = 167;
x = 7;
}
new GuiTextEditCtrl("EventTrivia_TextEdit1") {
profile = GuiBlueTextEditProfile;
height = 20;
width = 300;
x = 84;
y = 37;
}
new GuiTextCtrl("EventTrivia_Text2") {
profile = GuiBlueTextProfile;
height = 20;
text = "Question";
width = 53;
y = 34;
}
new GuiTextCtrl("EventTrivia_Text3") {
profile = GuiBlueTextProfile;
height = 20;
text = "Answer";
width = 42;
y = 74;
}
new GuiTextEditCtrl("EventTrivia_TextEdit2") {
profile = GuiBlueTextEditProfile;
height = 20;
width = 300;
x = 84;
y = 77;
}
new GuiButtonCtrl("EventTrivia_Button1") {
profile = GuiBlueButtonProfile;
text = "Submit Quesiton";
width = 385;
y = 134;
}
}
}
function EventTrivia_Button1.onAction() { //If the button is pressed
temp.question = EventTrivia_TextEdit1.text;
temp.answer = EventTrivia_TextEdit2.text;
temp.acc = player.account;
EventTrivia_Window1.destroy();
triggeraction(this.x,this.y,"Trivia",temp.question,temp.answer,temp.acc);
}
function onCreated() onTimeout(); //Focus the chairs to the question
function onTimeout() {
if (player.ani == "sit" || client.isfocus) {
setfocus(30.5, 20);
} else {
resetfocus();
}
setTimer(1);
}