Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Alert(); In Graal! (https://forums.graalonline.com/forums/showthread.php?t=134265209)

Gunderak 12-09-2011 03:29 PM

Alert(); In Graal!
 
Anyway I have made my own "Alert" function.
If you would like to see it here's how.

Step 1:
Make a new class and name it "alert".
Now place this code in the newly created class.
PHP Code:

//#CLIENTSIDE
function Alert(titlemessage) {
  new 
GuiWindowCtrl("Alert_Window") {
    
profile GuiBlueWindowProfile;
    
destroyonhide 1;
    
canmaximize false;
    
canminimize false;
    
canclose false;
    
canmove false;
    
isexternal 0;
    
width 320;
    
height 120;
    
text title;
    
screenwidth width 2;
    
screenheight height 2;
    new 
GuiScrollCtrl("Alert_Text_Container") {
      
profile GuiBlueScrollProfile;
      
6;
      
24;
      
width 308;
      
height 69;
      
hScrollBar "dynamic";
      
vScrollBar "dynamic";
      new 
GuiMLTextCtrl("Alert_Text") {
        
profile GuiBlueMLTextProfile;
        
text message;
        
width 287;
      }
    }
    new 
GuiButtonCtrl("Alert_Ok_Button") {
      
profile GuiBlueButtonProfile;
      
width 40;
      
height 20;
      
Alert_Window.width Alert_Ok_Button.width 7;
      
Alert_Window.height Alert_Ok_Button.height 7;
      
text "Ok";
    }
  }
}

function 
Alert_Ok_Button.onAction() {
  
Alert_Window.destroy();


Step 2:
This is how to use it.
On any script place this directly under onCreated on the clientside.
PHP Code:

this.join("alert"); 

Then to alert the player place this.
PHP Code:

Alert("Alert!""Hello world!"); 

It works like this:
Alert("TITLE", "MESSAGE");

-Enjoy

ff7chocoboknight 12-09-2011 04:14 PM

Anyone who knows how to make GUIs can make that without any problems. -__-

Hezzy002 12-09-2011 05:43 PM

Thanks! I really needed this for my server.

Gunderak 12-09-2011 05:47 PM

Well I figured someone who doesn't now has this to learn off.
No need to be too sutle.

ffcmike 12-09-2011 06:03 PM

Quote:

Originally Posted by Gunderak (Post 1677043)
Well I figured someone who doesn't now has this to learn off.

It would be much better to write a guide for making simple GUI windows.

Gunderak 12-09-2011 06:21 PM

There are already guides on that on the Graal Bible.
I just thought it would be nifty to be able to do alert(); in Graal.

ffcmike 12-09-2011 06:25 PM

It would also be much better if Alerts were created and destroyed dynamically, as if you were to receive multiple alerts in quick succession they would over-write eachother.

Alert: You've just won the Server Lottery, congratulations!

1 second later

Alert: Graal765432 has sent you a hug

Gunderak 12-09-2011 06:30 PM

Well maybe making an clientr variable as an index and then increasing it when an alert is created and decreasing when the close button is pressed..
I suppose that would work.
I didn't think of this when scripting it.

ffcmike 12-09-2011 06:32 PM

Quote:

Originally Posted by Gunderak (Post 1677056)
Well maybe making an clientr variable as an index and then increasing it when an alert is created and decreasing when the close button is pressed..
I suppose that would work.
I didn't think of this when scripting it.

You don't need an array or index variable, it's possible to create GUIs with a variable name, then use catchevent(); to receive necessary actions on the correct GUI object.

Gunderak 12-09-2011 06:35 PM

I don't know how I would go about doing it using catchevent(); so il just stick with using an index for now.

ffcmike 12-09-2011 06:45 PM

Quote:

Originally Posted by Gunderak (Post 1677058)
I don't know how I would go about doing it using catchevent(); so il just stick with using an index for now.

Lets say I was going to create a GUI object which name includes an increasing number to distinguish itself:

PHP Code:

public function alert(temp.titletemp.message){
  new 
GuiWindowCtrl("Alert_" thiso.alertcount) {
    new 
GuiButtonCtrl("Alert_Button_" thiso.alertcount) {
      
//stuff
      
thiso.catchevent(this.name"onAction""buttonPress");
    }
  }
  
this.alertcount ++;


This would be creating a separate GUI control for each alert, where catchevent will then catch the specified action and pass the GUI object as a parameter within the specified function name:

PHP Code:

function buttonPress(temp.gui){
  
temp.gui.destroy();


I believe this can also be done without even assigning a GUI control a name.

Tigairius 12-09-2011 10:00 PM

You can also use:
PHP Code:

shared.adminMessage("text"); 

which will display a message even after being disconnected from the server.

One neat thing you might consider adding is perhaps some confirm function. For instance:
PHP Code:

response confirm("Are you sure you want to do this?");
if (
response) {
  
doit();
}else {
  
dontdoit();


Or by taking advantage of waitfor() :)

Gunderak 12-10-2011 03:34 AM

@Ffcmike thanks for the help, il try your idea out when I ye home.

@Tigarius I have used shared.adminMessage(); before but I wanted to make it have a title aswell. And shared.adminMessage(); I'm not sure it it would overwrite the pay if you get another message.


All times are GMT +2. The time now is 09:12 PM.

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