[Tut] [317] Creating a Server and Coding

Results 1 to 7 of 7
  1. #1
    Account Upgraded | Title Enabled! Brandon is offline
    MemberRank
    Aug 2006 Join Date
    Florida - U.S.ALocation
    1,090Posts

    [Tut] [317] Creating a Server and Coding

    NOTE: The forum where all the old posts were was having issues so i couldn't dig up the server tutorial amongst the 1000+ pages. This guide is from the moparscape forums compliments of
    "The Guardian"

    Section 1: Making your server
    Welcome to my guide of making a server, and learning how to code it. I am The Guardian, of the server Enkrona, and this tutorial will teach you many things.

    Now, before I get going into things, let me tell you a few good things and bad things about Runescape private servers:
    *They all crash, this means, they will crash while they are running, and they will require a restart.
    *They don't have the most current runescape graphics, so don't complain.
    *None of them are complete, some magic doesnt work, and most sources are different.
    *All sources are based off a few beginning servers, and have been upgraded upon and re-released

    Chapter 1: Getting your source
    Unless you want to create an entire server from scratch (that will take an experienced coder months), you should get what is called a source. A source is a pre-made server that you can get, and you can edit, and host. Here is a link to some good server downloads:
    http://www.moparscape.org/smf/index.php/topic,122377.0.html
    I suggest you bookmark that page, as you may love some sources, and hate others. Once you get this, you must unzip it with winRAR, which is a common file compression program. Now you have your server folder, but don't mess around with it yet.

    Chapter 2: Getting JDK
    Before we can do anything, you must get the Java Development Kit, or JDK. JDK allows you to run your server, and compile it. To get JDK, go to this page:
    http://java.sun.com/javase/downloads/index.jsp
    And download JDK 6u1.
    Once you're done installing JDK, we now need to set up your servers IP, which is what the players will use to connect to your server.
    Getting a no-ip
    To get an IP, go to www.no-ip.com, and sign up. Once you have signed up, log in. Now on the side, you should see Your No-IP. Under that, is a list of things you can do. On the side, under the Hosts/Redirects section, click Add. It should take you to a page, where you can make a new one. For the Hostname, you create the name you want, and in the scroll box, you pick the rest of the subdomain. Once you have typed your hostname, and selected the other part of it, scroll down, and click Create Host. You now have your No-IP for your server set up.
    Note: If you have a router, you need to port-forward. There are several tutorials on this, and I suggest you do them or nobody can connect to your server.

    Chapter 3: Compiling/Running
    Now go into your server folder, you should see .java files, and .class files. Locate client.java, and open it with Notepad. This is your main folder for programming the things in your server. The other files are more technical, and you shouldn't mess with them until you learn java a bit. Now, in your client.java, use ctrl + f, to find the name of the server source you downloaded, and change the name ONLY within the quote marks, otherwise the compiler will tell you about errors.

    I used PvPscape for that screenshot, so yours may look different.
    Now, save the client.java file, and double-click your compiler. If your compiler says it cannot find the path specified, you need to get Mod Taharoks Ultimate Compiler, which can be found here:
    http://www.moparscape.org/smf/index.php/topic,49747.0.html
    Heres what a no-error compiling looks like:

    Now, if it compiled without errors, you can run your server by doubleclicking Runserver.bat, or Run.bat.
    It will say something like:
    "Starting server on 0.0.0.0.43594"
    Thats normal, and that means your server is running.

    Now, open Moparscape, and type in "localhost" for the IP, and log into your server.
    You now have a working server. You can use tutorials in this section to customize your server.



    Section 2: Learning how to code your server
    Welcome to the second section on making a server, the tutorial of the basics of java, to get you started on making your very own private server. We will go over many different things in this tutorial, and I don't mind if you skip around to the parts you don't know. I hope many people will learn from this.
    ----------------
    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);
    }
    }
    }




    ---------------------------------------------------
    This sums up my tutorial, and I hope everyone learned something. If anyone finds problems or bugs, tell me.

    Post if you liked, or even just read this.


    Credits: The Guardian


  2. #2
    Enthusiast sliferx94 is offline
    MemberRank
    Feb 2007 Join Date
    25Posts

    Re: [Tut] Creating Your Own Server + Coding It

    I dont know if i can post here But Man This is COOOL!! how did u do that im a slow learner but im learning hmm at the npc part how much i make the height and which Scape is the Best is it Pvp Scape ??cuz im downloading Demonscape V 3 ???

  3. #3
    Account Upgraded | Title Enabled! GlobalMuOnline is offline
    MemberRank
    Jan 2007 Join Date
    LatviaRullz!Location
    203Posts

    Re: [Tut] Creating Your Own Server + Coding It

    This is best tut ever

  4. #4
    There's no RL just AFK -fedexer- is offline
    MemberRank
    May 2006 Join Date
    ScotlandLocation
    1,632Posts

    Re: [Tut] Creating Your Own Server + Coding It

    Good work to The Gaurdian , hes at it again :SniperHea

  5. #5
    Valued Member flamin is offline
    MemberRank
    Aug 2006 Join Date
    hell, where you all are gonna goLocation
    149Posts

    Re: [Tut] Creating Your Own Server + Coding It

    i gotta give him props, no one wrote a real, FULL TuT
    nice

  6. #6
    Apprentice bigdragon219 is offline
    MemberRank
    May 2007 Join Date
    7Posts

    Re: [Tut] Creating Your Own Server + Coding It

    uhu i click on the link and i must look the site but then windows search have you a another Scape??

  7. #7
    Account Upgraded | Title Enabled! georgegeorge is offline
    MemberRank
    Oct 2005 Join Date
    Israel, Tel-AviLocation
    1,079Posts

    Re: [Tut] Creating Your Own Server + Coding It

    very good man!



Advertisement