Scripting Guide

Eh, the problem when I started out for me, was, not really understanding the different parts of scripting…strings, and things like that, etc…

So, here is a small guide…

[CENTER]Parts of Scripting
[SIZE=“4”]

Commands [/SIZE]
[spoilerbox=Some of the commands you’ll need to know…]

strtofloat(#s(STRINGNAME)) - Converts a string to a format that a script reads as a number. If you just have #s(stringname), it will see the numbers as the litteral keys of, say, for example, 4 and 5…but the strtofloat makes it read the string as a value, so the actual value of 45. Strtofloat stands for string to float.

#s() - Extracts what is in the actual string…so, if client.health is 100, it’ll extract 100 from the string.

#v() - Will make a script recognize a variable for the number that it actually is…Can only be used with variables…

Example:

if(playerenters){ showtext 500,30,30,arial,b,#v(this.number); }

toweapons - this will add the NPC that it is in to a players weapons…but be warned, it will add the WHOLE NPC…

toweapons weaponname;

you can also have a folder for the weapon to be in in the Qmenu…to define the folder, put it infront of the weapon name with a slash after it…

foldername/weaponname;

[CODE]
if(playerenters){
toweapons Staff/Test;
}
if(weaponfired){
say2 BLAH;
}

Parameters - Parameters are represented by the word “params” in commands.rtf…they are basically extra pieces of information that travel with what ever is being sent…one of the more widely used uses for paramaters are triggerhacks…

if(weaponfired){
triggeraction playerx,playery+1,mine,2;
}

In this script, when you fire the weapon, it will send the action “Mine” and the parameter “2” to playerx, and playery+1…

If there is an NPC in the location, and it checks for
if(actionmine)
it can read the parameter of 2 that you sent it!
Parameters are read by scripts using #p(0),#p(1), etc…
You can send more than one parameters by just putting a comma after the previous parameter and adding another one.

Example…

if(weaponfired){
triggeraction playerx,playery,mine,gold,2;
}

Now the receiving NPC…

if(actionmine){
   this.hearts-=#p(1);
   if(this.hearts==0){
      say2 You mined some #p(0)!;
   }
}

keypressed - Will check if a player presses a key! Also, you can use #p(0) to find the key code of the pressed key and #p(1) to find the actual symbol of it…be warned, keypressed does NOT recognize tab, comma, and some other vital button that would be nice to have detected…

if(keypressed){
   message #p(0),#p(1);
}
if(strequals(#p(1),a)){
   say2 You pressed "a"!
}

This script will show you the key code then the actual key that you pressed, and if you press a, it will say you pressed a.

keydown(keynumber) - This command is very simple to understand or use, but people commonly make mistakes with it…
The biggest mistake is putting an actual letter into the parenthesis…
keycode(s) would be WRONG…there is supposed to be a number, not a letter inside.
The numbers for keycode are as follows…
0 - up
1 - left
2 - down
3 - right
4 - S
5 - A
6 - D
7 - M
8 - tab
9 - Q
10 - P
So, to check if the player pressed “S,” you’d do

if(keydown(4)){
}

keycode(letter) - This will give you the keycode of the letter…usually used to get the keycode to use in things like keydown2…

if(playerenters){
   message keycode(i);
   }
}

This will display the keycode of i…

A keycode is basically how you identify the key…

keydown2(keycode,true) - This will check for other keys that normal keydown doesn’t detect for…

You replace the keycode with the number of the key…if it is a key that you can type, you can do
keydown2(keycode(letter),true)
and replace letter with that key…

But, if it is something like control, alt, enter, backspace, or other keys that don’t actually leave a “mark,” you’ll have to know their actual keycode…

Here are some of the more common keycodes…

Backspace - 8
Space - 32
Enter - 13

if(keydown3(keycode(o),true)){
say2 You pressed o!;
}

openurl LINK - Will open a url with that link…

Do NOT include the http:// part…

if(playertouchsme){
 openurl www.graal.in;
}

Will take you to graal.in when you touch the object…

Leader - Being the level leader simply means that you were the first to enter the level.

Tokenize - Tokenize is a command used to divide a string into “tokens.”
Tokens are created by spaces…Every space starts a new token…

So, if the script is…

if(playerchats){ tokenize #c; }

and the player says “I love fish,” then the tokens would be as such…
#t(0) - I
#t(1) - love
#t(2) - fish

#t(number) is used to access tokens created, with the first one being #t(0).

Timevar - Timevar is a server variable that is used to work with time…one unit of timevar is equal to 5 seconds.

serverwarp - serverwarp will warp you to a different server…pretty straight server…

serverwarp server;
Where server is the server name.

if(playerenters){
   serverwarp Noddess;
}

! - The symbol, !, set in front of anything, means not…
So, if(!strtofloat(#s(client.health))==5) will check that client.health is NOT equal to 5…

if(!strtofloat(#s(client.health))==5){ setstring client.health,5; }

Set/Unset - Will set flags to true or false…

if(playerenters){
set entered;
}
if(playertouchsme){
unset entered;
}

leftmousebutton/rightmousebutton - this will be triggered when the player clicks the button (right/left)…

Example…

if(leftmousebutton){
if(mousescreenx,mousescreeny in |10,30|){
message You click here!!!;
}
}

Comparisons/Defining - “=” is used to set something, usually a variable, to a value. While == is used to compare two things…

Example:

  1. Defining…

if(playerenters){ this.on=1; }
2. Comparing…

if(this.on==1){ this.on=0; }

strequals(string,value) - Check if the two things are equal…I’ll show an example here. It stands for string equals.

Example:

if(playerenters && strequals(#g,admin)){ }
will check if the players guild tag is “Admin”

timeout - Is used to start loops, mainly…
Causes the script to be reread in a certain amount of time…

Example:

if(playerenters){ timeout=0.05; } if(timeout){ blah; timeout=0.05; }

“Check” - If anybody you talk to refers to something called a check, they are talking about an if().

Here is an example of a check…

if(playerenters){blah;}

There are many different things you can check for…
playerchats - if a player says something
playerenters - if a player enters a level
leftmousebutton - if a player clicks with their left mouse button
keypressed - if a player presses a key…
ETC…

lay/lay2 - These commands are used to put items in places, such as bombs, hearts, arrows, etc. You can see the whole list in commands.rtf…

The command for lay is
lay itemname;

if(playerchats && strequals(#c,/heal)){
   lay heart;
}

The difference between lay and lay2 is that lay2 let’s you determine where the item goes on the level, while lay just puts the item at the x and y of the NPC calling the lay…

lay2 itemname,x,y;

if(playerchats && strequals(#c,/heal)){
   lay2 heart,playerx,playery;
}

setlevel2/setlevel - Both of these will warp you to a new level, but the difference is that setlevel will warp you to the new level but keep you at the X and Y that you are already at. With setlevel2, you can specify where the player will appear on the new level.

if(playerenters){
   setlevel2 onlinestartlocal.nw,30,30;
}

This will warp the player to onlinestartlocal.nw, to the location where x is 30 and y is 30.

if(playerenters){
   setlevel onlinestartlocal.nw;
}

This will warp the player to the level onlinestartlocal.nw, but the players x and y will be the same as when it was when they entered.

Make sure to remember to do .nw after the level name

For all of the #g,#a,#K, and all of those other things, read the ending of commands.rtf.

[/spoilerbox]


[COLOR=“Red”]Strings
[/COLOR]
[spoilerbox=Some information about strings]

Strings are used to save information permanently…While variables are only saved until you log out, strings will keep information…

There are a few different kinds of strings…

client.strings - There is a limited amount amount of client.strings (250). They are saved onto the players, and can be changed/added using setstring. They can be accessed through any script that the player is using.

Example: setstring client.health,100;

level.strings - These are strings that can be accessed by any NPC on the given level…They are used for things where you want everybody in the level to see.
For use with NPC server, mainly…
Example: setstring level.lightson,1; if(strtofloat(#s(level.lightson))==1){ lights stuff; }

server.strings - These strings can be accessed by any NPC anywhere on the server. They are used for many different things, including chatboxes and other things, such as events. There is an unlimited amount of server strings.
Example:

if(playerenters && strequals(#a,alex)){
setstring server.alexenter,1;
}

Then there is a weapon in the player like this…

if(strtofloat(#s(server.alexenter))==1){say2 Alex has entered the level called blah.nw!; }

Normal Strings - These strings are just normal strings…again, can be defined with text or numbers…

Example:

if(playerenters){setstring string,text;}

[/spoilerbox]


[COLOR=“Red”]Images
[/COLOR]
[spoilerbox=All the things that you’d need to know about working with images (for GUIs, HUDs, etc…).]

Indexs - Image indexs are interesting things…these kinds of indexs are used in things like showimg, showtext, etc…

The indexs define the image, and let you modify it through the script…basically, like an image ID code. The one thing about indexs that you must remember is that any index of 250 or lower will render the image or text visible to everyone, while any number about 250 will make it only visible to the current person…

showtext - Showtext is used to show text at the location that you want with the correct font and type…

The formatting is as follows…

showtext index,x,y,font,style,text; - where style is things like b,i,or u…

if(playerenters){
 showtext 20,30,30,arial,b,Welcome!;
}

showimg - Show image shows an image with the given filename at the given location…

The command is
showimg index,filename,x,y;

if(playerenters){
   showimg 50,noobhead.gif,30,30;
}

showimg can also be used to show text…it is recommended to use showtext, but you should be informed…the format for showing text with showimg is…

showimg index,@font@style@text,x,y;

You replace the word font with the font name, the word style with a style, and text with the text…

if(playerenters){
   showimg 40,@arial@b@Welcome!,30,30;
}

changeimgzoom - Will change the zoom on the image…basically make the image bigger OR smaller…

Command: changeimgzoom index,factor;

Factor represents the factor of the zoom…
A factor of 0.5 will make the image half as big.
A factor of 2 will make the image twice as big.

if(playerenters){
   showimg 5,tree.png,30,30;
   changeimgzoom 5,2;
}

This will make the image called tree.png, shown at 30,30, twice as big.

changeimgvis - This will change what “level” the image is shown at, meaning that either in pixels or in x/y…

Changeing the image visibility to 4 or higher will mean that the location (x and y) in the main showimg will be seen as the pixel location of the screen…this is also used to layer images…

Example:

if(playerenters){
   showimg 500,door.png,screenwidth-10,screenheight-10;
   changeimgzoom 500,4;
}

[/spoilerbox]

[COLOR=“Red”]Loops
[/COLOR]
[spoilerbox=Loops are used to force a script to re-read something over and over.]

Timeout Loops - They basically check for a timeout, and then have a timeout. They need to be activated by a timeout earlier. Forces the script to re-read itself…

Example:

if(playerenters){ timeout=0.05; } if(timeout){ blah; timeout=0.05; }

forloops - They will literally check all possible things that can happen with the specified parameters…It is better to see with an example…

this.i=0; - defines what number the number starts at.
this.i<200; - will keep checking the number until it gets to the maximum of 200.
this.i++; - the number will rise by 1 every time.

for(this.i=0;this.i<200;this.i++){ blah }

[/spoilerbox]


[COLOR=“Red”]Flags
[/COLOR]
[spoilerbox=Information about Flags]

Flags are simple things that can be turned off or on, and can be seen in the RC profile section…

Normal Flags - There are normal flags that can be set with the command “set” and “unset.”

if(playerenters){set entered;}

will set the flag entered to true…

if(playerenters){unset entered;}

will unset the flag, or basically set the flag to false.

These flags can be accessed through the RC and changed manually.

this.flags - These flags can only be seen by the NPC they are in…they are used often for turning things on/off. They will NOT be added to the player.

if(weaponfired){ if(!this.on)set this.on; else unset this.on; }


[COLOR=“Red”]Variables
[/COLOR]
Variables are used to hold numbers, temporarily…

this.variables - These variables can only be read by the current NPC. they are set by doing this.variable = NUMBER.

if(playerenters){ this.variable=5; }

[/spoilerbox]

[COLOR=“Red”]Functions
[/COLOR]
[spoilerbox=Information on Functions]
Functions are used to keep a script from getting overwhelmingly complicated as well as to not have to re-write script parts over and over.

Functions - Functions are, again, used for convenience as well as to make the script look cleaner…they are basically blocks of script that are defined after they are called…It is easier to show in an example.

if(playerchats && strequals(#c,/buy bombs)){
buybombs();
}
function buybombs(){
playerrupees-=40;
playerbombs+=10;
}[/CODE]

buybombs(); is where the function is called, and function buybombs(){blah;} is where the function itself is called.

[/spoilerbox]

[SIZE="4"]
[COLOR="Red"][I][U]Triggeractions[/U][/I] [/SIZE][/COLOR]
[spoilerbox=Information on triggerhacks]
Triggeractions basically tell the server to do something, such as add a weapon, delete a weapon, and so forth.

[B]Triggeractions[/B] - Triggeractions will work if they are turned on in the options. Search the forums for more information about them. 

They are used like this...

[CODE]if(playerchats && strequals(#c,/deletethis)){
triggeraction 0,0,gr.TRIGGERHACKNAME,paramaters,paramaters;
}[/CODE]

A list of triggerhacks that Graal Reborn has:

gr.addweapon
gr.deleteweapon
gr.addguildmember
gr.removeguildmember
gr.removeguild
gr.setguild
gr.setgroup
gr.setlevelgroup
gr.appendfile
gr.writefile
gr.rcchat

You can also use triggeractions to send information to other NPCs, and the check for them on the receiving NPC is if(actionNAME).

Weapon:
[CODE]
if(weaponfired){
triggeraction playerx+1,playery+1,plant,1;
}
[/CODE]
Now the NPC recieving the triggeraction...which has to be playerx+1 and playery+1 when the weapon is fired...
[CODE]
if(actionplant && #p(0)==1){
setimg plant1.png;
}
[/CODE]

When the weapon is fired, it'll give information to any npc at playerx+1,playery+1...

If the npc there is the one that I posted, it will show the image of a plant.

Triggeractions in these situations shoot information the the specified x and y...
[/spoilerbox]
[SIZE="4"]
[COLOR="Red"][I][U]Script Formatting[/U][/I] [/SIZE][/COLOR]
[spoilerbox=How to format the scripts, using things like {,},(,), and ;.]

[B]{ and }[/B] These are used with checks to define what the check affects...

[CODE]
if(playerenters){
set this.flag;
this.cow=1;
}[/CODE]
The {} are around set this.flag; and this.cow=1;, so when the check is confirmed, or in other words, when the player enters, the things inside of the {} will happen...

[CODE]if(randomflag){
set this.flag;
}
this.cow=1;
[/CODE]
Here, only set this.flag; is inside of the {}, so if the player has the flag of randomflag set to true, only then will this.flag be set to true.


[B];[/B] - This is used to end a command...

[CODE]set this.flag;[/CODE]

[/spoilerbox]

[SIZE="4"]
[COLOR="Red"][I][U]Indexs[/U][/I] [/SIZE][/COLOR]
[spoilerbox=Index information!]
Indexs define a player, baddy, or other npc by the order that they entered the level...they are more advanced and should not be used by begginers...

[B]Player Indexs[/B] - There are millions of things you can do with these...check player hearts, the players rupees, the players bombs, darts, ap, etc...There are almost ALWAYS used with a forloop to cycle through the players...The highest index will always be the number of people in the level.
There are way too many uses for these to be counted, such as finding how many people are in a certain area (the example will be this), checking if a player is dead or not, and such...

All of the commands work as follows...
players[index].THING, where thing is what you are looking for.

[CODE]for(this.i=0; this.i<playerscount; this.i++){
  if(players[this.i].x in |20,30| && players[this.i].y in |20,30|){
    this.count++;
  }
}

All of the other indexs I won’t mention because there are so many other kinds…signs, horses, bombs, you name it…
[/spoilerbox]


[COLOR=“Red”]Examples
[/COLOR]
[spoilerbox=Example scripts!]

if(playerenters){ setimg door.png; triggeraction 0,0,gr.updatelevel,; } if(compuscount<=0){ hide; }
Will update the level when a player enters, and when all baddies on the level are dead, it will hide itself (it is a door).

if(playerenters){ toweapons -report; } if(playerchats){ tokenize #c; if(strequals(#t(0),/report)){ triggeraction 0,0,gr.rcchat,Report: #a - #c; setplayerprop #c,Report Sent!; this.count++; } } if(this.count>=10){ serverwarp Login; }
A simple little report feature…when the player says /report and then the text after that, it sends the report to RC…if the player starts spamming RC with reports, it disconnects them.

This next one will be an example of how an GUI is done…with the clicking detects and everything…

// NPC made by Alex
if(playertouchsme){
  disabledefmovement;
  this.on=1;
  this.xlocal=screenwidth/2;
  this.ylocal=screenheight/2;
  timeout=0.05;
}
if(timeout){
  if(this.on==1){
    showtext 500,this.xlocal-10,this.ylocal-10,arial,b,Buy;
    showtext 501,this.xlocal-30,this.ylocal-30,arial,b,Close;
    showimg 502,gui.gif,this.xlocal,this.ylocal;
    if(leftmousebutton){
      if(mousescreenx in |this.xlocal-10,this.xlocal+10| && mousescreeny in |this.ylocal-10,this.ylocal+10|){
        buy();
      }
      if(mousescreenx in |this.xlocal-30,this.xlocal-30| && mousescreeny in |this.ylocal-30,this.ylocal-30|){
        close();
      }
    }
  }
}
function buy(){
  if(playerrupees>=10){
    playerrupees-=10;
    playerbombs +=10;
    close();
  }
}
function close(){
  hideimgs 500,502;
  this.on=0;
  enabledefmovement;
}

In this script, when you touch the object that it is in, it will freeze you and give you two options…buy or cancel…if you click cancel, it’ll unfeeze you and hide the images, if you click buy it’ll sell you some bombs and then unfreeze you and hide the images

if(playerchats){
  if(strequals(#c,/sit)){
    setani sit,;
  }
  if(strequals(#c,/dance)){
    setani dance,;
  }
}

In this script, if the players says /sit, it’ll make them sit, and if they say /dance, it’ll make them dance.

if(playerenters){
toweapons -reconnet;
}
if(playerchats && strequals(#c,/reconnect)){
  serverwarp Noddess;
}

This is a script to reconnect you when you say /reconnect…change Noddess to your server’s name.
[/spoilerbox]

[/CENTER]

Hey benzy u reading this?

I AM GOING TO USE THIS

Post to be used later

my thanks are precious. at least to me.

xD My thanks are too >:) only given out 1400 :frowning:

If anyone has ideas on what to add…

put it in a spoiler box, its pretty big and takes up room in the thread

show how to use trigger actions and the use of player indexes

show:
-getangle() : how it works and what it converts to
-vecx() and vecy(): explain how these work and how they can be applied
-arrays : how to declare them, read and write
-parameters

Also alex, im a bit pissed off at seeing someone like you who still hasnt perfected gs1 and your writing a guide for it. If you learnt dont you think others can as well, if there having trouble it means there too young and they cant think logically anyway…

GS1 is a very easy language and is mainly a process of using common sense and maths skills (if you have any that is…). Its not the syntax thats the hard part. I just dont get how most people new to gs1 cant see that :frowning:

ALSO RILEY I WANT ALEX TO SEE THIS SO DONT DELETE IT! ITS USEFUL ADVICE, NOT MEANT TO BE FLAMING grrrrr

edit:

WRONG!!! sorry but its true… the compiler will read this.count as a floating point by default, if you then want to compare a string thats why theres strequals()

#v will tell the compiler that the value in the parenthesis is a floating point variable
strtofloat() will convert a string to a floating point
#s() will tell the compiler that the variable inside the parenthesis is a string

and for those who dont know:
parenthesis == ()
floating point == a data type (more info:http://en.wikipedia.org/wiki/Floating_point)

also some shit you missed…
int() will cut the decimals of a floating point to make it a whole number
example : int(1.00002343423876) will become 1

abs() distance from 0
example :-2 will become 2 & 2 will become 2

lmao, you basically listed all of my scripting skills. xP

What I wANT IS REAL FUNCTIONS DECLARATIONS. NOT THIS NO PARAMETER/RETURN VALUE BULLSHIT

Sent from my MB860 using Tapatalk

I’m gonna go make him a siggy banner for it now. >:3
[hr][/hr]
Here you guys go

"["URL="http://forums.graal.in/forums/showthread.php?t=5034"]"["IMG]http://img191.imageshack.us/img191/9249/alexscriptingguidebanne.png[/IMG][/URL]

Remove the " " in URL and IMG and you can have it, idk how to make the BBCode stop.

PS: Why the hell can’t I have more than 4 images in my Siggy? TT^TT

What the fuck is this shit?

Scripting tut for noobs I guess. I like it. People are fucking stupid sometimes, it’s good to be able to direct them to a good link.

Yeah, tric, thanks…Um, this just annoyed me when I started…I could ask about the harder stuff, but then some of the easier things were never told anywhere to me…it isn’t a freaking guide for people that are at my level or even a bit below…more for the people that were like me when they started…

Thanks Yenairo xP

And Spooon, seriously, just stay off…if you don’t like it, I’m fine with that…just thought about how I felt when I started, and then posted what I thought would help someone.[ATTACH=CONFIG]2264[/ATTACH][ATTACH=CONFIG]2263[/ATTACH]

If you’re going to make a scripting guide, “style” you’re fucking scripts. There’s a fucking button for it if you do not like doing it yourself.

if (#v(this.var) == 5) { stuff; } This will not work. #v is used when you do not want variables to be read as text. Variables are read normally in ‘if’ statements I don’t know where the fuck you got the term “check”, btw.

if (this.var == 1) message #v(this.var2); This will work if this.var and this.var2 exist.

set and unest are used for flags. this.bullshit is not a flag, it’s a variable.

if (!dead) set dead; else unset dead;

This is not true. Anything outside of the brackets will still be set, but it will work like ‘if (created)’.

timeout = 0.05;
this.var++;
if (this.var == 20) message A second has passed.;

This script will still looped with out a Timeout flag.

___Merged doublepost__________________

Honestly, this guide will do nothing but make kids script like retards. Love all of the errors and misconceptions.

It’s still complete shit.

Thanks Alex,I know nothing about scripts but I will be sure to use this when Joeys server hosting is back up,I really needed the showtext

The only button you need.

It’s still a waste of time reading this.