Thread: Some Basics in RSPS Coding

Results 1 to 6 of 6
  1. #1 Some Basics in RSPS Coding 
    K0ownage
    Guest
    This was taken off a addition of my "How to create a private server" tutorial which has been removed, because there are many other helpful tutorials similar to mine.

    This section is just some of the basics, for new rsps coders, this will help them get a feel of the coding. If things like this were out there when I started it would have been alot easier *sigh* Well then here you go!

    Coding.

    ----------------
    Table of contents:
    1. Description of statements, methods, and classes.
    2. Working with statements.
    3. Working with methods.
    4. Working with integers, and booleans.
    5. Working with classes.
    6. Common methods in private servers.
    7. Making NPCs
    ----------------

    Chapter 1: How java works
    In this chapter, you will learn the key vocabulary in Java, and how the most common things in java work, and how they are used. This will not dig very deep, it will just set you up so you can understand further chapters more easily.

    In java, there are many confusing words that, well, confuse you. You may hear the terms, "class", and "statement", and "method". Well, all of these words are some of the most commonly used terms in java, so you 'd better get used to them.

    The class
    A class is a file that you create that can be run and compiled by the compiler. Usually a .java file is called a class, but one java file can contain many classes; but when you do that, things get complicated, so I will not go over this. A good thing that you may recognize is the client class (client.java), they are compiled from .java to .class files, because you cannot read the version of java that your computer runs. The compiler is a wonderful thing. It checks for errors in your java code, and makes java easier to program for you.

    The method
    A method is a section of coding within a class that can be called upon with statements and other methods. Sounds confusing? By the end of this tutorial, you will understand. A method is basically a chunk of coding, that you can just put anywhere, and use repetitively by, "calling," it. I will dig deeper into what calling is later in this tutorial.

    The Statement
    Ah, the good old statement. A statement is usually a small chunk of code that can be placed within methods and classes. Statements usually call upon other methods to make their job easier. You can use multiple statements that call the same method. This is why java is so great. To do the job of many statements, you only need one method. A statement is usually used as a conditional, or: if this, then do this.

    ---------------------------------------------------
    Chapter 2: Working with statements
    In this chapter, you will learn how to make your own statements, and you will learn how they work.

    About the statement
    The statement is a line, or several lines of coding, that are most of the time used as conditionals (if, then). A statement can be used to call other methods, such as commands.

    The "if" statement.
    An if statement is a statement that is strictly conditional. Here is the basic layout for it:
    Code:
    if(this) (then)
    The this is the conditional, and the then is what to do. Usually, in private server coding, the then part is used with braces, heres what it looks like:
    Code:
    if(this)
    {
    do stuff in here
    }
    Those braces allow several methods to be used at once. Other statements that only use one method look like this:
    Code:
    if(this) then;
    Here is the command, a common use in private servers.
    Code:
    if(command.equalsIgnoreCase("commandhere"))
    {
    do stuff in here
    }
    Some "do stuff in here" things can be teleports, messages, adding of items, etc.
    The way of teleporting in private servers is as follows:
    Code:
    teleportToX = xcoord;
    teleportToY = ycoord;
    Where xcoord and ycoord are the coordinates that teleport you. You must put a ; at the end of it to show the end of the part of the statement.

    The while statement
    The while statement is a statement that is used as a loop, there are other ones, but while is the best in my opinion.
    The while statement is used exactly as the if statement, but it is reused every 500 milliseconds.
    Here is the way it ususally goes:
    Code:
    while(this)
    {
    do this
    }
    Ways to use conditions within statements
    Ways to make conditions within statements like this:
    == means is equal to (within the computers memory)
    >= means is greater than or equal to.
    <= means is less than or equal to.
    .equals means that the actual things being used are identical
    < means less than.
    > means greater than.
    It will appear like this:
    Code:
    if(this > this)
    {
    do this
    }
    ---------------------------------------------------
    Chapter 3: Working with methods
    In this chapter, you will learn how to create your own method, and call it within a statement.

    The method
    The method is a chunk of code that can be used over and over again within statements. The most common method is the void, which is a method with no return type. To make sure you can use the void within statements and other methods, you must first use the word, "public". A common method, the void, goes as follows:
    Code:
    public void name()
    {
    all of your coding goes in here
    }
    A void can contain statements inside of them. The () part is the parameters, which goes on into much more experienced coding, and I will not go into that in this tutorial. Maybe in future tutorials. Now inside your void, you can put in place all of the coding you want, and if you want to use that coding within a statement, or another void, you would use it as follows:
    Code:
    name();
    Thats all it takes to call your entire void. A void may be any size in length, its only limit is your skill and imagination. If you were to call a void inside a statement, it would appear as follows:
    Code:
    if(this)
    {
    name();
    }
    This represents the conditional, and name represents the name of the void called.


    ---------------------------------------------------
    Chapter 4: Using integers, and booleans
    In this chapter, you will learn how to use integers, and booleans. You will learn their purpouse, and how they can help you.

    Overview
    Integers and booleans are the most commonly used ways of storing data types in private servers. The integer will store a whole number within your computers memory, and the boolean will store a true or false statement within your computers memory.

    The integer
    The integer is used to store a number in your computers memory, that can be used to define, or check if things are a certain number or not. To use an integer, you must first declare it with a name, and its value.
    Declaring an integer goes as follows:
    Code:
    public int name = value;
    You must declare your integer not within a method or statement, but anywhere else in a class to make it available to all methods and statements.
    We use public to make it available by other methods, and int to declare its type. Name is the name of it, and value is the initial value before it is changed.
    The most common thing you may see is playerRights, in which case 0 is a normal player, 1 is a moderator, and 2 is an admin.
    Using an integer in a statement goes as follows:
    Code:
    if(name == value)
    {
    name2 = value;
    }
    Where name is your integer, and the value is checked by the if statement. name2 is the name of a different integer, in which you can change. The if statement will only work if the "name" integer is the correct value specified. Here is it more in detail, where name is used as human, and alien is used as name2.
    Code:
    if(human == 1)
    {
    alien = 0;
    }
    A boolean can better represent this. Which is why we are going on to booleans now.

    The Boolean
    A boolean is used almost the same as an integer, but instead of numbers you would use true, or false.
    Like an integer, you must declare your boolean:
    Code:
    public boolean name = value;
    Where this time, value is set to either true, or false by default.
    Name is the name of your boolean, (like human, or alien).
    A boolean can be used in a statement as follows:
    Code:
    if(human)
    {
    alien = false;
    }
    You don't have to put an == true for a boolean that is true, but you do have to put an == false for a boolean that is false.
    Like this:
    Code:
    if(human == false)
    {
    alien = true;
    }
    The first statement will make it so if they are a human, then they are not an alien. The second one will mean if they are not a human, then they are an alien. You must first tell the server what a human and alien is within a method, otherwise it will have no effect.

    ---------------------------------------------------
    Chapter 5: Working with classes
    In this chapter you will learn how classes work, and how they relate, and how classes make java a unique programming language.

    Making Classes
    Classes are usually single java files, but you can declare many classes within one java file; although I recommend you don't. To make a class, you must first create a java file, named name.java. Name is the name of your new class. A class must have a main method in it.
    Now when you edit it, you must declare the class like this:
    Code:
    public class name {
    public void main() {
    }
    }
    Public makes it usable by other classes, and name is the name of your class.
    Inside the braces is where you would put your methods, statements, integers, booleans, and anything else that is considered java coding.
    Now, if you wanted to make a class so you dont have to code in your client class anymore, but you still want all the methods inside your client class, you would make what we call a subclass, or, a child class.
    Basically, all you would need to adopt all of the methods, statements, integers, and booleans is to put extends, and then the parent class. As follows:
    Code:
    public class child extends parent
    {
    }
    Child is the name of your class, so put that there. And parent is the name of the class in which you wish to use all of its methods.
    In the child class, you can create a new statement, or method, identical to the one of the parent class, and override it by placing different code.
    To get a new class to work within a private server, you have to make it visible by the server class. I will not go into much detail about objects, but you need to know this to get it to work.
    To make the server class recognize it, and make it work while it runs, you must paste these two things with the same group in which the other classes are called:
    Code:
    name = new name();
    and
    Code:
    public static name reference = null;
    Reference is used in more experienced coding, and you should just keep reference the same as your class name.
    name in both of these examples above is the name of your class.

    ---------------------------------------------------
    Chapter 6: Common methods in private servers.
    In this chapter you will learn the most common methods in private servers, and what they do.

    sendMessage
    This method will send a message to people in the text box, it looks like this:
    Code:
    sendMessage("message");
    it is used like this:
    Code:
    sendMessage("Hello");
    The word Hello will be sent to the player in their chat box.
    addItem
    This method is used to add an item, or a few, to a players inventory. It will only add a few of items if they are stackable, or noted.
    It looks like this
    Code:
    addItem(ID, number);
    ID represents the item ID, which can be found in your item.cfg, and number is the amount of it.
    Here is how it can be used:
    Code:
    addItem(995, 100000);
    If I am correct, 995 is the money item, and that will give them 100000 coins.

    The Command
    This is used in an if statement.
    It looks like this:
    Code:
    if(command.operator("command"))
    {
    do this
    }
    operator is usually equalsIgnoreCase, but it can be startsWith, and just equals.
    Here is what a command can look like:
    Code:
    if(command.equalsIgnoreCase("money") {
    addItem(995, 1000000);
    }
    Yet again, if I am correct, and 995 is the money item (I'm not sure), then that will give them 1M in money.

    ---------------------------------------------------
    Chapter 7: Making NPCs
    In this chapter, you will learn how to spawn NPCs.

    Spawning
    So you want to make NPCs eh? Well, you're at the right chapter. NPCs would be tedious, and incredibly hard to make if the makers of private servers did not use CFG files to spawn NPCs. Spawning NPCs requires a restart, but not a compile, because the server loads the NPCs every time it runs. Open your autospawn.cfg file, and look at it. You should see something around the likes of this:
    Code:
    spawn = 580    2950    3387    0    2952    3390    2948    3385    1    Falador Mace Shop
    There are little squares in that code, because this website cannot show tabs. Anyways, spawning NPCs goes like this:
    Code:
    spawn = ID(tab)xcoord(tab)ycoord(tab)height(tab)x1(tab)y1(tab)x2(tab)y2(tab)walktype(tab)description
    ID is the NPC id, x coordinate and y coordinate is where they originally spawn, the x1, x2, y1, y2 are coordinates in which they walk. I haven't experimented around with walking ranges, so you're going to have to figure it out yourself. The walktype should always remain 1, and the description is to help you know what it is, and it does not effect the coding of the NPC.


    ---------------------------------------------------
    A class with a method and statement
    To show you how classes, methods, and statements relate, I will show you a class that has a method that has a statement.
    Code:
    public class givememoney extends client {
    public void main() {
    if(command.equalsIgnoreCase("money"))
    {
    addItem(995, 1000000);
    }
    }
    }
    Private Server Information.[*]They all crash, this means, they will crash while they are running, and they will require a restart, this cannot be helped.[*]They don't have the most current runescape graphics, they won't ever be so good.[*]None of them are complete, some magic doesnt work, and most sources are different, it takes years to get it perfect.[*]All sources are based off a few beginning servers, and have been upgraded upon and released.


    Client.java
    Client.java is where you can basically control your source.
    Most of the stuff goes there.
    So for example if your source's name is z0pszscape then click CTRL+F in your client.java and search for z0pszscape and change the name to whatever you like and keep searching till you can't find a z0pszscape.
    So if you log on, the server's name will be the name you chose.
    Ill teach you some basics of adding a command.
    Code:
    if (command.startsWith("food1"))
                {
            addItem(391,1);
                    addItem(391,1);
                    addItem(391,1);
                    addItem(391,1);
                    addItem(391,1);
                    addItem(391,1);
                    addItem(391,1);
                    addItem(391,1);
                    addItem(391,1);
                    addItem(391,1);
                    addItem(391,1);
                    addItem(391,1);
                    addItem(391,1);
                    addItem(391,1);
                    addItem(391,1);
                    addItem(391,1);
                    addItem(391,1);
                    addItem(391,1);
                    addItem(391,1);
                    addItem(391,1);
                    addItem(391,1);
                    addItem(391,1);
                    addItem(391,1);
                    addItem(391,1);
                    addItem(391,1);
                    addItem(391,1);
                    addItem(391,1);
                    addItem(391,1);
                }
    Well this is easy just change the food1 which is the command name and change the 391 to what you want the item to be.And the 1 after the 391 for the amount of the item you want.
    To find item ID's download the moparscape client and click "help" then you will see item ID's, click that and then you will see a big list of item ID's.

    So client.java is mostly made of public and private voids and int's ect...
    Autospawn.cfg
    Code:
    //------NpcID---CoordX--CoordY--Height--RangeX1-RangeY1-RangeX2-RangeY2-WalkType-Descrption
    spawn = 1    2    3    4    5    6    7    8    9    TestNpcSpawn
    Autospawn.cfg is used like.
    1. Here u type what ID your NPC you want to add in your server.
    2. Type in what the cordination X u want.
    3. Type in what the cordination Y u want.
    4. Here u type the hight of your NPC, most normal it is 0 u type here..
    5. Here u can type what the MAX ranged X1 the NPC can walk
    6. Here u can type what the MAX ranged Y1 the NPC can walk
    7. Here u can type what the MAX ranged X2 the NPC can walk
    8. Here u can type what the MAX ranged Y2 the NPC can walk
    9. Type the name of the NPC u want..

    How a object can teleport you with restrictions to use the object.
    First Stepearch for in client.java
    Code:
    /*OBJECT CLICK ONE*/
    You should see something like below.
    Code:
    case 2213: //Bank Booth
    break;
    Paste this after the break; in one of the tele cases.
    Code:
    case 1234:  // Teleportation Name
    teleportToX = 1234;
    teleportToY = 1234;
    break;
    Ok now change "case 1234:" (The 1234 to the Object ID you want, to teleport you.)
    Change the other "1234" to the coords you want the object to teleport you to
    And change the "Teleportation Name" to the name of the teleport.

    Second Step:
    Ok this is the restrictions part.
    How about you wanted the person to have 20 attack before they can use the object to teleport you?
    Well then the case should look like this.
    Code:
     case 0000:
        if(playerLevel[1] >= 20) {
        sendMessage("You use the object.");
        teleportToX = 0000;
        teleportToY = 0000;
        }
        } else {
        sendMessage("You need 20 attack to use this object")
        break;
    Now just change the "20" to how much you want the person to have the skill level to use the object.
    And change the "sendMessage" to what you want the message to be.

    How about you wanted it to be admin only? or mod?
    It's the same thing.
    Code:
     case 0000:
        if(playerRights >= 2) {
        sendMessage("You use the admin only object.");
        teleportToX = 0000;
        teleportToY = 0000;
        }
        } else {
        sendMessage("Admin ONLY.")
        break;
    Now change the "2" in the playerRights in the case to the right you want the person to have to use the object.And Once again change the "sendMessage"

    -----------------------------------------------------------------------------------------------------------

    Credits: K0ownage
     

  2. #2  
    Registered Member
    Join Date
    Jun 2008
    Posts
    372
    Thanks given
    1
    Thanks received
    3
    Rep Power
    8
    Wow this is great thanks!
     

  3. #3  
    FullMetal Alchemist
    Guest
    Very nice :O Must've taken you ages Lol
     

  4. #4  
    I'm kind of back :D

    Nick's Avatar
    Join Date
    Nov 2007
    Age
    28
    Posts
    803
    Thanks given
    0
    Thanks received
    5
    Rep Power
    384
    Wow.........There's no way you did this, if you seriously did, This deserves a sticky. No dought.


     

  5. #5  
    Member #35, most veteran member left? :D


    Join Date
    Jul 2006
    Age
    30
    Posts
    2,660
    Thanks given
    53
    Thanks received
    331
    Rep Power
    925
    Before you make a guide like this, you need to make sure you're really good with what you're writing about and that you're telling people the proper things.

    For example, you don't have to put == false in an if statement, you can use an exclamation point like this: !variable.

    A class with a method and statement
    To show you how classes, methods, and statements relate, I will show you a class that has a method that has a statement.
    Code:
    public class givememoney extends client {
    public void main() {
    if(command.equalsIgnoreCase("money"))
    {
    addItem(995, 1000000);
    }
    }
    }
    That's completely wrong lol.

    Private Server Information.[*]They all crash, this means, they will crash while they are running, and they will require a restart, this cannot be helped.[*]They don't have the most current runescape graphics, they won't ever be so good.
    Not all private servers crash - If shittily programmed things are put in the server, it will become unstable. Also, 508 servers have come out, if you haven't noticed.

    Finally, they are not called "voids," they are called "methods."

    It's a nice guide, but you really need to know more about the subject before you write about it.


    `Ex-global moderator x3 (resigned)
     

  6. #6  
    Registered Member

    Join Date
    Jun 2007
    Posts
    2,237
    Thanks given
    267
    Thanks received
    411
    Rep Power
    1283
    I've seen this before.
    It used to be on Moparscape, it was made by Mod Tharok if i remember correctly.
    I only remember the part about the booleans with the aliens and humans.
    I have a printed copy for proof.
    Don't worry, Be happy.
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

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