This project is read-only.

quiz.js (java script) :)

Mar 22, 2014 at 10:17 PM
print(0,"quiz.js has been loaded correctly remake by: Oobe");



try { quiztxt = File.load("quiz.txt").split("\r\n"); } catch(e) { quiztxt = new Array(); }

if(quiztxt.length < 1) {

quiztxt.push("Q:Example question");
quiztxt.push("A:Example answer[or]Answer Example");

File.save("quiz.txt",quiztxt.join("\r\n"));
print(0,"quiz.txt now has been created, place questions and answer in: \x5CScripting\x5Cquiz\x2Ejs\x5CData\x5Cquiz\x2Etxt");
}

try{ template = File.load("quiz.ini").split("\r\n"); }catch(e){ template = new Array(); }

if(template.length < 1) {

template[0]="\u2591\u2591\u2591\u2591\u2591\u2591\u2591";
template[1]="\x5BQUIZ\x5D\u2591";
template[2]="\u2591\u2591\u2591\u2591\u2591\u2591\u2591";
template[3]="string=Please load some quiz questions first";
template[4]="string=Quiz has been started by +n - good luck!! :P";
template[5]="string=Quiz was stopped by +n";
template[6]="string=Or";
template[7]="string=Question +x of +y";
template[8]="string=(I) +q";
template[9]="string=Time's up!!";
template[10]="string=The answer was: +a";
template[11]="string=These people got the answer right:";
template[12]="string=(N) no one got the right answer (N)";
template[13]="string=(H) +n [+p points]";
template[14]="string=Well done +n, you answered first!! :)";
template[15]="string=Well done +n, you answered second!! :)";
template[16]="string=Well done +n, you answered correctly!! :)";
template[17]="string=Quiz has now finished - here are the final results!!";
template[18]="string=(N) no one got any of the questions right (N)";
template[19]="string=+n received +p points";
template[20]="string=(H) (H) (H) the winner is +n with +p points!! (H) (H) (H)";

File.save("quiz.ini",template.join("\r\n"));
print(0,"quiz.ini template has been created successfully");
}


var quizend = quiztxt.length;
var qcount = 1;
var restype = true;
var points = 3;
var quiztimer = 0;
var quizon = false;
var number = 0;
var dn = "";
var wn = "";
var PlayersOk = 0;
var cpts = new Array();
var splayers = true;

for (var calc = 0; calc < 100; calc++) {
    cpts[calc] = 0;
}

function onTextBefore(u, t) {

if(!restype) {

var answers = quiztxt[number].substr(2).split("[or]");

for(var o = 0;o < answers.length; o++) {

if(t.toLowerCase().search(answers[o].toLowerCase())!=-1) {
if(!u.tstr) {
 if(points == 1) {

  print(u,template[16].substr(7).replace(/\x2Bn/gi, u.name));

  u.tstr = true;
  correct.push(u.name);

  if(u.pts == null) {
   u.pts = 0;
  }

  u.pts = u.pts + points;
 }

 if(points == 2) {

  print(u,template[15].substr(7).replace(/\x2Bn/gi, u.name));
  u.tstr = true;
  correct.push(u.name);

  if(u.pts == null) {
   u.pts = 0;
  }


  u.pts = u.pts + points;
  points = points - 1;
 }


 if(points == 3) {
  print(u,template[14].substr(7).replace(/\x2Bn/gi, u.name));
  u.tstr = true;
  correct.push(u.name);

  if(u.pts == null) {
   u.pts = 0;
  }


  u.pts = u.pts + points;
  points = points - 1;
 }
}
}
}
}

return t;

}


function getScores() {
Users.local(function (P) {
    if (P.pts != null) {
        PlayersOk++;
        cpts[PlayersOk - 1] = P.pts;
    }
});
}


function onTimer() {

if(quizon) {

if(quiztimer >= 20 && number >= quizend) {
print(0,"");
print(0,template[17].substr(7));
print(0,"");
quiztimer = 0;
restype = true;
number = 0;
qcount = 1;
quizon = false;
getScores();

var ws = Math.max(cpts[0], cpts[1], cpts[2], cpts[3], cpts[4], cpts[5], cpts[6], cpts[7], cpts[8], cpts[9], cpts[10], cpts[11], cpts[12], cpts[13], cpts[14], cpts[15], cpts[16], cpts[17], cpts[18], cpts[19], cpts[20], cpts[21], cpts[22], cpts[23], cpts[24], cpts[25]);

if(PlayersOk < 1){
print(0, "");
print(0,template[18].substr(7));
print(0, "");

splayers = false;

}

if(splayers){

print(0, "");

Users.local(function(d){
 if(d.pts > 0 && d.pts != null) {

  print(0,template[19].substr(7).replace(/\x2Bn/gi, d.name).replace(/\x2Bp/gi, d.pts));
}


});
print(0, "")


}
Users.local(function(k)   {

            //get the winner
    if (k.pts == ws) {
        wn = k.name;
        dn = wn;
    }


});
Users.local(function(x){
                    //if game is a draw
    if (x.pts == ws && x.name != wn) {
        dn = dn + " & " + x.name;
    }
});

if(splayers){
    for(var fl=0;fl<5;fl++) {

 print(0,template[20].substr(7).replace(/\x2Bn/gi, dn).replace(/\x2Bp/gi, ws));

  }
}
}

if(quiztimer >= 20 && !restype) {
var thisanswer=quiztxt[number].substr(2).replace(/\x5B\x6F\x72\x5D/gi, " "+template[6].substr(7)+" ");
print(0,"");
print(0,template[9].substr(7));
print(0,"");
print(0,template[10].substr(7).replace(/\x2Ba/gi,thisanswer));
quiztimer = 0;
restype = true;
number++;
qcount++;
points = 3;

if(correct.length>0) {
print(0,"");
print(0,template[11].substr(7));
    print(0,"");
}

if(correct.length<1) {
print(0,"");
print(0,template[12].substr(7));
print(0,"");
}


for(var i=0;i<correct.length;i++) {
if(i == 0) {
 print(0, template[13].substr(7).replace(/\x2Bn/gi, correct[i]).replace(/\x2Bp/gi, "3"));
}
if(i == 1) {
 print(0, template[13].substr(7).replace(/\x2Bn/gi, correct[i]).replace(/\x2Bp/gi, "2"));
}
if(i > 1) {
 print(0, template[13].substr(7).replace(/\x2Bn/gi, correct[i]).replace(/\x2Bp/gi, "1"));
}
}

print(0,"");
}

if(quiztimer >= 20 && restype) {
if(quiztxt[number] != "") {
    print(0,"")
print(0,template[7].substr(7).replace(/\x2Bx/gi, qcount).replace(/\x2By/gi, quiztxt.length/2))
    print(0,"");
print(0,template[8].substr(7).replace(/\x2Bq/gi, quiztxt[number].substr(2)));
    print(0,"");
quiztimer = 0;
restype = false;
number++;
correct = new Array();
Users.local(function (c) {
    c.tstr = false;
});
}

if(quiztxt[number] == "") {
quiztimer = 20;
number = quizend+1;
}
}
}

quiztimer++;

}


function onCommand(u, cmd){

if(cmd.toLowerCase().search("game quiz") == 0 && u.level > 0) {
     if(cmd.toLowerCase().substr(10)=="start"){
if(quizon) {
// game in progress
}
if(!quizon) {
try {
quiztxt = File.load("quiz.txt").split("\r\n");
}
catch(e) {
quiztxt = new Array();
}
if(quiztxt[0] != null) {
print(0,template[4].substr(7).replace(/\x2Bn/gi, u.name));
quiztimer = 0;
number = 0;
quizend = quiztxt.length;
qcount = 1;
restype = true;
correct = new Array();
points = 3;
quizon = true;
splayers = true;
wn = "";
dn = "";
PlayersOk = 0;
cpts = new Array();
for (var calc = 0; calc < 100; calc++) {
cpts[calc] = 0;
}
}
else {
print(0,template[3].substr(7).replace(/\x2Bn/gi, u.name)+" - \x5CScripting\x5C"+scriptName()+"\x5CData\x5Cquiz.txt");
}
Users.local(function(m){
if(m.tstr) {
 m.pts = 0;
 m.tstr = false;
 }

});
}
}
if(cmd.toLowerCase().substr(10) == "stop"){
if(!quizon) {
// no game in progress

}else{
print(0,template[5].substr(7).replace(/\x2Bn/gi, u.name));
quizon = false;
}
}
}
}


function onHelp(u){
if(u.level > 0){
print(u, "#game quiz <start | stop>")
}
}