Page 1 of 2 1 2 LastLast
Results 1 to 10 of 19

Thread: Trivia Script

  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.

  2. #2
    Pretty cool, I like the fact you've got pre-set questions / answers that are quite random ^^

  3. #3
    Quote Originally Posted by SnakeRekon View Post
    Pretty cool, I like the fact you've got pre-set questions / answers that are quite random ^^
    Yea, although I could have made it more efficient. Right now it looks like a blob of mess :P

  4. #4
    hextraordinary Hex's Avatar
    Join Date
    Jun 2013
    Location
    Straya
    Posts
    2,906
    ahhh so confusing

  5. #5
    Big Cheese ShizGodsu's Avatar
    Join Date
    Jun 2013
    Location
    Italia!
    Posts
    1,977
    Reason why I don't bother learn to script. It hurts m eyes and gives me a headache .-.
    Roaming.

  6. #6
    Street Boss John's Avatar
    Join Date
    Jun 2013
    Location
    Lebanon
    Posts
    825
    Nice, but try not to loop it to death using setTimer(1);
    You can stop the looping using setTimer(0); in a function calling to end the event.
    -Johnaudi

  7. #7
    Street Boss John's Avatar
    Join Date
    Jun 2013
    Location
    Lebanon
    Posts
    825
    Oh btw, you can replace all the changeimgzoom() and showtext() functions with a single functions, like
    PHP Code:
    function putText(txt) {
      
    changeimgzoom(int);
      
    showtext(...);

    Would be much neater then rewriting everything so you can have a better debug sequence.
    -Johnaudi

  8. #8
    Quote Originally Posted by John View Post
    Nice, but try not to loop it to death using setTimer(1);
    You can stop the looping using setTimer(0); in a function calling to end the event.
    The setTimer is used to detect if a player is sitting in a chair so that they can see the screen if they're on an iPhone, iPod Touch, or a smaller android device. It hardly takes much capacity.

  9. #9
    Street Boss *Meister's Avatar
    Join Date
    Jun 2013
    Location
    Singapore
    Posts
    774
    Do you just type those scripts on Microsoft Word?
    I fight for equality. I fight for justice. I fight for the right thing.
    I fight therefore I am.

  10. #10
    Quote Originally Posted by *DaScientist View Post
    Do you just type those scripts on Microsoft Word?
    I use the class editor in RC. Otherwise, I use fp4's GS2 NPC Editor.

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
  •