Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #16  
Old 05-30-2010, 03:52 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
Tips for creating resizable GUI controls

The variables "vertSizing" and "horizSizing" let you easily make GUI controls that resize when the parent control resizes.

vertSizing is usually either "height" or "top". A value of "height" will change the height of the control as the height of the parent control changes. A value of "top" will move the control down as the parent control's height changes.

horizSizing is usually either "width" or "height". A value of "width" will change the width of the control as the width of the parent control changes. A value of "left" will move the control to the right as the width of the parent control changes.

These can be combined to do most kinds of resizing schemes.

PHP Code:
//#CLIENTSIDE
function onCreated() {
  new 
GuiWindowCtrl("Test_Window") {
    
profile GuiBlueWindowProfile;
    
    
clientRelative true;
    
    
clientWidth 300;
    
clientHeight 300;
    
    
= (GraalControl.width width) / 2;
    
= (GraalControl.height height) / 2;
    
    
text "Test Window";
    
    new 
GuiControl("Test_Object1") {
      
useOwnProfile true;
      
      
profile.opaque true;
      
profile.fillColor = {100100100};
      
      
width 100;
      
height 215;
      
      
5;
      
5;
      
      
// do nothing as the window grows wider
      
horizSizing "";
      
      
// grow taller as the window grows taller
      
vertSizing "height";
    }
    
    new 
GuiControl("Test_Object2") {
      
useOwnProfile true;
      
      
profile.opaque true;
      
profile.fillColor = {150100200};
      
      
width 185;
      
height 215;
      
      
110;
      
5;
      
      
// grow wider as the window grows wider
      
horizSizing "width";
      
      
// grow taller as the window grows taller
      
vertSizing "height";
    }
    
    new 
GuiControl("Test_Object3") {
      
useOwnProfile true;
      
      
profile.opaque true;
      
profile.fillColor = {150100100};
      
      
width 290;
      
height 70;
      
      
5;
      
225;
      
      
// grow wider as the window grows wider
      
horizSizing "width";
      
      
// move down as the window grows taller
      
vertSizing "top";
    }
  }

produces this:



There are also other values for vertSizing and horizSizing, but I have never needed to use them. Their names should be self-explanatory.

Quote:
GuiControl.horizsizing - string - specifies the horizontal resizing behaviour when the parent control is resized: right, width, left, center or relative
GuiControl.vertsizing - string - specifies the vertical resizing behaviour when the parent control is resized: bottom, height, top, center or relative


Creating custom objects types
While it's not really possible to create custom object types, you can use a few tricks to replicate the functionality.

For example, let's say you're making a mail system for players to send mail back and forth, but also for scripts to send mail to players. You could do this by joining a class to every script that needs to send mail or by using a public function, but there's an even cleaner way.

First, you will need a database NPC to make the object.

PHP Code:
// database NPC "Mail"
function onCreated() {
  
MailMessage = new TStaticVar();
  
MailMessage.join("mail_message");
}

// recreate the object when the server restarts
function onInitialized() {
  
this.onCreated();

What this does is makes a global object with the name "MailMessage" and joins it to the class "mail_message". Inside the class "mail_message" we can have functions.

PHP Code:
public function send() {
  
// replace this with the code to store the message
  
printf("Sending a message to '%s' from '%s' with subject '%s' and message '%s'."thisrecipientthis.senderthis.subjectthis.text);

Now, from any script you can do the following to send a mail message:

PHP Code:
temp.msg = new MailMessage();

msg.recipient "cbk1994";
msg.sender "(npcserver)";
msg.subject "Hello world!";
msg.text "Did it work?";

msg.send(); 
This technique can be used both serverside and clientside. It is especially useful for cases where passing parameters as an array would be inconvenient. I wrote a custom projectile script a few weeks back that used the same syntax as the mail message script above for parameters like "angle". It's a lot more coder-friendly than "shoot(32, 42, 0.4, 0, 0, ...)"
__________________
Reply With Quote
  #17  
Old 05-30-2010, 04:03 AM
Cloven Cloven is offline
Delteria
Cloven's Avatar
Join Date: Dec 2006
Location: Florida, United States
Posts: 542
Cloven has a spectacular aura about
Send a message via AIM to Cloven
Nice job.
Reply With Quote
  #18  
Old 05-30-2010, 04:23 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
Those gui sizings are pretty awesome
Reply With Quote
  #19  
Old 05-30-2010, 07:02 AM
adam adam is offline
http://wiki.graal.us/
adam's Avatar
Join Date: Nov 2001
Posts: 2,247
adam has a spectacular aura aboutadam has a spectacular aura about
Send a message via AIM to adam
Nice work man. I am very pleased!
__________________
Rogue Shadow (TCN)(NAT)(Global Development Team)

For development help, contact the patrons of the #graaldt irc channel below, I am usually there.
Click Here to Join IRC Chat Now! -- irc.freenode.net Channel: #graaldt
Quote:
<Dustyshouri> no, RogueShadow is always talking about scripts lol
<Dustyshouri> in fact, he pretty much brought Graal back as a topic single-handedly
Reply With Quote
  #20  
Old 05-30-2010, 11:13 AM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
Haha, on my mail system I've done exactly the same as you, weird

Good job, learned about the re-sizing (would rep but can't)
__________________
Reply With Quote
  #21  
Old 05-31-2010, 03:01 PM
Deas_Voice Deas_Voice is offline
Deas
Deas_Voice's Avatar
Join Date: Jun 2007
Location: Sweden
Posts: 2,264
Deas_Voice is a jewel in the roughDeas_Voice is a jewel in the rough
Send a message via AIM to Deas_Voice Send a message via MSN to Deas_Voice Send a message via Yahoo to Deas_Voice
nice, didn't know about the re-sizing stuff.

why haven't this thread been stickied yet? )=
__________________
.
WTF is real life, and where do I Download it?
There is no Real Life, just AFK!
since 2003~
I Support~
ღAeonღ | ღTestbedღ | ღDelteriaღ

if you are going to rep me, don't be an idiot, leave your name!
I got nothing but love for you
Reply With Quote
  #22  
Old 09-13-2010, 05:58 PM
Deas_Voice Deas_Voice is offline
Deas
Deas_Voice's Avatar
Join Date: Jun 2007
Location: Sweden
Posts: 2,264
Deas_Voice is a jewel in the roughDeas_Voice is a jewel in the rough
Send a message via AIM to Deas_Voice Send a message via MSN to Deas_Voice Send a message via Yahoo to Deas_Voice
bump, still not stickied!
__________________
.
WTF is real life, and where do I Download it?
There is no Real Life, just AFK!
since 2003~
I Support~
ღAeonღ | ღTestbedღ | ღDelteriaღ

if you are going to rep me, don't be an idiot, leave your name!
I got nothing but love for you
Reply With Quote
  #23  
Old 09-13-2010, 10:29 PM
Jiroxys7 Jiroxys7 is offline
Hazard to Graal
Jiroxys7's Avatar
Join Date: Apr 2009
Posts: 343
Jiroxys7 will become famous soon enough
Quote:
Originally Posted by DustyPorViva View Post
Default Inventory Prefixes:
- : hides the inventory
* : can't be deleted by player
category/itemname : Organizes the weapons in category names.

However, these aren't exactly script functions, so much as client features
I've seen people using + and $ too. does this actually provide any features? or was it probably just used for other scripting purposes?
__________________
MY POSTS ARE PRONE TO EDITS!
Reply With Quote
  #24  
Old 09-13-2010, 10:33 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
Quote:
Originally Posted by Jiroxys7 View Post
I've seen people using + and $ too. does this actually provide any features? or was it probably just used for other scripting purposes?
They're either using it for their own scripting purposes, or doing so to manipulate the alphabetical order of the weapon list. Using certain characters at the beginning of the weapon name will ensure a WNPC is at the top of the weapon list in RC, usually for organizational purposes(easier to find more important weapons). Otherwise people tend to use special characters to denote various scripted organization of items. For example, if they use a custom MUD inventory, they may prefix items with +, weapons with $ and so on.
Reply With Quote
  #25  
Old 01-21-2011, 10:38 PM
Deas_Voice Deas_Voice is offline
Deas
Deas_Voice's Avatar
Join Date: Jun 2007
Location: Sweden
Posts: 2,264
Deas_Voice is a jewel in the roughDeas_Voice is a jewel in the rough
Send a message via AIM to Deas_Voice Send a message via MSN to Deas_Voice Send a message via Yahoo to Deas_Voice
WHY haven't this awesome thread been stickied yet?!
__________________
.
WTF is real life, and where do I Download it?
There is no Real Life, just AFK!
since 2003~
I Support~
ღAeonღ | ღTestbedღ | ღDelteriaღ

if you are going to rep me, don't be an idiot, leave your name!
I got nothing but love for you
Reply With Quote
  #26  
Old 01-21-2011, 11:30 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by Deas_Voice View Post
WHY haven't this awesome thread been stickied yet?!
Not enough tips n tricks, and you keep bumping it anyway.

I still think someone needs to compile all the documentation on the forums and populate the Wiki(s) with it.

First step: Compile list of helpful posts. (Any reply in the NPC-Scripting forum with [PHP] or [HTML] tags by someone who knows what they're doing usually)
__________________
Quote:
Reply With Quote
  #27  
Old 01-22-2011, 01:12 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 fowlplay4 View Post
Compile list of helpful posts. (Any reply in the NPC-Scripting forum with [PHP] or [HTML] tags by someone who knows what they're doing usually)
Here's an incomplete list of helpful posts, in no particular order:

Again, this is an incomplete list. The only reason there are so many of mine is because I tend to bookmark posts I make that I think I might need again.
__________________
Reply With Quote
  #28  
Old 01-22-2011, 01:39 AM
oo_jazz_oo oo_jazz_oo is offline
Jazz teh Awesome
oo_jazz_oo's Avatar
Join Date: Jul 2006
Location: California
Posts: 596
oo_jazz_oo is a jewel in the roughoo_jazz_oo is a jewel in the rough
Send a message via MSN to oo_jazz_oo
After Tig said about the new playerlist having pm windows open in the middle of the screen, I asked him how he did this. Apparently Stefan had said how to at some point?
But it went unnoticed (to me at least). I think some people will find it helpful.

PHP Code:
externalwindow.x
externalwindow
.
Inside the gui control, of course.

(However, it seems when the window is initially created, it ignores the external.x/y position...and you need to set those after the window is visisble)

Found the post! http://forums.graalonline.com/forums...&postcount=746
__________________

Reply With Quote
  #29  
Old 01-22-2011, 02:10 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by oo_jazz_oo View Post
PHP Code:
externalwindow.x
externalwindow
.
Inside the gui control, of course.

(However, it seems when the window is initially created, it ignores the external.x/y position...and you need to set those after the window is visisble)

Found the post! http://forums.graalonline.com/forums...&postcount=746

Just thought I'd elaborate on your example there:

PHP Code:
//#CLIENTSIDE

function onCreated() {
  
createGUI();
}

function 
createGUI() {
  
// Destroy Existing Window for Testing purposes
  
if (isObject("HelloExample")) {
    
HelloExample.destroy();
  }
  
// Create Window
  
new GuiWindowCtrl("HelloExample") {
    
0;
    
0;
    
width 200;
    
height 200;
    
text "Hello World!";
    
profile GuiBlueWindowProfile;
    
isexternal true;
    
visible true;
    
externalwindow.30;
    
externalwindow.30;
  }
  
// Update Windows External X, Y
  // Work-around for current bug that causes it to ignore
  // external window values when created.
  
this.trigger("UpdateWindow""");
}

function 
onUpdateWindow() {
  
with (HelloExample) {
    
with (externalwindow) {
      
// Centers GUI in middle of screen.
      
= (screenwidth width) / 2;
      
= (screenheight height) / 2;
    }
  }

__________________
Quote:
Reply With Quote
  #30  
Old 02-11-2011, 12:39 PM
Cubical Cubical is offline
Banned
Join Date: Feb 2007
Posts: 1,348
Cubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant future
Quote:
Originally Posted by cbk1994 View Post
Here's an incomplete list of helpful posts, in no particular order:

Again, this is an incomplete list. The only reason there are so many of mine is because I tend to bookmark posts I make that I think I might need again.
This should be reposted and stickied with the addition of a few of Dusty and WhiteDragons post.
Reply With Quote
Reply


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 03:43 AM.


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