Results 1 to 10 of 19

Thread: Trivia Script

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Trivia Script

    I made a Trivia script which I made for zone. Thought I might share it with you all!

    PHP Code:
    //Scripted by Graal801624 with help from the GraalOnline forums
    function getMultiIndex(temp.id) { //Get the index of a multidimensional array
      
    for (temp.0temp.this.playerWins.size(); temp.++) {
        if (
    this.playerWins[temp.i][0] == temp.id) {
          return 
    temp.i;
        }
      }
      return 
    "no";
    }
    function 
    onCreated() {
      
    this.30;
      
    this.12;
      
    setshape13232 );  //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(19821.617"Arial""","Q: " temp.question);
      
    showtext(19721.617"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(19821.617"Arial""","Q: " temp.question);
        
    showtext(19721.617"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(19821.617"Arial""","Q: " temp.question);
        
    showtext(19721.617"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(19821.617"Arial""",temp.question);
        
    showtext(19721.617"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(19821.617"Arial""","");
        
    showtext(19721.617"Arial""","");
        
    changeimgzoom(198.7);
        
    this.answer null;
        
    this.mode null;
      }
      if(
    player.chat=="/resetquestion" && player.clientr.isStaff) { //reset the trivia question
        
    showtext(19821.617"Arial""","");
        
    showtext(19721.617"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"5737);
        }
      }
      if (
    player.chat.trim().lower() in this.answer && this.mode != "guess") { //The player got it correct
        
    showtext(19821.616.3"Arial"""player.nick " has won the round.");
        
    showtext(19721.617.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(19821.616.3"Arial"""player.nick " has won the round.");
        
    showtext(19721.617.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.account1});
      }
      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(19821.617"Arial""",player.nick " has won the Trivia game!");
          
    showtext(19721.617"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";
        
    = (GUIContainer.clientwidth-320)/2;
        
    = (GUIContainer.clientheight-200)/2;
        new 
    GuiTextCtrl("EventTrivia_Text1") {
          
    profile GuiBlueTextProfile;
          
    height 20;
          
    text "Please fill out the  text boxes.";
          
    width 167;
          
    7;
        }
        new 
    GuiTextEditCtrl("EventTrivia_TextEdit1") {
          
    profile GuiBlueTextEditProfile;
          
    height 20;
          
    width 300;
          
    84;
          
    37;
        }
        new 
    GuiTextCtrl("EventTrivia_Text2") {
          
    profile GuiBlueTextProfile;
          
    height 20;
          
    text "Question";
          
    width 53;
          
    34;
        }
        new 
    GuiTextCtrl("EventTrivia_Text3") {
          
    profile GuiBlueTextProfile;
          
    height 20;
          
    text "Answer";
          
    width 42;
          
    74;
        }
        new 
    GuiTextEditCtrl("EventTrivia_TextEdit2") {
          
    profile GuiBlueTextEditProfile;
          
    height 20;
          
    width 300;
          
    84;
          
    77;
        }
        new 
    GuiButtonCtrl("EventTrivia_Button1") {
          
    profile GuiBlueButtonProfile;
          
    text "Submit Quesiton";
          
    width 385;
          
    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.520);
      } else {
        
    resetfocus();
      }
      
    setTimer(1);

    Last edited by The Doctor; 07-02-2013 at 03:18 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •