Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 04-28-2008, 10:51 PM
Bell Bell is offline
Registered User
Bell's Avatar
Join Date: Feb 2007
Posts: 1,824
Bell has much to be proud ofBell has much to be proud ofBell has much to be proud ofBell has much to be proud ofBell has much to be proud ofBell has much to be proud ofBell has much to be proud of
-Dialog.txt

For those of you that use party dialog, Novo thought you might find this to be a little more efficient and useful than the standard methods normally used.
PHP Code:
/**
 * Dialog System asks for the user to select an option
 * then returns the value of the selected option.
 *
 * Also allows asking other players.
 *
 * @author Novo
 * @date 27/04/08
 *
 * How to use:
 *  findweapon("-Dialog").openDialog( "Window Title", "Message", {"Options", "Or", {"assoc", "Associative Values"} } );
 *  findweapon("-Dialog").openDialogList( "Window Title", "Message", {"Options", "Or", {"assoc", "Associative Values"} } );
 *  findweapon("-Dialog").openExternalDialog( "Player", "Window Title", "Message", {"Options", "Or", {"assoc", "Associative Values"} } );
 *  findweapon("-Dialog").openExternalDialogList( "Player", "Window Title", "Message", {"Options", "Or", {"assoc", "Associative Values"} } );
 *
 */

/**
 * Mediates between client and server
 */
function onactionserverside( cmd, dialog, pl, title, msg, options ) {
  switch ( 
cmd ) {
    case 
"dialog": case "dialogList":
      
temp.replyTo = player.account;
      
with ( findPlayer( pl ) ) {
        
triggerclient( "gui", "-Dialog", cmd, dialog, temp.replyTo, title, msg, options );
      }
    break;
    case 
"replyDialog":
      
with ( findplayer( pl ) ) {
        
triggerclient( "gui", "-Dialog", "replyDialog", dialog, params[3] );
      }
    break;
  }
}

//#CLIENTSIDE
/**
 * Mediates between server and client
 */
function onactionclientside( cmd, dialog, pl, title, msg, options ) {
  switch ( 
cmd ) {
    case 
"dialog":
      
temp.reply = openDialog( title, msg, options );
      
triggerserver("gui", name, "replyDialog", dialog, pl, temp.reply );
    break;
    case 
"dialogList":
      
temp.reply = openDialogList( title, msg, options );
      
triggerserver("gui", name, "replyDialog", dialog, pl, temp.reply );
    break;
    case 
"replyDialog":
      
Reply( dialog, params[2] );
    break;
  }
}

/**
 * Opens a Dialog in another player. (Buttons)
 *
 * @param pl
 *   Player's Account you want
 * @param title
 *   Dialog's Title.
 * @param msg
 *   Message Asked
 * @param options
 *   An array of values ( format: {{value, text}, ...} or {text, ...}
 *
 * @return
 *   Option selected
 */
public function openExternDialog( pl, title, msg, options ) {
  
this.dialogCount ++;
  
temp.dialog = this.dialogCount;

  
triggerserver("gui", name, "dialog", temp.dialog, pl, title, msg, options );

  
// Wait until there is a reply.
  
waitfor( this, "onReplied"@ temp.dialog );
  
  
// Return reply!
  
return GetReply( temp.dialog );
}

/**
 * Opens Dialog in another player ( List )
 *
 * @see openExternalDialog
 */
public function openExternDialogList( pl, title, msg, options ) {
  
this.dialogCount ++;
  
temp.dialog = this.dialogCount;

  
triggerserver("gui", name, "dialogList", temp.dialog, pl, title, msg, options );

  
// Wait until there is a reply.
  
waitfor( this, "onReplied"@ temp.dialog );
  
  
// Return reply!
  
return GetReply( temp.dialog );
}

/**
 * Opens a dialog and returns answer
 *
 * @see openExternalDialog
 */
public function openDialog( title, msg, options ) {
  
// No options!
  
if ( options.size() < 1 )
    return 
null;

  
// One Option? You call that an Option?
  
if ( options.size() == 1 ) {
    if ( 
options[0].type() == 3 )
      return 
options[0][0];
    return 
options[0];
  }

  
this.dialogCount ++; // Unique Dialog ID
  
temp.dialog = this.dialogCount;
  
// Conflicting Dialog? ( Happens when you update the code )
  
if ( isObject( "Dialog_"@ this.dialogCount ) )
    (
"Dialog_"@ this.dialogCount ).destroy();

  new 
GuiWindowCtrl( "Dialog_"@ temp.dialog ) {
    
this.text = title;
    
this.dialog = temp.dialog;
    
extent = {50 + 50 * options.size(), 80};
    
position = { (GraalControl.width - this.width) / 2, (GraalControl.height - this.height) / 2 };
    new 
GuiMLTextCtrl( "DialogMessage_"@ this.dialog ) {
      
x = 15;
      
y = 20;
      
this.text = msg;
    }

    for ( 
temp.i = 0; temp.i < options.size(); temp.i ++ ) {
      new 
GuiButtonCtrl( "DialogButton_"@ this.dialog @"_"@ temp.i ) {
        
y = 40;
        
x = 25 + 50 * temp.i;
        
width = 45;

        
this.dialog = temp.dialog;
        if ( 
options[ temp.i ].type() == 3 ) {
          
this.option = options[ temp.i ][0];
          
this.text = options[ temp.i ][1];
        } else {
          
this.option = options[ temp.i ];
          
this.text = options[ temp.i ];
        }

        
thiso.catchevent( this.name, "onAction", "onReply" );
      }
    }
  }

  
// Wait until there is a reply.
  
waitfor( this, "onReplied"@ temp.dialog );
  
  
// Return reply!
  
return GetReply( temp.dialog );
}

/**
 * Opens Dialog List
 *
 * @see openExternalDialogList
 */
public function openDialogList( title, msg, options ) {
  
// No options!
  
if ( options.size() < 1 )
    return 
null;

  
// One Option? You call that an Option?
  
if ( options.size() == 1 ) {
    if ( 
options[0].type() == 3 )
      return 
options[0][0];
    return 
options[0];
  }

  
this.dialogCount ++; // Unique Dialog ID
  
temp.dialog = this.dialogCount;
  
// Conflicting Dialog? ( Happens when you update the code )
  
if ( isObject( "Dialog_"@ this.dialogCount ) )
    (
"Dialog_"@ this.dialogCount ).destroy();

  new 
GuiWindowCtrl( "Dialog_"@ temp.dialog ) {
    
this.text = title;
    
this.dialog = temp.dialog;
    
extent = { 300, 330};
    
position = { (GraalControl.width - this.width) / 2, (GraalControl.height - this.height) / 2 };
    new 
GuiMLTextCtrl( "DialogMessage_"@ this.dialog ) {
      
x = 15;
      
y = 20;
      
this.text = msg;
    }

    new 
GuiScrollCtrl( "DialogScroll_"@ temp.dialog ) {
      
position = {10, 40};
      
extent = {280, 280};
      
vscrollbar = "dynamic";
      
hscrollbar = "dynamic";

      new 
GuiTextListCtrl( "DialogList_"@ temp.dialog ) {
        
extent = {280, 280};
        
fitparentwidth = true;
        
this.dialog = temp.dialog;

        
thiso.catchevent( this.name, "onDblClick", "onReplyList" );
      }
    }
  }
  
  (
"DialogList_"@ temp.dialog ).clearrows();
  for ( 
temp.i = 0; temp.i < options.size(); temp.i ++ ) {
    if ( 
options[ temp.i ].type() == 3 ) {
      
temp.option = options[ temp.i ][0];
      
temp.msg = options[ temp.i ][1];
    } else {
      
temp.option = options[ temp.i ];
      
temp.msg = options[ temp.i ];
    }

    
with ( ("DialogList_"@ temp.dialog ).addRow( 0, temp.msg ) ) {
      
this.dialog = temp.dialog;
      
this.option = temp.option;
    }
  }

  
// Wait until there is a reply.
  
waitfor( this, "onReplied"@ temp.dialog );
  
  
// Return reply!
  
return GetReply( temp.dialog );
}

/**
 * Used for replies using list object
 */
function onReplyList( gui, entryid, entrytext, entryindex ) {
  
temp.dialog = gui.dialog;
  
temp.response = gui.rows[ entryindex ].option;

  
// Dispose of GUI
  
("Dialog_"@ temp.dialog ).destroy();

  
// Send the response
  
Reply( temp.dialog, temp.response );
}

/**
 * Used for replies using buttons
 */
function onReply( gui ) {
  
temp.response = gui.option;
  
temp.dialog = gui.dialog;

  
// Dispose of GUI
  
("Dialog_"@ temp.dialog ).destroy();

  
// Send the response
  
Reply( temp.dialog, temp.response );
}

/**
 * Main reply module
 *
 * Sets and triggers reply event
 */
function Reply( dialog, reply ) {
  
this.(@"reply_"@ dialog ) = reply;

  
// This allows 'waitfor' to stop it's wait
  
trigger("onReplied"@ dialog, "" );
}

/**
 * Returns the answer of a given dialog
 */
function GetReply( dialog ) {
  return 
this.(@"reply_"@ dialog );
} 
__________________
For support contact
http://support.toonslab.com/

Last edited by Skyld; 04-28-2008 at 11:15 PM.. Reason: Adding PHP tags for clarity
Reply With Quote
  #2  
Old 04-29-2008, 04:05 AM
Desear Desear is offline
Live to Laugh
Desear's Avatar
Join Date: Apr 2008
Location: MD
Posts: 345
Desear is on a distinguished road
Send a message via AIM to Desear Send a message via MSN to Desear
Very nice.
__________________
"Ha Bros before Ho's."
Reply With Quote
  #3  
Old 04-29-2008, 08:16 PM
Dan Dan is offline
Daniel
Join Date: Oct 2007
Posts: 383
Dan is an unknown quantity at this point
Send a message via MSN to Dan
Nice.
__________________
Reply With Quote
  #4  
Old 04-29-2008, 08:42 PM
[email protected] sid.gottlieb@googlemail.com is offline
Banned
Join Date: Mar 2008
Posts: 861
sid.gottlieb@googlemail.com will become famous soon enough
I like, nice idea Novo! :: high five ::
Reply With Quote
  #5  
Old 04-30-2008, 12:58 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Aww, Skyld deleted my post

stupid non-scripting pwas!!!!!!!

Also, it looks nice, but I don't get exactly what you mean by "party dialog".
__________________

Last edited by Tolnaftate2004; 04-30-2008 at 07:23 PM.. Reason: Moved.
Reply With Quote
  #6  
Old 04-30-2008, 01:09 AM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
PHP Code:
    case "dialog": case "dialogList":
      
temp.replyTo = player.account;
      
with ( findPlayer( pl ) ) {
        
triggerclient( "gui", "-Dialog", cmd, dialog, temp.replyTo, title, msg, options );
      }
    break; 
More efficent to do:

PHP Code:
    case "dialog": case "dialogList":
      
with ( findPlayer( pl ) ) {
        
triggerclient( "gui", "-Dialog", cmd, dialog, playero.account, title, msg, options );
      }
    break; 
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #7  
Old 04-30-2008, 01:20 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by xXziroXx View Post
PHP Code:
    case "dialog": case "dialogList":
      
temp.replyTo = player.account;
      
with ( findPlayer( pl ) ) {
        
triggerclient( "gui", "-Dialog", cmd, dialog, temp.replyTo, title, msg, options );
      }
    break; 
More efficent to do:

PHP Code:
    case "dialog": case "dialogList":
      
with ( findPlayer( pl ) ) {
        
triggerclient( "gui", "-Dialog", cmd, dialog, playero.account, title, msg, options );
      }
    break; 
Hardly, but I guess. Care to explain what this thing does, I have no clue
__________________
Reply With Quote
  #8  
Old 04-30-2008, 03:57 PM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
If you know how thiso works, you should be able to figure out quite easily how playero works...
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #9  
Old 04-30-2008, 06:55 PM
Bell Bell is offline
Registered User
Bell's Avatar
Join Date: Feb 2007
Posts: 1,824
Bell has much to be proud ofBell has much to be proud ofBell has much to be proud ofBell has much to be proud ofBell has much to be proud ofBell has much to be proud ofBell has much to be proud of
Quote:
Originally Posted by cbkbud View Post
Aww, Skyld deleted my post

stupid non-scripting pwas!!!!!!!

Also, it looks nice, but I don't get exactly what you mean by "party dialog".

Any questions about the script itself can be taken up with Novo. You'll find him losing his mind on Zodiac usually.
__________________
For support contact
http://support.toonslab.com/

Last edited by Tolnaftate2004; 04-30-2008 at 07:24 PM.. Reason: Moved.
Reply With Quote
  #10  
Old 05-01-2008, 03:25 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Bell View Post
You'll find him losing his mind on Zodiac usually.
What else is there to do on Zodiac?
__________________
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 04:22 AM.


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