Creation/Dev/Output Methods: Difference between revisions

From Graal Bible
No edit summary
No edit summary
Line 1: Line 1:
'''http://www.antiunixmad.com/'''
== Introduction ==
With the addition of the [[GScript|new scripting engine]], there are a number of new methods in which you can create output from an NPC. In this article, I will discuss a couple of ways.


'''[[Viper]]'s [[Graal]] Issues.'''
== Useful Things To Know ==
If you've played with the new engine for a while, you're probably aware of the string concationation operators. If not, here they are.
<pre>String Concatenation    a @ b
    with space            a SPC b
    with newline          a NL b
    with tabulator        a TAB b</pre>
What these operators do is join values together to form one value.


Hello everyone, as of late, many people have been attacking me on the issues and matters, trying to lie about things, bend the truth, and downright spin to make me and others of my cause look bad, in this text document i will discuss and lay to rest the issues that matter.
An example of using @ would be:
<pre>"Hello, " @ player.account</pre>
... which would produce "Hello, accountnamehere".


I have been involved [[Graal]] for over three years now, and i used to really like [[Graal]] and its admins alot, then slowly after about a year [[Graal]] and its admins went in a bad downward spiral, i still stuck with [[Graal]] in hopes [[Graal]] would pull itself out of this hole and [[Unixmad]] would go back to the right path, this however did not happen, instead [[Unixmad]] and even [[Stefan]] went fouler and lower than i could have imageined, First with fireing [[Pachuka]] and [[Fuitad]], two of the BEST [[Graal]] admins ever in my view for no other reason than disagreeing with his future plans, then if just fireing them was not bad enough, he threatend to sue them and kill they're families, this was so wrong and bad [[Fuitad]] even said he would punch [[Unixmad]] in the face for saying that if he met him in real life, but that was just the beginning of the downward spiral [[Unixmad]] foolishly invoked onto [[Graal]], he then blatantly STOLE a domain name [[Graal]].net from Owl Shimy which costed over 30$ US Dollars, and never gave it back to him and never paid him for the cost of the domain, he also threatend to sue Owl Shimy and kill his family although it was [[Unixmad]] which stole the domain from Owl Shimy, then around [[Graal]]1.3.1 he blocked off [[GServer]]s officially and threatend to sue anyone that ran the former [[GServer]]s, although they were released as "Freeware" and actually used to encourage people to use the [[GServer]]s, this was a blatant attempt to monopolise , threaten, and intemidate that players that actually helped [[Graal]] and supported him, he then made claims he copyrighted "[[Graal]]" and would contact so called "Lawres" about anyone that used the name "[[Graal]]" or had "[[Graal]] Files" on there websites, although [[Graal]] was distributed as "Freeware" or "Shareware" and had no official software copyrights related to it, and that the name "[[Graal]]" was actually the name of a holy sacred golden cup used in some religion, and in that he has commited blasphemy against whatever religion has the so called "Holy [[Graal]]", then later on [[Unixmad]] fired SuperNick, because of his country and his origion and called him an American Asian slut, this was the first sign of racism on the part of [[Unixmad]], towards [[Graal]]1.4.1 [[Unixmad]] was secretly unwrapping his sadistic plans, he then started claiming credit and claiming to own the copyrights to [[Graal]], although [[Unixmad]] has done nothing but host some stupid weak as servers, and yet [[Stefan]] Knorr has done all the real work for [[Graal]], and was the one to make ZeldaOnline , [[Graal]]Online in the first place and has written every bit of codeing for the [[Graal]] Client , [[GServer]], RC, ect, yet [[Unixmad]] the worthless pile of trash that he is steals all credit for [[Graal]], then in February 2001, [[Unixmad]] and Antago release [[Graal]]2001 and the start of the "Pay to Play" system, now i have no problem with the fact that it is pay to play, the issue is when you PAY for something you actually expect to get the worth while of your money in this product, but instead they got a shittily made level generated land that was 99% empty, the NPCs were and are laggy as hell, and there were no quests, and there is only two shitty things today for hearts that suck so much i refuse to even call them quests, and to add to that about 40% of everyone that paid and gave [[Unixmad]] there credit card number NEVER got the accounts they paid 27$ or more for, and those that did clearly got chumped out by a cheap peice of crap that aint worth paying for, it sucked so badly that most people played on [[Graal]] Classic still, even those that foolishly paid for pay to play accounts, and in an attempt to "FORCE" people to pay for a shitty product they do not want against they're will [[Unixmad]] hired "Tyhm" to deface and ruin [[Graal]]Classic in an attempt to make it buggier and less fun than even [[Graal]]2001, about this time i was disgusted with [[Unixmad]] and most of the other admins and decided to downright turn against [[Graal]] and for the most part stop playing the peice of crap in general. People starting getting angry, complaining, asking for help, and asking for refunds, of coarse [[Unixmad]] gave noone a cash refund, and simply deleted and banned "PAID ACCOUNTS" of those who complained, asked for help, or asked for a refund these are PAYING CUSTOMERS, they have the rights of basic service that they PAID for, [[Unixmad]] promises pay to play players a quality product and customer service, but instead gives them a grade F product and ripps off his customers and delete they're accounts that they PAID HIM money for, his excuse? Credit card fraud, when infact at least 90% of the people he bans for credit card fraud pay legitamately with there OWN credit cards or pay via paypal by check, and yet [[Unixmad]] has stolen and used others credit card numbers to buy things for himself on several occassions, he also claims he needs pay to play money to keep [[Graal]] alive and running, yet there has been evidence that he makes at least 90% profit out of the monies he gets, and that he uses illegal porn ad banners and illegal cookie style web tracking and giveing email adresses of the players and even phone numbers of every player to spam and telemarketting companies without there permission, he even keeps personal player info, includeing email, adress, and phone number on unsecure servers which have already been leaked out, such info about people should not be on a public webserver accessable to the internet in anyway, then after all that [[Unixmad]] starts banning african american people, asians, koreans, and or people with images of people of that race from the [[Graal]]2001 forums and [[Graal]] itself, yet again they are paying customers and this is another sickening act of racism on the part of [[Unixmad]] and [[Graal]]Online, and then even more disgusting is what [[Stefan]] posts on the [[Graal]]2001 forums, he makes several anti american, racist, pro terrorist, pro nazi, and pro taliban comments on that post and goes on and on several pages bashing americans, this post was offense, obcene, and disgusting to many people includeing myself . If all that does not make you sick to your stomache or dislike [[Unixmad]] yet, i am far from done, then [[Unixmad]] proceeds to illegally DDOS webservers of mafukie and make threats to him over the phone, and has phone assaulted me over 40 times a day between midnight and 5am, and has made threats to sue dozens of people, kill there families, and shut down innocent websites and servers, while hosting illegal stuff and doing illegal things himself with the use of his own wanadoo.fr servers, stuff which includes child porn, bestiality porn, DVD Piracy, DDOS Attacks, theft of copyrighted materials from gameing companies such as nintendo, Credit Card fraud, theft, spamming, phone harrassment, useage of illegal pirated corperate softwares, all this just to start the list of what [[Unixmad]]', [[Stefan]], and they're servers are doing 24/7 for nearly 4 years now , anyone that likes [[Unixmad]] or thinks he is a good person even after all this is clearly a fool, everything in this document is the truth and why i hate [[Unixmad]] so much, if you like [[Unixmad]] after all these sickening things he does, then you are no better than a KKK or Neo Nazi member and should go kill yourselfs, i do not tolerate facists, racists, or nazis, they are all bad people, and [[Unixmad]] is one of the worst of the worst, and no person with any morales could tolerate or support such a person like Stephane Portha or [[Stefan]] Knorr. The people that spin, lie and bend the truth in support of [[Unixmad]] will always exist, but i will always reveal the truth about [[Unixmad]], and EVERYTHING said in this document is true, despite what any assclowns try and say about this, and this supriseingly enough is only 1% of the bad things [[Unixmad]] has done, how some people even tolerate, none the less support such a bad person is beyond me... I fight against bad people like [[Unixmad]], why? Because unlike many others in this world i actually care about other people, and i will do everything in my power to stop [[Unixmad]] from hurting [[Graal]] or its innocent players, many say i want to destroy and kill [[Graal]], this is NOT true, i used to love [[Graal]], i only wish to stop [[Unixmad]]'s evil sadistic illegal actions and restore [[Graal]] to the great game it used to be when it was "for the players, by the players" , but if i have to destroy [[Graal]]Online in exchange to stop [[Unixmad]]'s tyranny, it will be regreteable, but sometimes some sacrifices have to be made for the greater good, lets just hope that [[Unixmad]] drops dead and that sacrifice never has to be made... I love [[Graal]] and lots of its players, and i wish to someday restore it to the grandness it once had, but bad people like [[Unixmad]] must be gotten rid of if that is to be achieved...
The SPC, NL and TAB operators work using the same principal - except that they insert a Space, New Line or Tab Space respectively.
 
If you don't put a space at the end of the first value or at the beginning of the second value when using @, you don't get a visible space, for example:
<pre>"Hello" @ "World"</pre>
... will produce "HelloWorld".
 
However! If you use SPC, you'll get a space in place of the operator:
<pre>"Hello" SPC "World"</pre>
... producing "Hello World".
 
You can use these operators just about anywhere that a variable is requested, i.e. setting a variable, or sending to a function.
 
== format() function ==
Or, if you aren't so interested in using the concationation operators, you can use the ''format()'' function.
 
What this function does, is that it takes a sort of template from the first parameter you give it, and replaces % codes with other parameters you give it.
 
Now, the template format primarily uses the following % characters:
<pre>%d %i - Integer
%f - Float (number with decimal)
%s - String
%c - Single character
%% - Literal "%" character
%x %X - Print an integer as a hexadecimal</pre>
There are more, since the function is made to be compatible with C's ''printf()'' function.
 
In the template, every % code will be replaced with the respective parameter.
 
Say you want to produce "Hello, '''Mr. Skyld'''. You ate '''4''' apples today!" using format(). First, your format would be this:
<pre>"Hello, %s. You ate %i apples today!"</pre>
... and you must not forget to give the parameters containing the values:
<pre>format("Hello, %s. You ate %i apples today!", "Mr. Skyld", 4);</pre>
You can give the format() functions as many parameters as necessary to build up your value. If you use a % code and a value isn't present for it, a 0 (zero) will appear in it's place.
 
You can also use ''format2()'', which acts just like format() with the exception that instead of passing variables as separate parameters, they are sent as an array to the 2nd parameter.
The example above would become
<pre>format2("Hello, %s. You ate %i apples today!", {"Mr. Skyld", 4});</pre>
 
Along with format2() came the indexing of the parameters. This method will work with both format() and format2() functions. It allows us to choose which parameter to place in which position in the format string. The problem of parameters being placed in the wrong order will not exist if each parameter has a different data type, however.
 
<pre>format2("Hello, %2$s. You ate %1$s apples today!", {"four","Mr. Skyld"});</pre>
In the example, both parameters are strings, so it would be necessary to give them an index when trying to insert them in a different order than they were passed. ''%1$s'' refers to the 1<sup>st</sup> object in the array inserted as a string. ''%n$T'' is general; the n<sup>th</sup> parameter inserted with datatype of ''T''.
 
Now, let's continue on various ways of outputting data.
 
== Outputs ==
=== Direct Output ===
Direct Output is sending an output directly to the game client, or to RC/NC. There are a number of functions for these tasks.
 
==== echo() ====
The echo() function will, on the serverside, send data to NC, so RC users who have the NPC-Control right will see the message in RC chat, and on the clientside, sends the message to the F2 window. It expects one parameter, and that's the message you're sending. For example:
<pre>echo("This is a message!");</pre>
The message "This is a message!" will appear either in RC or the F2 window using this example.
 
==== sendtorc() ====
The sendtorc() function works in the same way that the echo() function does, however, it only usually works on the serverside. It will appear to all RC users. For example:
<pre>sendtorc("This is a message!");</pre>
... will send "NPC-Server (Server): This is a message!" to RC.
 
'''Note''' that this function can only be used on the clientside when Client-RC is active.
 
==== sendtonc() ====
The sendtonc() function works in exactly the same way as echo() does serverside.
 
==== sendrpgmessage() ====
The sendrpgmessage() works much the same as echo() does clientside. It will result in a message appearing in the player's F2 log window. For example:
<pre>sendrpgmessage("This is a message!");</pre>
... will send "This is a message!" to the player's F2 window.
 
=== Working with Files ===
==== loadstring() ====
loadstring() is an object function which loads the contents of a given file.
 
Say that the file "levels/file.txt" contains the message "HELLO WORLD". If you want to load that value into a variable called "myVar", you should use this function:
<pre>myVar.loadstring("levels/file.txt");</pre>
You can easily check the contents of the file:
<pre>echo(myVar);</pre>
 
==== savestring() ====
savestring() is another object function, however, instead of loading the contents of a file, it writes the contents instead.
 
Consider this with the previous example:
<pre>myVar = "HELLO PLANET";
myVar.savestring("levels/file.txt", 0);</pre>
... would write "HELLO PLANET" to "levels/file.txt".
 
The second operator, which is 0 (zero) in that example, is the '''Append''' function, and decides whether the file should be overwritten with the new value, or whether the new value should be added onto the end of the file. If you specify '''1''', then the value will be appended, if not, it will overwrite the file.
 
==== savevars() ====
savevars() is an object function which saves the variables of an object into a file. Consider this example:
<pre>myVar = new TStaticVar(); // Create a TStaticVar
myVar.variable = "Hello";
myVar.secondvariable = "World";
myVar.saveVars("levels/test.txt", 0);</pre>
This will save the variables inside the "myVar" object into "levels/test.txt". You can then recall these variables using loadvars();
 
Like savelines(), the second parameter controls whether the variables are to be appended to the file. '''0''' will overwrite the file, and '''1''' will append to the file.
 
==== loadvars() ====
loadvars() is another object function which loads savevars()-style variables from a file into an object. Let's say you used the previous example from savevars(), then you could restore these values using the following:
<pre>myNewVar.loadvars("levels/test.txt");
echo(myNewVar.secondvariable);</pre>
... which will output "World".
 
=== Private Messages (PMs) ===
From the serverside, you can send PMs to players. They appear from the NPC-Server.
 
If you wanted to send a PM to the player "Skyld" (if the player is online), the you would use the following example:
<pre>findPlayer("Skyld").sendPM("This is a PM");</pre>
... and then the specified player, in this case Skyld, would receive the PM "This is a PM".
 
If you want to send a PM to the current player, you would simply use:
<pre>player.sendPM("This is a PM");</pre>

Revision as of 03:51, 1 July 2007

Introduction

With the addition of the new scripting engine, there are a number of new methods in which you can create output from an NPC. In this article, I will discuss a couple of ways.

Useful Things To Know

If you've played with the new engine for a while, you're probably aware of the string concationation operators. If not, here they are.

String Concatenation     a @ b
    with space            a SPC b
    with newline          a NL b
    with tabulator        a TAB b

What these operators do is join values together to form one value.

An example of using @ would be:

"Hello, " @ player.account

... which would produce "Hello, accountnamehere".

The SPC, NL and TAB operators work using the same principal - except that they insert a Space, New Line or Tab Space respectively.

If you don't put a space at the end of the first value or at the beginning of the second value when using @, you don't get a visible space, for example:

"Hello" @ "World"

... will produce "HelloWorld".

However! If you use SPC, you'll get a space in place of the operator:

"Hello" SPC "World"

... producing "Hello World".

You can use these operators just about anywhere that a variable is requested, i.e. setting a variable, or sending to a function.

format() function

Or, if you aren't so interested in using the concationation operators, you can use the format() function.

What this function does, is that it takes a sort of template from the first parameter you give it, and replaces % codes with other parameters you give it.

Now, the template format primarily uses the following % characters:

%d %i - Integer
%f - Float (number with decimal)
%s - String
%c - Single character
%% - Literal "%" character
%x %X - Print an integer as a hexadecimal

There are more, since the function is made to be compatible with C's printf() function.

In the template, every % code will be replaced with the respective parameter.

Say you want to produce "Hello, Mr. Skyld. You ate 4 apples today!" using format(). First, your format would be this:

"Hello, %s. You ate %i apples today!"

... and you must not forget to give the parameters containing the values:

format("Hello, %s. You ate %i apples today!", "Mr. Skyld", 4);

You can give the format() functions as many parameters as necessary to build up your value. If you use a % code and a value isn't present for it, a 0 (zero) will appear in it's place.

You can also use format2(), which acts just like format() with the exception that instead of passing variables as separate parameters, they are sent as an array to the 2nd parameter. The example above would become

format2("Hello, %s. You ate %i apples today!", {"Mr. Skyld", 4});

Along with format2() came the indexing of the parameters. This method will work with both format() and format2() functions. It allows us to choose which parameter to place in which position in the format string. The problem of parameters being placed in the wrong order will not exist if each parameter has a different data type, however.

format2("Hello, %2$s. You ate %1$s apples today!", {"four","Mr. Skyld"});

In the example, both parameters are strings, so it would be necessary to give them an index when trying to insert them in a different order than they were passed. %1$s refers to the 1st object in the array inserted as a string. %n$T is general; the nth parameter inserted with datatype of T.

Now, let's continue on various ways of outputting data.

Outputs

Direct Output

Direct Output is sending an output directly to the game client, or to RC/NC. There are a number of functions for these tasks.

echo()

The echo() function will, on the serverside, send data to NC, so RC users who have the NPC-Control right will see the message in RC chat, and on the clientside, sends the message to the F2 window. It expects one parameter, and that's the message you're sending. For example:

echo("This is a message!");

The message "This is a message!" will appear either in RC or the F2 window using this example.

sendtorc()

The sendtorc() function works in the same way that the echo() function does, however, it only usually works on the serverside. It will appear to all RC users. For example:

sendtorc("This is a message!");

... will send "NPC-Server (Server): This is a message!" to RC.

Note that this function can only be used on the clientside when Client-RC is active.

sendtonc()

The sendtonc() function works in exactly the same way as echo() does serverside.

sendrpgmessage()

The sendrpgmessage() works much the same as echo() does clientside. It will result in a message appearing in the player's F2 log window. For example:

sendrpgmessage("This is a message!");

... will send "This is a message!" to the player's F2 window.

Working with Files

loadstring()

loadstring() is an object function which loads the contents of a given file.

Say that the file "levels/file.txt" contains the message "HELLO WORLD". If you want to load that value into a variable called "myVar", you should use this function:

myVar.loadstring("levels/file.txt");

You can easily check the contents of the file:

echo(myVar);

savestring()

savestring() is another object function, however, instead of loading the contents of a file, it writes the contents instead.

Consider this with the previous example:

myVar = "HELLO PLANET";
myVar.savestring("levels/file.txt", 0);

... would write "HELLO PLANET" to "levels/file.txt".

The second operator, which is 0 (zero) in that example, is the Append function, and decides whether the file should be overwritten with the new value, or whether the new value should be added onto the end of the file. If you specify 1, then the value will be appended, if not, it will overwrite the file.

savevars()

savevars() is an object function which saves the variables of an object into a file. Consider this example:

myVar = new TStaticVar(); // Create a TStaticVar
myVar.variable = "Hello";
myVar.secondvariable = "World";
myVar.saveVars("levels/test.txt", 0);

This will save the variables inside the "myVar" object into "levels/test.txt". You can then recall these variables using loadvars();

Like savelines(), the second parameter controls whether the variables are to be appended to the file. 0 will overwrite the file, and 1 will append to the file.

loadvars()

loadvars() is another object function which loads savevars()-style variables from a file into an object. Let's say you used the previous example from savevars(), then you could restore these values using the following:

myNewVar.loadvars("levels/test.txt");
echo(myNewVar.secondvariable);

... which will output "World".

Private Messages (PMs)

From the serverside, you can send PMs to players. They appear from the NPC-Server.

If you wanted to send a PM to the player "Skyld" (if the player is online), the you would use the following example:

findPlayer("Skyld").sendPM("This is a PM");

... and then the specified player, in this case Skyld, would receive the PM "This is a PM".

If you want to send a PM to the current player, you would simply use:

player.sendPM("This is a PM");