Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Basic NO PREVIOUS KNOWLEDGE TUTORIALS (https://forums.graalonline.com/forums/showthread.php?t=73995)

DustyPorViva 05-16-2007 04:22 AM

Quote:

Originally Posted by PrinceOfKenshin (Post 1308303)
not that simple lol you would use keydown gani scripts. Is that it?

What do you mean?

killerogue 05-16-2007 04:40 AM

I think he means something along the lines of pressing a key and it playing a gani, i.e.:

PHP Code:

function onKeyPressedkeynrkeyname )
{
  if (
keyname == "s")
  {
    
setani("fireani""");
  }



E: My final suggestion, if you have a friend who's a good scripter...ask him to tutor you. It's easier to learn from someone rather than something ( I.E. the wiki ). The wiki's just there for informational purposes really, otherwises it's just..blegh.

Andy0687 05-16-2007 04:42 AM

Quote:

Originally Posted by killerogue (Post 1308310)
I never claimed I was good scripter. >_> Nor a scripter when I couldn't script anything. IF anything I was eager to learn, lazy to do anything.

I was hoping you would pay more attention to the talking down to people part, or does this not seem familer?

http://forums.graalonline.com/forums...ad.php?t=67451

All im saying is, when you yourself were having trouble, you looked for help and expected it/would hide behind the whole "im new" thing. When people would flame you for how bad you were, did you not get upset? So why would you in turn do that exact same thing to a new scripter? Give them a chance to learn, its not fluid for some people, and eventually they may realise its not for them.

Encourage not Discourage

DustyPorViva 05-16-2007 04:55 AM

Quote:

Originally Posted by killerogue (Post 1308315)
I think he means something along the lines of pressing a key and it playing a gani, i.e.:

I don't think that was the context of his post. I assume it had something to do with what I posted, but I have no idea.

Rapidwolve 05-16-2007 05:37 AM

Quote:

Originally Posted by Andy0687 (Post 1308316)
I was hoping you would pay more attention to the talking down to people part, or does this not seem familer?

http://forums.graalonline.com/forums...ad.php?t=67451

All im saying is, when you yourself were having trouble, you looked for help and expected it/would hide behind the whole "im new" thing. When people would flame you for how bad you were, did you not get upset? So why would you in turn do that exact same thing to a new scripter? Give them a chance to learn, its not fluid for some people, and eventually they may realise its not for them.

Encourage not Discourage

I've also noticed this attitude of his, I never said anything though. I kept it to myself.

killerogue 05-16-2007 05:49 AM

Quote:

Originally Posted by Andy0687 (Post 1308316)
Stuff

I didn't get mad or upset about that. :O Also, that would have been the first time I attempted to learn. Not the second, in which I was successful.

You'll also notice James, that I had good reasoning behind the things I said. If I have an attitude it's because of personal reasons, and that isn't anything to discuss here and you're both ( and rapidwolve ) right that I shouldn't be taking it out on people.

And, what I'm saying now is stemming from other encounters with Switch involving him acting like a brass-assed monkey.

Deadly_Killer 05-16-2007 06:36 AM

Quote:

Originally Posted by killerogue (Post 1308333)
Not the second, in which I was successful.

According to whom? :p

killerogue 05-16-2007 06:38 AM

Quote:

Originally Posted by Deadly_Killer (Post 1308347)
According to whom? :p

Good one! :D

But in terms of success, I mean being able to understand and use gscript, somewhat effectively I guess.

Deadly_Killer 05-16-2007 07:17 AM

Quote:

Originally Posted by killerogue (Post 1308349)
Good one! :D

But in terms of success, I mean being able to understand and use gscript, somewhat effectively I guess.

;)

zokemon 05-16-2007 07:51 AM

I try to teach lots of people GS2 who choose to come to me and it usually works rather well. I PERSONNALY believe the best way to start teaching it is to explain the following:
- How a script is read (compiled together and all the functions are stored to be run when "called")
- The 2 different things you can do in a gs2 script (call functions and set variables)
- How functions work (Also: calling built-in functions [such as onCreated()] and redefining built-in functions [such as function show() {}])
- The 4 variable types: (Float, String, Object, Array)

I believe the last of those things to be the MOST important to actually grasp the concepts of gs2 coding. I am a GUI man though, so my ideas may just be biased as I use objects a lot.

If anyone wants to try to make a guide like such, feel free!
I should get around to actually making one sometime (when I'm not so swamped D: ).

killerogue 05-16-2007 08:19 AM

Thought I'd do my best to explain objects simply, and a few things of what you can do with them.

This Lesson One, focuses mainly on using text files with objects.

PHP Code:

// Lesson 1: Objects and How They Work

// Today we're going to make objects and use a few object functions!
// Objects must be created by making TStaticVars like below:

// temp.objName = new TStaticVar();

// Keep in mine, the capitalization in my var name is just a stylistic
// choice and has no effect on the outcome of the script. Tho, it's
// a good idea to make sure you've got all the capitalization correct 
// when using TStaticVars() and things like it!

// Let's Begin!

function onCreated()
{
  
temp.newObj = new TStaticVar(); // Here we create the object.
  
  // Below we will define some variables of the new object
  // It being a created object, we can create as many vars
  // as we want for the damn thing. :)
  
  
temp.newObj.personOne   "Stan";
  
temp.newObj.personTwo   "Zero";
  
temp.newObj.personThree "Twinny";
  
temp.newObj.personFour  "James";
  
  
// With the newly created variables above, there are a number 
  // of things you can do with the information stored in each variable
  // in the object.
  
  // Let's look at a few!
  
  // * - Files - * \\
  // Here we will save the vars into a text file:
  
  // temp.newObj.saveVars("textfilepath/textfilename.txt", 0);
  
  // Keep in mind saveLines is another form of saving variables
  // from objects into text files. However it saves each var line
  // for line. I'm not too big on explanations right now as I don't
  // use saveLines often.
  
  // The first param for saveVars() is pretty obvious. :p
  // The second param however, decides whether the file is overwritten,
  // or merely if the file is just added onto!
  
  
  // Having saved these informations into a text file, we can then later
  // receive this information through a command we shall learn in the next
  // lesson, dubbed: loadVars();
  
  /* Special Practice Notes:
        1. Things like saveVars(), or loadVars() are object only functions.
           Meaning they can only be attached onto the tail of an object that
           has, or in the case of loadVars sometimes, doesn't have information in it.
  */
}

// Lesson 1: Objects and How They Work, cont.

  // Now that you understand the basics of objects and how you can understand the 
  // uses and storing of informations inside of them. Let's look a bit deeper
  // our target for this lesson is loadVars.
  
  // Now, when you first create an object, it usually has nothing in it.
  // Of course that applies to IF you create the object first, but in my opinion,
  // it's always best to clearly state out the new static variable assignment.
  
  //Like before loadVars is am object only function, let's take a look at it's use.
  
  
function onStuff()
  {
    
// Again we create the object.
  
    
temp.newObj = new TStaticVar();
    
    
// Now we load the vars from a text file, consider your test text file is named
    // test.txt. And it contains the 5 names from before. We simply do this:
    
    
temp.newObj.loadVars("test.txt");
    
    
// But what if you wanted to get the information from an object through a script?
    // We certainly can't just yank it out now can we? Of course not!
    
    // There's only one sure shot thing that can get us the variables we want, 
    // and it's an object function! Aptly named, getDynamicVarNames().
    
    // Dynamic variables are variables that never stay the same and could change
    // at any time they or the person controlling them wishes for them to.
    
    // Now the way to access the dynamic variables is a bit more difficult than the talk
    // that's been going on around here. We're going to use a "for each" look,
    // to go through the dynamic var names of an object.
    
    // The for each loop allows us to apply a variable name to each piece of information
    // in an array. So let's do something like this:
    
    
for (temp.oVtemp.newObj.getDynamicVarNames()) // In case you were wondering, getDynamicVarNames returns an array allowing for a for each loop to have it's way with the text file/
    
{
      
temp.someArray.add(temp.oV);
    }
    
// We can now echo all the information from the dynamic variables in the object because
    // the for each loop going through the values, added each value to "temp.someArray" one value
    // at a time.
    
    // Now that array contains all the information from the object. A simple way to echo all this info.
    // to RC. Like so:
    
    // echo(temp.someArray);
  



zokemon 05-16-2007 08:45 AM

The problem with that as being a starting tutorial Stan is, You don't exactly explain what a function or object IS.

Pimmeh 05-16-2007 09:19 AM

I think the most important thing for me, and I think others as well, is to have a list of thingies that I can pull out of my sleeve while scripting... I learned the very basics (compared to dontblock;drawoverplayer shizzle from GS1) from Chandler (cool guy btw :) ) but I really should find someone to learn the more complex things like setting a UI or a staffblock that you can spawn with a mouseclick if you have a certain weapon ready.
But the most important thing is how the heck I can be able to UNDERSTAND what is happening in really important scripts. This helped me a lot with GS1.

Crono 05-16-2007 12:56 PM

gscript 2 is just more confusing for nublets (hell it confuses me). experiment offline with gscript 1 to learn the basics then move on to gscript 2.

im sure im one of the few here who has this opinion though

Skyld 05-16-2007 01:56 PM

Quote:

Originally Posted by Rapidwolve (Post 1308192)
Yeah I know, I am a regular user of your wiki. Was getting ready to contribute more functions but it was down. :(

It seems to be back up now!

http://skyld.vip.graal.net/

xXziroXx 05-16-2007 02:14 PM

Quote:

Originally Posted by Skyld (Post 1308395)
It seems to be back up now!

http://skyld.vip.graal.net/

Yay! :D

zokemon 05-16-2007 02:20 PM

I personally just think it depends the type of person. GS2 was a ton easier to understand for me then GS1 was.

GS2 is easier for people that are in the mindset of object oriented coding. Otherwise, it seems a ton harder then GS1.

Rapidwolve 05-16-2007 09:06 PM

Quote:

Originally Posted by Gerami (Post 1308392)
gscript 2 is just more confusing for nublets (hell it confuses me). experiment offline with gscript 1 to learn the basics then move on to gscript 2.

im sure im one of the few here who has this opinion though

I also anyone who wants to learn how to GScript should start with GS1, this way they can get all the practice they want and its offline so they can't do any harm to a server. Converting from GS1 to GS2 is really easy, so once you got GS1 down you pretty much have GS2 down, atleast thats how it was for me.

Quote:

Originally Posted by Skyld (Post 1308395)
It seems to be back up now!

http://skyld.vip.graal.net/

Yay

Switch 05-16-2007 09:25 PM

Quote:

Originally Posted by DustyPorViva (Post 1308240)
Sadly I find the wiki lacking one thing(I've yet to see skyld's though), and that is actually what goes in commands. All it tells you is if it's a floating, integer, or string. That doesn't really help much...

Anyways, for Switch:
PHP Code:

function onCreated() 
{
  
player.chat "Stuff.";


function onCreated() // This is a function. Before GS2, things like this were called in events. Basically, if it happened, execute any code in the parenthesis. In GS1, it would be if (created) {}, but all that changed in GS2. Events were translated into their own functions. So basically this means, when the NPC is created, execute everything in the parenthesis.

{...} // As explained above, parenthesis are closed around any amount of commands executed when an event is called. All commands must be executed with an event/function and closed inside parenthesis.

player.chat = "Stuff."; // player.* is associated with anything for the player. This can be player.hearts, for their hearts, player.ap, for their ap, player.x, for their x coordinate, and so on. So, taking that, and taking the knowledge that = is assign, means that you are assigning something to the player's chat, which means you'll force them to say something. "Stuff." is a string. A string is alphanumerical. That means anything not a variable, floating value, integer, has to be enclosed in quotes, or else it won't be assigned. If you want to get basic, text has to be in quotes. And lastly, the semi-colon has to be after every command. Anytime you do 'something' end it with a semi-colon before you move onto the next thing.

Except what's CREATED mean, then? :p

Quote:

Originally Posted by Rapidwolve (Post 1308277)
The world would be a better place if there were more people like you.

Definitely :D

Rapidwolve 05-16-2007 09:28 PM

CREATED is when the weapon is first initialized or updated.

DustyPorViva 05-16-2007 09:46 PM

Well if you're joking, then, it means when God said let there be an NPC.
If you're not, then it means exactly what Rapidwolve said. The first time the NPC is 'loaded'(first time a/the[not sure] player enters the level), and is not to be confused with onPlayerenters, which executes each time a/the player enters the level, or like mentioned, the NPC/level is updated.

Switch 05-16-2007 09:55 PM

Quote:

Originally Posted by DustyPorViva (Post 1308497)
it means when God said let there be an NPC.

Thanks for being an ass ;( Like we said we have NO backround of ANYTHING x.x

JkWhoSaysNi 05-16-2007 10:27 PM

Quote:

Originally Posted by Rapidwolve (Post 1308459)
I also anyone who wants to learn how to GScript should start with GS1, this way they can get all the practice they want and its offline so they can't do any harm to a server. Converting from GS1 to GS2 is really easy, so once you got GS1 down you pretty much have GS2 down, atleast thats how it was for me.



Yay

GS1 is harder to learn though because the function names are horrible and it doesn't support strings decently. I still have to look up the function names every time I read a GS1 script.

GS2 is far easier to learn and it's what they'll need to know anyway. Why bother learning something that's already outdated? Not only that, all the stuff on the both the graal bible and Skyld's wiki have GS2 examples and few (if any?) GS1 examples.

Quote:

CREATED is when the weapon is first initialized or updated.
Nope. onInitialized is when the weapon/npc is first created by the NPC server. The onCreated function is called whenever the NPC is created or updated.

killerogue 05-16-2007 10:31 PM

Quote:

Originally Posted by Switch (Post 1308503)
Thanks for being an ass ;( Like we said we have NO backround of ANYTHING x.x

Thank you for being an ass. Because the guy was just joking, then he provided you with a serious explanation.

And you begin to wonder why it is, that I dislike you.

@ Zero, well to be honest...lol..I did't give an explanation because I don't know the word for word definition of an object and I'm not too good at explaining singular things. :(

Admins 05-16-2007 10:38 PM

onCreated = when the npc is created/added, or you update the script (this behaviour has been changed from GS1, to avoid needing to reset the npc all the time)
onInitialized = called on server restart

Twinny 05-17-2007 12:32 AM

Quote:

Originally Posted by Stefan (Post 1308520)
onCreated = when the npc is created/added, or you update the script (this behaviour has been changed from GS1, to avoid needing to reset the npc all the time)
onInitialized = called on server restart

PHP Code:

function onInitialized()
{
  
this.whoops++;
  
printf("This is the %i time NPC-Server has died",this.whoops);


:D

Sum41Freeeeek 05-17-2007 01:25 AM

I remember the old old gscript bible. It explained everything for newbie scripters.

PrinceOfKenshin 05-17-2007 09:29 PM

I was reading the gscript thing skyld made (very helpful not to mention) but i dont get what you use parameters are for. Someone want to explain?

killerogue 05-17-2007 09:42 PM

Parameters are information based inside the current event. So if I did something like this.

PHP Code:

function onCreated()
{
  
temp.chatText "stuff";
  
this.doFunction(temp.chatText);
}

function 
doFunction()
{
  echo(
params[0]);


Take a guess what that would echo? :)

DustyPorViva 05-17-2007 09:44 PM

It's really just passing information from one thing to another. Like passing a note in class. Like with a triggeraction, the destination script has no way of knowing what, say, your level is, unless you send it through the triggeraction. Say you have a gani for hammer, and you have different levels of hammers, level 1, level 2, gold hammer, and different images for each hammer. You can make ONE gani show different images for each level of the hammer, instead of a gani for each level. But, it must be told what level the hammer is, so you pass it through a parameter.

PrinceOfKenshin 05-17-2007 09:49 PM

Quote:

Originally Posted by killerogue (Post 1308808)
Parameters are information based inside the current event. So if I did something like this.

PHP Code:

function onCreated()
{
  
temp.chatText "stuff";
  
this.doFunction(temp.chatText);
}

function 
doFunction()
{
  echo(
params[0]);


Take a guess what that would echo? :)

the temp.chatText = "stuff"; ?

Crow 05-17-2007 09:52 PM

Quote:

Originally Posted by zokemon (Post 1308362)
- The 4 variable types: (Float, String, Object, Array)

GScript variables are always 'Double' though. Sorry, just had to point that out :p

DustyPorViva 05-17-2007 09:56 PM

Well, he's passing a variable, and it's information as a parameter. That means when he goes to echo, he's echoing parameter 0(the first parameter), which is the variable temp.chatText. But, it is echoing the variables information, so it will echo just stuff.

Switch 05-17-2007 10:33 PM

Q: Parameters are (?)

Chompy 05-17-2007 10:34 PM

Quote:

Originally Posted by Switch (Post 1308821)
Q: Parameters are (?)

Do you even read posts before you post a post by yourself?

PS: Post #70 or #73

PrinceOfKenshin 05-17-2007 11:15 PM

Quote:

Originally Posted by DustyPorViva (Post 1308816)
Well, he's passing a variable, and it's information as a parameter. That means when he goes to echo, he's echoing parameter 0(the first parameter), which is the variable temp.chatText. But, it is echoing the variables information, so it will echo just stuff.

gotcha thats what i mean = ) thanks i will post if i don't get anything else..

killerogue 05-17-2007 11:20 PM

Quote:

Originally Posted by PrinceOfKenshin (Post 1308811)
the temp.chatText = "stuff"; ?

Do you even know what a string is? >_> I suggest you try that before you're trying to pass params in functions.

Quote:

Originally Posted by Switch (Post 1308821)
Q: Parameters are (?)

I'm sorry, if you can't think to read for yourself then I can't help you as I just posted an explanation on the matter. And Dusty posted 2.

PrinceOfKenshin 05-18-2007 02:10 AM

Quote:

Originally Posted by killerogue (Post 1308836)
Do you even know what a string is? >_> I suggest you try that before you're trying to pass params in functions.

yes i do x.x

killerogue 05-18-2007 02:16 AM

Well, your question wasn't very clear so I didn't understand you. Sorry if I insulted you.

zokemon 05-18-2007 05:27 AM

Quote:

Originally Posted by Crow (Post 1308814)
GScript variables are always 'Double' though. Sorry, just had to point that out :p

In C++, yes. But if you use the wiki.graal.net at all you will notice every parameter marked with one of these 4 variable types. You don't ever see one marked with "double".


All times are GMT +2. The time now is 07:35 AM.

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