Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 10-20-2011, 09:31 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
Personal Notepad

What is it?
A personal notepad scripted in GS2.

What use is there for it?
For anyone to be able to save quick notes whenever they please.

How do I install it?
Step 1.
Add this to the NPC Servers rights.
PHP Code:
rw levels/notepad/*.txt 
Step 2.
Add this to your servers Folder Options.
PHP Code:
file    levels/notepad/*.txt 
Step 3.
Copy this script and save it as a weapon.
PHP Code:
/* 
Personal Notepad v1.0 
This notepad was scripted by Gunderak. 
You may use this on your server if you wish 
so long as this comment block remains intact. 
*/ 
function onActionServerSide() { 
  
//Saves the note as a text file on the server. 
  
if (params[0] == "save") { 
    
text params[1]; 
    
text.savestring("levels/notepad/" player.account ".txt"0); 
    
player.chat "Saved Note!"
  } 
  
//Loads the text from the players text file. 
  
if (params[0] == "load") { 
    
temp.text.loadstring("levels/notepad/" player.account ".txt"); 
    
triggerclient("weapon"this.name"gettext"temp.text); 
  } 


//#CLIENTSIDE
function onCreated() { 
  
//What should be written to open it? 
  
this.activator "/notepad"
  
//Creates the GUI. 
  
NotepadOpen(); 
  
AboutOpen(); 


function 
ChatBar.onAction() { 
  
//Checks if they write what should open it. 
  
if (ChatBar.text == this.activator) { 
    
ChatBar.text ""
    
//Loads the text. 
    
triggerserver("weapon"name"load"); 
    
//Shows the notepad window. 
    
Notepad_Window.show(); 
    
//Hides the about window if it is open. 
    
About_Window.hide(); 
  } 


function 
NotepadOpen() { 
  
//Creates the notepad GUI. 
  
new GuiWindowCtrl("Notepad_Window") { 
    
profile GuiBlueWindowProfile
    
clientrelative true
    
clientextent "271,305"

    
canclose false
    
canmaximize false
    
canminimize false
    
canmove true
    
canresize false
    
closequery false
    
destroyonhide false
    
dockable true
    
text servername " Personal Notepad"
    
= (screenwidth 2) - (width 2); 
    
= (screenheight 2) - (height 2); 

    new 
GuiScrollCtrl("Notepad_Text_Container") { 
      
profile GuiBlueScrollProfile
      
height 271
      
hscrollbar "dynamic"
      
vscrollbar "dynamic"
      
width 271

      new 
GuiMLTextEditCtrl("Notepad_Text") { 
        
profile GuiBlueMLTextEditProfile
        
height 17
        
horizsizing "width"
        
text ""
        
width 246
      } 
    } 
    new 
GuiButtonCtrl("Notepad_Close_Button") { 
      
profile GuiBlueButtonProfile
      
text "Close"
      
width 80
      
hint "Closes And Discards Changes."
      
276
      
= -1
    } 
    new 
GuiButtonCtrl("Notepad_Save_Button") { 
      
profile GuiBlueButtonProfile
      
text "Save"
      
width 80
      
hint "Saves Changes."
      
192
      
276
    } 
    new 
GuiButtonCtrl("Notepad_About_Button") { 
      
profile GuiBlueButtonProfile
      
text "About"
      
width 80
      
hint "Opens About Window."
      
95
      
276
    } 
  } 
  
//Hides it so it doesnt open until it should. 
  
Notepad_Window.hide(); 


function 
AboutOpen() { 
  
//Hides the notepad window and creates the about window. 
  
Notepad_Window.hide(); 
  new 
GuiWindowCtrl("Notepad_About_Window") { 
    
profile GuiBlueWindowProfile
    
clientrelative true
    
clientextent "184,118"

    
canclose false
    
canmaximize false
    
canminimize false
    
canmove false
    
canresize false
    
closequery false
    
destroyonhide false
    
dockable false
    
text "About"
    
= (screenwidth 2) - (width 2); 
    
= (screenheight 2) - (height 2); 

    new 
GuiButtonCtrl("Notepad_About_Close_Button") { 
      
profile GuiBlueButtonProfile
      
text "Close"
      
width 80
      
hint "Closes About Window And Returns To Edit Mode."
      
53.5
      
89
    } 
    new 
GuiScrollCtrl("Notepad_About_Container") { 
      
profile GuiBlueScrollProfile
      
height 90
      
hscrollbar "dynamic"
      
vscrollbar "dynamic"
      
width 187
      
= -2
      
= -0.5

      new 
GuiMLTextCtrl("Notepad_About_Text") { 
        
profile GuiBlueMLTextProfile
        
height 150
        
horizsizing "width"
        
text "<center> With this tool you can write any notes you wish to remember and save them for further reference."
        
width 183
      } 
    } 
  } 
  
//Hides it so it doesnt open until it should. 
  
Notepad_About_Window.hide(); 


function 
onActionClientSide() { 
  
//Makes the notepad text the players note. 
  
if (params[0] == "gettext") { 
    
Notepad_Text.text params[1]; 
  } 


function 
Notepad_About_Button.onAction() { 
  
//When the about button is pressed. 
  
Notepad_About_Window.show(); 
  
Notepad_Window.hide(); 


function 
Notepad_Close_Button.onAction() { 
  
//When the close button is pressed. 
  
Notepad_Window.hide(); 


function 
Notepad_About_Close_Button.onAction() { 
  
//When the about windows close button is pressed. 
  
Notepad_About_Window.hide(); 
  
Notepad_Window.show(); 


function 
Notepad_Save_Button.onAction() { 
  
//When the player saves a note it saves it to the server. 
  
triggerserver("weapon"name"save"Notepad_Text.text); 
  
//Hides the notepad window. 
  
Notepad_Window.hide(); 

Enjoy.





If you spot any bugs/problems with it shout me a pm and I will try to fix ASAP

Edit: Updated the script for better naming of GUI's to avoid conflict with any other scripts.
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion

Last edited by Gunderak; 10-21-2011 at 08:51 AM..
Reply With Quote
  #2  
Old 10-20-2011, 09:40 AM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
I really like your use of comments. It is a good habit to keep with you and will come in handy for future developers. One thing I would like to comment on is the fact that you do not need to specify "levels/" before a directory in your folder configuration, and since you are not using a clientside function to retrieve the notepad's text, you don't even need it in folder configuration at all.
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #3  
Old 10-20-2011, 09:48 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
Well it does use this, im not sure if its classed as a clientside function?
PHP Code:
function onActionClientSide() {
  
//Makes the notepad text the players note.
  
if (params[0] == "gettext") {
    
Notepad_Text.text params[1];
  }

I will probably stand corrected...
Thanks for the comment
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #4  
Old 10-20-2011, 11:46 AM
xXziroXx xXziroXx is offline
Master of Puppets
xXziroXx's Avatar
Join Date: May 2004
Location: Sweden
Posts: 5,288
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
Send a message via AIM to xXziroXx Send a message via MSN to xXziroXx
Like Tig said, you're really commenting your code in a good way, keep it up. Personally I can't understand why anyone would want to use this script over making a .txt document on their computer though...
__________________

"A delayed game is eventually good, but a rushed game is forever bad." - Shigeru Miyamoto
Reply With Quote
  #5  
Old 10-20-2011, 12:02 PM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
hehe idk I just wanted to challenge my self ;D
Im thinking of making a Caculator.
Then making them all into one GUI where you can chose what you want to do.
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #6  
Old 10-20-2011, 12:42 PM
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
Looks pretty good, only things I would comment on are inconsistent naming of GUI controls (Close_Button, etc. are likely to conflict with other scripts) and that you're hiding the windows before they're even created in NotepadOpen() and AboutOpen(). You don't really need to create the GUIs until the player uses the command to open them.
__________________
Reply With Quote
  #7  
Old 10-20-2011, 12:56 PM
xXziroXx xXziroXx is offline
Master of Puppets
xXziroXx's Avatar
Join Date: May 2004
Location: Sweden
Posts: 5,288
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
Send a message via AIM to xXziroXx Send a message via MSN to xXziroXx
Quote:
Originally Posted by cbk1994 View Post
You don't really need to create the GUIs until the player uses the command to open them.
I disagree. It's usually a lot smoother to create GUIs (hidden) as soon as the script is loaded, and then just toggle visibility upon need.
__________________

"A delayed game is eventually good, but a rushed game is forever bad." - Shigeru Miyamoto
Reply With Quote
  #8  
Old 10-20-2011, 10:46 PM
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
I disagree. It's usually a lot smoother to create GUIs (hidden) as soon as the script is loaded, and then just toggle visibility upon need.
For essential interface windows that need to appear and reappear I'd agree, but is it really necessary to open dozens of rarely used windows and hide them when the player logs on? You're gaining no benefit from doing this as the speed required to create a single GUI is negligible, and in turn potentially sacrificing the user's memory and client speed. I don't really see how this is any smoother since the player can't tell the difference.
__________________
Reply With Quote
  #9  
Old 10-20-2011, 11:16 PM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
I don't think this would kill the players loading speed too dramatically.
Fair enough of it was super long..
And as for the naming of the GUI's il rename them later, but it's being used on a smallish server and doesn't conflict with anything atm.
Maybe like Notepad_ButtonName?
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #10  
Old 10-20-2011, 11:21 PM
salesman salesman is offline
Finger lickin' good.
salesman's Avatar
Join Date: Nov 2008
Location: Colorado
Posts: 1,865
salesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud of
Quote:
Originally Posted by Gunderak View Post
Maybe like Notepad_ButtonName?
Yeah. Read the guide that Chris linked in his post, it's good advice.
__________________
Reply With Quote
  #11  
Old 10-21-2011, 10:05 AM
Emera Emera is offline
Delterian Hybrid
Emera's Avatar
Join Date: Mar 2011
Location: Newcastle Upon-Tyne
Posts: 1,704
Emera is a jewel in the roughEmera is a jewel in the rough
I wouldn't use it, but very nicely done. Great use of reading from a text file.
__________________
Reply With Quote
  #12  
Old 10-21-2011, 02:17 PM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
hehe thanks :3
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #13  
Old 11-28-2011, 09:20 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
@who ever neg repped me for this:
i Copied and Pasted it INto my Srever and it Didn't Work.

First off, learn to spell.
Secondly, learn some grammar.
And lastly, grow up!

Seeming I'm feeling nice I have decided to write a mini tutorial so you can get it to work.

Step 1:
Open RC and click the weapons button.


Step 2:
Click the "Add" button.


Step 3:
Name it!


Step 4:
At the very top write this, and substitute YOUR_GRAAL_ACCOUNT for your "Graal######" number.
PHP Code:
findplayer("YOUR_GRAAL_ACCOUNT").addweapon(name); 
Underneath that paste the main script.


Step 5:
Return to your Graal window and write /notepad

There, wasn't that hard now was it?
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion

Last edited by Gunderak; 11-28-2011 at 12:09 PM..
Reply With Quote
  #14  
Old 11-28-2011, 08:32 PM
ff7chocoboknight ff7chocoboknight is offline
Skyzer Zolderon
ff7chocoboknight's Avatar
Join Date: Dec 2006
Location: New Hampshire, United States
Posts: 725
ff7chocoboknight is a glorious beacon of lightff7chocoboknight is a glorious beacon of lightff7chocoboknight is a glorious beacon of light
Send a message via AIM to ff7chocoboknight Send a message via MSN to ff7chocoboknight
Quote:
Originally Posted by Gunderak View Post
@who ever neg repped me for this:
i Copied and Pasted it INto my Srever and it Didn't Work.
rofl
__________________
Reply With Quote
  #15  
Old 12-09-2011, 11:56 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
I'm not joking..
Attached Thumbnails
Click image for larger version

Name:	lol.png
Views:	166
Size:	3.2 KB
ID:	54068  
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
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 01:19 PM.


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