Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Question box script (https://forums.graalonline.com/forums/showthread.php?t=134267522)

Gunderak 12-08-2012 06:24 AM

Question box script
 
Hey, i'm trying to make a question prompt that basically pops up with a question, this is in a class. So then if I want to ask the player a question I just join the NPC or weapon to the class and call the method.
I can't figure out how to get the answer back. In C# you do something like this. Here is the NPC.
PHP Code:

function onCreated(){
  
temp.qu AskQuestion("This is a title""This is a question");
  if(
qu){
    
this.chat "It's true!";
  }else{
    
this.chat "It's not true!";
  }


Here is the class.
PHP Code:

//#CLIENTSIDE
function AskQuestion(titlequestion) {
  new 
GuiWindowCtrl("QUESTION_WINDOW") {
    
profile GuiBlueWindowProfile;
    
clientrelative true;
    
clientextent "222,99";

    
canclose false;
    
canmaximize false;
    
canminimize false;
    
canmove true;
    
canresize true;
    
closequery false;
    
destroyonhide false;
    
text title;
    
1093;
    
646;

    new 
GuiButtonCtrl("QUESTION_YES") {
      
profile GuiBlueButtonProfile;
      
text "Yes";
      
width 116;
      
69;
    }
    new 
GuiButtonCtrl("QUESTION_NO") {
      
profile GuiBlueButtonProfile;
      
text "No";
      
width 107;
      
115;
      
69;
    }
    new 
GuiScrollCtrl("QUESTION_SCROLL") {
      
profile GuiBlueScrollProfile;
      
height 68;
      
hscrollbar "dynamic";
      
vscrollbar "dynamic";
      
width 225;

      new 
GuiMLTextCtrl("QUESTION_MULTILINE") {
        
profile GuiBlueMLTextProfile;
        
height 34;
        
horizsizing "width";
        
text question;
        
width 200;
      }
    }
  }
}
function 
QUESTION_YES.onAction() {
  
QUESTION_WINDOW.destroy();
  return 
true;
}

function 
QUESTION_NO.onAction() {
  
QUESTION_WINDOW.destroy();
  return 
false;


Cheers.

BlueMelon 12-08-2012 12:24 PM

Try using scheduleevent() when they answer your question

Gunderak 12-08-2012 12:35 PM

So have AskQuestion(); then also have another function to get the results?

BlueMelon 12-08-2012 07:49 PM

Exactly. I would use catchevent() to catch the button clicks on both buttons and send them to 1 method which would call the event.

Tigairius 12-09-2012 12:17 AM

You could probably do this, I commented the changes.

PHP Code:

function AskQuestion(titlequestion) {
  
this.ans false;
  
  new 
GuiWindowCtrl("QUESTION_WINDOW") {
    
profile GuiBlueWindowProfile;
    
clientrelative true;
    
clientextent "222,99";

    
canclose false;
    
canmaximize false;
    
canminimize false;
    
canmove true;
    
canresize true;
    
closequery false;
    
destroyonhide false;
    
    
// added visible = true so it shows for new messages
    
visible true;
    
text title;
    
1093;
    
646;

    new 
GuiButtonCtrl("QUESTION_YES") {
      
profile GuiBlueButtonProfile;
      
text "Yes";
      
width 116;
      
69;
      
      
// catch the buttonclick event and send it to onButtonClick
      
thiso.catchEvent(this"onAction""onButtonClick");
    }
    new 
GuiButtonCtrl("QUESTION_NO") {
      
profile GuiBlueButtonProfile;
      
text "No";
      
width 107;
      
115;
      
69;
      
      
// catching the buttonclick event and send it to onButtonClick
      
thiso.catchEvent(this"onAction""onButtonClick");
    }
    new 
GuiScrollCtrl("QUESTION_SCROLL") {
      
profile GuiBlueScrollProfile;
      
height 68;
      
hscrollbar "dynamic";
      
vscrollbar "dynamic";
      
width 225;

      new 
GuiMLTextCtrl("QUESTION_MULTILINE") {
        
profile GuiBlueMLTextProfile;
        
height 34;
        
horizsizing "width";
        
text question;
        
width 200;
      }
    }
  }
  
  
// wait until the window is hidden 
  
waitfor(QUESTION_WINDOW"onHide");

  return 
this.ans;
}

function 
onButtonClick(obj) {
  
this.ans obj.text != "No";
  
QUESTION_WINDOW.hide();


Seems like déjÃ* vu.

Gunderak 12-09-2012 11:26 AM

Cheers Tig, wasn't even aware Graal had a waitfor method.


All times are GMT +2. The time now is 09:23 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.