Page 1 of 2 1 2 LastLast
Results 1 to 10 of 16

Thread: Gs2 for the Noobs #5

  1. #1
    Street Boss John's Avatar
    Join Date
    Jun 2013
    Location
    Lebanon
    Posts
    825

    Gs2 for the Noobs #5

    Hey guys, this tutorial will show the difference of classes, Databases, and weapons in Graal, as-well as showing some very basic examples of what you can do with them. And this will also be covering the use of an 'object'/NPC inside a level, and will most-likely introduce you to player client and clientr variables.

    weapons:

    A weapon is not what it sounds like, it's not a knife, or a sword in here, the weapon is a script that is attached to the player, it's usually a movement system, or a GUI, or some hack protection... Some servers (including iEra), has some of its' items scripts in their weapons.

    In the past 4 tutorials, we've been working with this type of scripts... You know when someone updates a weapon every time, it will echo() something in RC along the lines of:

    Weapon/GUI-script WeaponName added/updated by Graal#

    Most if not all functions are present in weapons, but remember that a 'weapon' CANNOT be used as an object, it cannot be present in a level, nor walk around a player, nor speak to anyone.

    You can triggerserver(), triggerclient() and do several other stuff inside a weapon...

    NPCs:

    Some of you might know what an NPC is, or at-least that it stands for Non-Player Character.

    First, you need to know how to place an NPC, open GraalEditor (also known as Level Editor), and select 'Baddies, NPCs, Chests' on the right... (Don't worry, nobody uses baddies and chests, the best thing to use is an NPC because you can script a baddy or a chest using an NPC)



    And those are the two types of NPCs available:


    We're going to use the one that is on the left, because the one on the right uses Gs1, and this is a Gs2 lesson so...

    The following script is self explanatory, which shows a standing still NPC.

    PHP Code:
    function onCreated() {
      
    this.showcharacter();

      
    this.body "body1.png";
      
    this.head "head1.png";
      
    this.shield "shield1.png":
      
    this.attr[1] = "hat1.png";
      
    this.nick "Jean-Paul Marie Jacques-Wilbert";
      
    this.colors[0] = "black";
      
    this.colors[1] = "black";
      
    this.colors[2] = "black";
      
    this.colors[3] = "white";
      
    this.colors[4] = "black";
      
    this.ani "idle";
      
    this.ap 100;

    Place it inside your NPC script and just upload the level to your server, once done, you'll see the NPC standing in that server.

    But what can you exactly do with it?
    Here it comes... A widely used built-in function WITH A GRAMMAR ERROR, is onPlayerTouchsMe()!

    What this does, it just checks when the player has touched the NPC, and when he does, it will trigger that function...

    Add to the script:
    PHP Code:
    function onPlayerTouchsMe() {
      
    player.chat "Ahh!! Sorry I keep touching you.... (awkward!!)";

    This function is used on iEra's doors! I'll give an example on it later...
    You can also warp a player to another level too.

    Example:
    PHP Code:
    function onPlayerTouchsMe() {
      
    player.setlevel2("levelname.nw"3020); // setlevel2(levelname, x, y);

    BTW, the this. prefix specifies to the object, so if you want to change the coordinates, the chat or anything on the NPC, simply use:
    PHP Code:
    this.10;
    this.30;
    this.2// Z axis is not 'really' used in 2D games, but can be used as a dis-actual offset of the y axis

    this.chat "My name is Brog and I kill pandas, they eat my bamboo!"
    An NPC DOES NOT contain triggerserver() and triggerclient() ... (actually, it does, but somehow it broke in time so they just use triggeraction in the meantime as a triggerserver() - for triggerclient, there's nothing, but you can always switch to the attr array which is available in both sections)

    Having an object in CLIENTSIDE, will make you ONLY YOU see that.
    Example:
    PHP Code:
    //#CLIENTSIDE
    function onPlayerTouchsMe() {
      
    this.chat "I'm noobish"//because this function is under CLIENTSIDE, you will see the NPC say the chat, but other players won't unless they touch him too!

    So this is what an NPC actually is, but not all NPCs are supposed to be visible, some NPCs have this.image = ""; and does a lot of stuff.

    Let's take for example a race. You know when you touch that very last part you will get warped, right?

    Then the script located in that last block is:
    PHP Code:
    function onPlayerTouchsMe() {
      
    player.setlevel2(this.level1020); // 10 and 20 are the coordinates of the winning spot

    But there's a problem here, now everyone that touches this NPC will be able to get warped to the winning spot, right? We only want one of them to get warped and the who that is the first.
    So I'm going to make a variable called 'winner', and what this will do is store the graalid of the first person inside this variable, then check IF the guy's ID is 'winner', warp him there.

    PHP Code:
    function onCreated() {
      
    this.winner "nobody";
    }

    function 
    onPlayerTouchsMe() {
      if (
    this.winner != player.account && this.winner != "nobody") {
        return; 
    // if the winner variable is not equals to the player account AND not equal "nobody", then go back, don't read the next code.
      
    } else {
        
    this.winner player.account// Why did I use this.? Because I want the variable to stay here when another player touches it!
        
    player.setlevel2(this.level1321.5); // warp the player to the winning arena
      
    }

    classes:
    This is a really important notion to learn.

    A class is not what you go to school and watch, it's not where you can stick bubblegum on the side of your table
    What 'class' means here, is a NPC script, that can be given to several others.

    Do you know Crate Race in iEra?
    Do you know how every crate is scripted? Here's how:

    PHP Code:
    //#CLIENTSIDE
    function onCreated() {
      
    setTimer(1); // Call onTimeOut() after 1 second
    }

    function 
    onTimeOut() {
      
    temp.randomnumber random(0100); // A random number between 0 and 100
      
      
    if (temp.randomnumber 50) { // if the random number is bigger than 50, hide
        
    this.hide();
      } else { 
    // if not, then show
        
    this.show();
      } 

      
    setTimer(1); // Call onTimeOut() again after 1 second.

    So we copy this script on every crate NPC and make a nice road with it.
    But here comes snk and tells us that, "Hey John, 1 second is way too much to change the visibility of the crates, how about you make it 0.5 seconds?"... And here's our problem, how are we gonna change from 1 second to 0.5 seconds in ALL the NPCs?! Oh my, I'm going to have to change it in EVERY NPC I've put the script in!

    Have no fear, Classes are here!

    What you can do with a class, is use 1 scripts, and connect them to any NPC/Weapon/Database you want!

    Let's create a new Class and call it whatever you want, I will call mine, "johnisawesome" (I'm too modest).

    How? Just press this icon: on Client-RC, then press the cross on the left in -> ->

    Okay, now that we have created our class, all we have to do is put our Crate script inside and press Apply.

    But we haven't linked the class to the NPC yet! How to do that?
    There's a default function called join(classname).

    So what we will put in the Crate NPC is:
    PHP Code:
    this.join("johnisawesome"); 

    Now, update the level in game and you will see that crates are working fine! And if snk wants you to change something in the Crate script all you have to do is just change it in the class, and it will auto change to all the crates in the level!

    This is one use of the classes in Graal.

    One thing you need to know in classes, triggerserver() and triggerclient() do not always work.

    databases:
    DBs are a little bit more advanced, they are the combination of weapons and classes...

    Here's a small information box about each of them:

    Weapons
    • Can be added to players
    • Cannot have a location on a map (as in X, Y and levelname)
    • Does not save variables
    • Cannot be attached to objects/players using join()
    • Allows triggerserver() and triggerclient()
    • Is static


    Classes
    • Can be linked to players
    • Can have a location on a map (as in X, Y and levelname)
    • Does not save variables
    • Can be attached to objects/players using join()
    • Does not allow triggerserver() and triggerclient()
    • Is not static


    Databases
    • Cannot be added to players
    • Can have a location on a map (as in X, Y and levelname)
    • Does save variables
    • Cannot be attached to objects/players using join()
    • Allows triggerserver() and triggerclient()
    • Is static
    So the thing is, what does 'static' mean and what does it mean by, it saves variables?

    But first, to create a database, do the same thing we did with Classes but with Database NPCs.

    Once created, you'd see (that's an example of Gang Wars database).

    Flags are the variables used using the 'this.'.
    And the Script is, well, the script.

    Press on Edit Script, type in:
    PHP Code:
    function onCreated() {
      
    this.something "Hello";

    Then press apply, and go to Edit Flags and you can see that there's written something=Hello

    Now if you change the script to:
    PHP Code:
    function onCreated() {
      echo(
    this.something);

    It would echo Hello because the this.something variable was saved in the database.

    So this.something is a saved variable, this is where server store their items, images, hats, and stuff like that.
    Last edited by John; 02-14-2014 at 11:09 AM.
    -Johnaudi

  2. #2
    Street Boss John's Avatar
    Join Date
    Jun 2013
    Location
    Lebanon
    Posts
    825
    A way to delete the variable is either by deleting the whole line in the Edit flags place, or by having a script made making this.something = "";

    As you can see, there is a Database already made called Control-NPC, this database has access to more functions, for example, you can create the function there called onRC(param1, param2 ...) and everytime it's called when someone says on RC any sentence that starts with /npc param1 param2 etc

    This is how staff announce, by using /npc announce "Text Here"
    'announce' is the first parameter, which corresponds to param1, and "Text Here" is the second parameter, which corresponds to param2.

    So the script should be:
    PHP Code:
    function onRC(param1param2) {
      if (
    param1 == "announce") {
        for(
    pl allplayers) {
          
    pl.chat param2// All players' chat will become param2's assigned variable
        
    }
      } else { 
    // if they didn't use announce
        
    echo("Whatever you said does not exist!");
      }

    Of course it's preferable to use switch() case() because there will be a lot of commands, but let's stick with that for now.


    Congratulations, you have mastered the noob Gs2 scripting tutorial! Now you have enough knowledge to run a small server alone!
    I'll be creating new tutorials going more into details of Gs2, making you a pro!
    Last edited by John; 02-14-2014 at 11:26 AM.
    -Johnaudi

  3. #3
    Street Boss John's Avatar
    Join Date
    Jun 2013
    Location
    Lebanon
    Posts
    825
    Thread updated.
    -Johnaudi

  4. #4
    Quote Originally Posted by John View Post
    Thread updated.
    When are you goin to make the pro version john? Oh yeah and thanks for taking time out to make theese =)
    Noof was here.

  5. #5
    Street Boss John's Avatar
    Join Date
    Jun 2013
    Location
    Lebanon
    Posts
    825
    Quote Originally Posted by Noofboy12 View Post
    When are you goin to make the pro version john? Oh yeah and thanks for taking time out to make theese =)
    I first want to see if people are learning and understand my guides, before continuing
    -Johnaudi

  6. #6
    Newcomer Neppy's Avatar
    Join Date
    Feb 2014
    Location
    Australia
    Posts
    24
    Thank You for the post john, i will try to understand it

  7. #7
    Veteran Striker's Avatar
    Join Date
    Jul 2013
    Location
    Britian
    Posts
    283
    John u teached me this correct?
    Striker*
    -Have any question, concerns or problems?
    Message me on forums, click on the link if you need help: http://era-go.com/forum/member.php?410-Striker
    Need help on iEra P.M my nick name is Striker*
    -Need further help? My email is:[email protected]
    ENjOY PLAYING IERA!!!!!
    -Gani Artist

  8. #8
    Big Cheese Captain
    Join Date
    Jun 2013
    Posts
    1,029
    function onCreated () {
    if (this.scripting == hard && iMask == rage.quits)
    echo ("I GIVE UP ;-;");
    }
    iEra Developer / SFX Admin

    Need help? Contact me:
    Email: [email protected]

  9. #9
    aaaaaaaaaaaaaaaaaaaaaaaaa Grief Hero's Avatar
    Join Date
    Jun 2013
    Location
    n/a
    Posts
    1,327
    Quote Originally Posted by iMask View Post
    function onCreated () {
    if (this.scripting == hard && iMask == rage.quits)
    echo ("I GIVE UP ;-;");
    }
    Would not work as you need a curly bracket after the if statement. You'd also need to declare the variables needed like this.scripting, hard, iMask and rage.quits.


    I saw. I conquered. I came.


  10. #10
    Big Cheese Captain
    Join Date
    Jun 2013
    Posts
    1,029
    Quote Originally Posted by Grief Hero View Post
    Would not work as you need a curly bracket after the if statement. You'd also need to declare the variables needed like this.scripting, hard, iMask and rage.quits.
    function onCreated () {
    echo ("This is why I will never be a coder");
    }

    function onCreated () {
    echo ("How would I decare my variables");
    }
    iEra Developer / SFX Admin

    Need help? Contact me:
    Email: [email protected]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •