If you do not like the forum format, check this site out for a website format of this post: -
http://www.freewebs.com/zephyrtk/gs2.../art01GS2.html
The link to the original post of this in the Delterian Forums is here:
-
http://forums.delteria.com/index.php...221&#entry7221
This thread is made for those who are completely new to GS2, but are assumed to be at least familiar with GS1, or old GScript. Sort of a way for GS1 scripters to familiarize themselves with this new monster... except its in plain English and makes it all easy to understand. The following is an example of a GS2 Tailor Script created solely by me from Scratch, and declared correct by scripters Riot, Ajira, Maniaman, and MisconceptioN.
I hope that the following will help you learn GS2, if you are not already smart about it:
-=-=-
Here's how I'll work this:
I will post the old GScript (if I bothered to convert it somehow) and then the new one. In this post, I have the old one and I'll post it first and do a fast brief on how it works, then do the new GScript and then put the effort onto explaining that.
TAILOR SCRIPT
BEFORE YOU READ THE SCRIPT, please keep in mind that there are many many ways to make GScript do whatever you want to. The glass is half full, or the glass is half empty. They both mean the same thing, but they use different ways of explaining it. The same applies to GScript and any other computer or foreign language you ever might want to learn.
In these two scripts, the function is for the player to say "
/set clothes/tunic PART COLOR."
ALSO, in GS2 I was told that the functions "setPARTcolor()" is deprecated (meaning they're old and there's better/easier ways to do them), but for the purposes of this I'm doing this so you can relate the Old to the New GSCript.
NPC Code:
// OLD GSCRIPT
if (created) {
setstring this.parts,"skin","coat","sleeves","shoe","belt";
}
if (playerchats) {
tokenize #c;
if (startswith(/set,#c)) {
if (strequals(#t(1),clothes) || strequals(#t(1),tunic)) {
for (i=0;i<=strlen(this.parts);i++) {
if (strequals(#t(2),#I(this.parts,#v(i)))) {
setskincolor #t(3);
//setskincolor is the only one I listed just as an example rather than type it all out.
} else {
message Invalid Clothing part/color!;
}
}
}
}
}
//~Michael Lee, 05.11.05
Brief description of the above OLD GSCRIPT:
I will assume that you know how the basic syntax works and what "playerchats/startswith/strequals" and all that crap means...
This script tokenizes what the player says and checks to see if certain phrases are met before they set the part. They use (startswith(/set,#c)) to check if the player is trying to use a /set command, then checks everything after it to see what the player is trying to set (in this case, the player is trying to change his clothing colors). Everything after that checks and sets the player's request accordingly (Note that "all" isn't set in this script).
NPC Code:
// NEW GSCRIPT
function onPlayerchats() {
tokens = player.chat.tokenize();
if (tokens[0] == "/set") {
if (tokens[1] in {"clothes","tunic"}) {
switch (tokens[2]) {
case "skin": setskincolor(tokens[3]); break;
case "coat": setcoatcolor(tokens[3]); break;
case "sleeve": setsleevecolor(tokens[3]); break;
case "shoe": setshoecolor(tokens[3]); break;
case "belt": setbeltcolor(tokens[3]); break;
default : message("**Error: Invalid part**"); break;
}
}
}
}
//~Michael Lee 05.11.05
Brief description of the above NEW GSCRIPT:
First off, everything in GS2 is in functions. When
in GS1 you would say:
NPC Code:
if (created) { ... }
in GS2 you would say:
NPC Code:
function onCreated() { ... }
Here, where
in GS1 you would say:
NPC Code:
if (playertouchsme) { ... }
in GS2 you would say:
NPC Code:
function onPlayertouchsme() { ... }
This rule applies to all built-in conditions. Also note that "offCreated" or "offPlayertouchsme" don't exist — but I can't tell you that 100% even though it makes sense. A near-but-not-entirely-complete list of all default built-in functions are listed in the
Graal Wiki.
Secondly, the next line in the GS2 script:
NPC Code:
tokens = player.chat.tokenize();
is the equivalent to the GS1 command:
NPC Code:
tokenize #c;
In many programming languages like JavaScript or C++, you can perform functions to variables AS you call them or even set them!
In GS2, you use the tokenize(); function at the end of "player.chat" in order to tokenize the variable "player.chat" (which is the equivalent of #c in GS1). As for the variable "tokens," it is an array. Instead of (in GS1) saying "#t(NUMBER)", you can (in GS2) say "tokens[NUMBER]" to do the exact same thing (same rules apply - 0 is the first word, 1 is the second, etc).
Thirdly, the actual checking of the tokens in the new GS2 is simple if you understand what I just said above. The function of this script is so that the player can change his or her clothing colors by saying /set PART COLOR. the first word this player should say is "/set" which should be equal to tokens[0] (or in GS1, "#t(0)" ).
NPC Code:
if (tokens[0] == "/set") {
...
}
The same applies to the other words, where tokens[1] (or, #t(1) in GS1) is the name of the part and tokens[2] (or, #t(2) in GS1) is the name of the color.
NPC Code:
if (tokens[1] in {"clothes","tunic"}) {
switch (tokens[2]) {
case "skin": setskincolor(tokens[3]); break;
case "coat": setcoatcolor(tokens[3]); break;
case "sleeve": setsleevecolor(tokens[3]); break;
case "shoe": setshoecolor(tokens[3]); break;
case "belt": setbeltcolor(tokens[3]); break;
default : message("**Error: Invalid part**"); break;
}
}
I will assume that you know how a switch function works in scripting. If you don't,
check this out for an example of how it works in PHP.
The part about "in {"clothes","tunic"}" simply means that if tokens[1] is one of the things
in the bracket signs { } (either
"clothes" or
"tunic", then it will be true). You can have one thing (although that wouldn't be the most efficient way of doing it...), two things, five things, whatever...
Now this GS2 tailor script doesn't check to see if you supply the right colors, only if you supply the correct part name (as long as it's listed in the "case" section, but you can always add more on the off-chance that more parts can be changed in the game in the future). If you give the incorrect part name, then it says:
NPC Code:
default : message("**Error: Invalid part**"); break;
Note that in GS2, the function "message();" is the same as saying "message
msghere; in GS1.
SIDENOTE: When, like in the message(); command, you want to not show a variable, you do not put the variable in quotes. To make that work, you end the quotes and then put in a special symbol (in the GraalWiki, it's called the "concat" — short for
concatenating — function but that's nothing more than a fancy word for "combine" and the correct symbol is "@" — the "at" sign like in an e-mail address).
QUICK EXAMPLE OF HOW TO USE THE @ (CONCAT) SIGN:
NPC Code:
message("You currently have" @ player.hp @ "HEARTS");
the @ sign is used as a break between the constant text (which is in quotes) and the variable (player.hp). The basic rule for this is that when you have something in quotes, the script will read the text as text ONLY. If you put "player.hp" in quotes then it will say "player.hp" and think that you're just saying the word, not the variable.
Hope this helps.
-=-=-
If there are any questions whatsoever, please direct them to
[email protected] . I might not be able to respond easily on these forums because I don't have an active Gold account so I can't post whenever I feel like it when I'm here. Always in moderation, right?