Thread: [Ruse] Custom NPCLoader

Page 1 of 3 123 LastLast
Results 1 to 10 of 28
  1. #1 [Ruse] Custom NPCLoader 
    Banned

    Join Date
    Aug 2011
    Posts
    843
    Thanks given
    541
    Thanks received
    220
    Rep Power
    0
    Well, thought this could be useful to most of you who don't like adding npc's manually through Json. Like making a shit load of these, might just take up most of your time if you do it that way so therefore why I created this! Yeah im sure this could be done better or improved, I did this quickly but it does work

    Note:
    You will have to make directions work yourself as it manually faces the npc south. Also create your own spawns! To do that, simply add a new line in the text file "spawns" using this format:

    Code:
    //----NpcId-----PosX----PosY----------------
    spawn = 1	3223	3219
    Here's the results;
    Attached image

    Add this class in your npc package and name it NPCLoader

    Code:
    import java.io.BufferedReader;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.io.IOException;
    
    
    /**
     * 
     * @author Pwnhub <Captain Pwn> [http://www.rune-server.org/]
     *
     */
    public class NPCLoader {
         
        private static final String FILE_DIRECTORY = "./data/def/txt/";
        private static int npcLimit = 50000;
        private static NPCList npcList[] = new NPCList[npcLimit];
        private static int areaSpawnAmount = 0;
        
        /**
         * Loads custom spawns via java file.
         */
        public static void loadCustomSpawns() {
            //spawnNPC(1, new Position(3222, 3220));
               //spawnNPC(2, new Position(3222, 3220));
        }
        
        /**
         * Handles the positions.
         * @param x
         * @param y
         * @param z
         * @return 
         */
        public static Position newPos(int x, int y, int z) {
            return new Position(x, y, z);
        }
        
        /**
          * Spawns the npc in the specified location.
         * @param id
         * @param x
         * @param y
         * @param z
         * @param direction
         * @param combatLvl
         * @param name
         */
        public static void spawnNPC(int id, Position pos) {
            NPC npc = new NPC(id, pos);
            World.register(npc);
            npc.setEntityInteraction(npc);
            npc.setDirection(Direction.NORTH);
        }
        
        /**
         * Loads the spawns from the text file.
         * @return
         */
        @SuppressWarnings("resource")
        public static boolean loadSpawns() {
            loadCustomSpawns();
            String line = "";
            String str = "";
            String str2 = "";
            String str3 = "";
            String[] str4 = new String[10];
            boolean ending = false;
            BufferedReader npcFile = null;
            try {
                npcFile = new BufferedReader(new FileReader(FILE_DIRECTORY+"spawns.txt"));
            } catch (FileNotFoundException fileex) {
                System.out.println(npcFile + " couldn't be located.");
                return false;
            }
            try {
                line = npcFile.readLine();
            } catch (IOException ioexception) {
                System.out.println(npcFile + " couldn't be read.");
                return false;
            }
            while (ending == false && line != null) {
                line = line.trim();
                int space = line.indexOf("=");
                if (space > -1) {
                    str = line.substring(0, space);
                    str = str.trim();
                    str2 = line.substring(space + 1);
                    str2 = str2.trim();
                    str3 = str2.replaceAll("\t\t", "\t");
                    str3 = str3.replaceAll("\t\t", "\t");
                    str3 = str3.replaceAll("\t\t", "\t");
                    str3 = str3.replaceAll("\t\t", "\t");
                    str3 = str3.replaceAll("\t\t", "\t");
                    str4 = str3.split("\t");
                    if (str.equals("spawn")) {
                        spawnNPC(Integer.parseInt(str4[0]), new Position(Integer.parseInt(str4[1]), Integer.parseInt(str4[1])));
                    }
                } else {
                    if (line.equals("[ENDOFSPAWNLIST]")) {
                        try {
                            npcFile.close();
                        } catch (IOException io) {
                            io.printStackTrace();
                        }
                        return true;
                    }
                }
                try {
                    line = npcFile.readLine();
                } catch (IOException io) {
                    ending = true;
                }
            }
            try {
                npcFile.close();
            } catch (IOException io) {
                io.printStackTrace();
            }
            return false;
        }
    
    
        /**
         * Loads the npc list from a text file.
         * @return
         */
        @SuppressWarnings("resource")
        public boolean loadNPCList() {
            String line = "";
            String str = "";
            String str2 = "";
            String str3 = "";
            String[] str4 = new String[10];
            boolean ending = false;
            BufferedReader npcFile = null;
            try {
                npcFile = new BufferedReader(new FileReader(FILE_DIRECTORY+"list.txt"));
            } catch (FileNotFoundException fileex) {
                System.out.println(npcFile + " couldn't be located.");
                return false;
            }
            try {
                line = npcFile.readLine();
            } catch (IOException io) {
                System.out.println(npcFile + " couldn't be read.");
                return false;
            }
            while (ending == false && line != null) {
                line = line.trim();
                int spot = line.indexOf("=");
                if (spot > -1) {
                    str = line.substring(0, spot);
                    str = str.trim();
                    str2 = line.substring(spot + 1);
                    str2 = str2.trim();
                    str3 = str3.replaceAll("\t\t", "\t");
                    str3 = str3.replaceAll("\t\t", "\t");
                    str3 = str3.replaceAll("\t\t", "\t");
                    str3 = str3.replaceAll("\t\t", "\t");
                    str3 = str3.replaceAll("\t\t", "\t");
                    str4 = str3.split("\t");
                    if (str.equals("npc")) {
                        createNewList(Integer.parseInt(str4[0]), str4[1],
                                Integer.parseInt(str4[3]), Integer.parseInt(str4[4]));
                    }
                } else {
                    if (line.equals("[ENDOFNPCLIST]")) {
                        try {
                            npcFile.close();
                        } catch (IOException io) {
                            io.printStackTrace();
                        }
                        return true;
                    }
                }
                try {
                    line = npcFile.readLine();
                } catch (IOException io) {
                    ending = true;
                }
            }
            try {
                npcFile.close();
            } catch (IOException io) {
                io.printStackTrace();
            }
            return false;
        }
        
        /**
         * The class of the npc list.
         */
        public class NPCList extends NPC {
            public int npcId = id;
            public String npcName = definition.name;
            public int npcHp = defaultConstitution;
            
            /**
             * The main constructor of the list.
             * @param _npcId
             * @param position
             */
            public NPCList(int _npcId, Position position) {
                super(_npcId, position);
                npcId = _npcId;
            }
        }
    
    
        /**
         * Creates a new npc list.
         * @param npcId
         * @param npcName
         * @param constitution
         */
        public void createNewList(int npcId, String npcName, int combatLvl, int constitution) {
            Position defaultPos = null;
            int slot = -1;
            for (int i = 0; i < npcLimit; i++) {
                if (npcList[i] == null) {
                    slot = i;
                    break;
                }
            }
            if (slot == -1)
                return;
            npcList[slot] = new NPCList(npcId, defaultPos);
            npcList[slot].npcName = npcName;
            npcList[slot].npcHp = constitution;
            npcList[slot].definition.setCombatLevel(combatLvl);
        }
    
    
    }
    Go to your NPC class in the same package and above;

    Code:
    Nex.spawn();
    Add;
    Code:
    NPCLoader.loadSpawns();
    Then download these and put them into the txt folder within the data folder a.k.a (data/txt) of your source. Make sure to read the notice above! The first npc has been spawned for you. Then you're done!


    Before you go, if you dont want to just load the npcs from a file, you can load them from the class. Just uncomment the lines in this void;

    Code:
    /**
         * Loads custom spawns via java file.
         */
        public static void loadCustomSpawns() {
            //spawnNPC(1, new Position(3222, 3220));
               //spawnNPC(2, new Position(3222, 3220));
        }
    That's it, that's all. Enjoy
    Reply With Quote  
     

  2. #2  
    Ask me how I'm doing

    .NF.'s Avatar
    Join Date
    Aug 2015
    Age
    30
    Posts
    2,174
    Thanks given
    293
    Thanks received
    619
    Rep Power
    567
    Nice release
    Attached image
    Reply With Quote  
     

  3. #3  
    Donator


    Join Date
    Feb 2014
    Age
    26
    Posts
    161
    Thanks given
    261
    Thanks received
    62
    Rep Power
    100
    what are the advantages in using this winterlove-esque format over defining the definitions in JSON or SQL?
    Reply With Quote  
     

  4. #4  
    Banned

    Join Date
    Aug 2011
    Posts
    843
    Thanks given
    541
    Thanks received
    220
    Rep Power
    0
    Quote Originally Posted by Raees View Post
    what are the advantages in using this winterlove-esque format over defining the definitions in JSON or SQL?
    because half the worlds npc population is missing and if people want to manually add npcs, they can still do that as the regular Json loader is still enabled. So therefore, the advantage is you dont have to waste your time spawning npcs around the world in Json when you could do it in 5 mins.

    Quote Originally Posted by LifeIsGifted View Post
    Nice release
    Thank you
    Reply With Quote  
     

  5. #5  
    Donator


    Join Date
    Feb 2014
    Age
    26
    Posts
    161
    Thanks given
    261
    Thanks received
    62
    Rep Power
    100
    Quote Originally Posted by Captain Pwn View Post
    because half the worlds npc population is missing and if people want to manually add npcs, they can still do that as the regular Json loader is still enabled. So therefore, the advantage is you dont have to waste your time spawning npcs around the world in Json when you could do it in 5 mins.



    Thank you
    Well if you had all the required NPCs in wL format, you could automatically convert them to JSON given that you have both the readers and writers programmed in the server. load all in wL -> write all to json
    Reply With Quote  
     

  6. #6  
    Banned

    Join Date
    Aug 2011
    Posts
    843
    Thanks given
    541
    Thanks received
    220
    Rep Power
    0
    Quote Originally Posted by Raees View Post
    Well if you had all the required NPCs in wL format, you could automatically convert them to JSON given that you have both the readers and writers programmed in the server. load all in wL -> write all to json
    meh , if people want to do that they can thx tho
    Reply With Quote  
     

  7. #7  
    Donator


    Join Date
    Feb 2014
    Age
    26
    Posts
    161
    Thanks given
    261
    Thanks received
    62
    Rep Power
    100
    Quote Originally Posted by Captain Pwn View Post
    meh , if people want to do that they can thx tho
    people can use your loader to do that. it's a good release because it'll save people time converting it to ruse.
    Reply With Quote  
     

  8. #8  
    Banned

    Join Date
    Aug 2011
    Posts
    843
    Thanks given
    541
    Thanks received
    220
    Rep Power
    0
    Quote Originally Posted by Raees View Post
    people can use your loader to do that. it's a good release because it'll save people time converting it to ruse.
    For sure i might make a program later that edits the npc json file
    Reply With Quote  
     

  9. #9  
    Banned

    Join Date
    Jul 2015
    Posts
    607
    Thanks given
    520
    Thanks received
    660
    Rep Power
    0
    I'd recommend to stick with the original (and proper) system for spawning global npcs..
    Reply With Quote  
     

  10. Thankful user:


  11. #10  
    Banned

    Join Date
    Aug 2011
    Posts
    843
    Thanks given
    541
    Thanks received
    220
    Rep Power
    0
    Quote Originally Posted by Swiffy View Post
    I'd recommend to stick with the original (and proper) system for spawning global npcs..
    hence why it loads both. Its proper, but saving time is also good..
    Reply With Quote  
     

Page 1 of 3 123 LastLast

Thread Information
Users Browsing this Thread

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


User Tag List

Similar Threads

  1. [Ruse] Easy Custom Minimap Icons
    By Beagon in forum Tutorials
    Replies: 0
    Last Post: 10-25-2015, 09:39 PM
  2. Replies: 171
    Last Post: 07-24-2015, 12:21 PM
  3. Custom Player Title's
    By Dune in forum Tutorials
    Replies: 43
    Last Post: 09-03-2007, 11:34 AM
  4. Custom player titles
    By Lothy in forum Tutorials
    Replies: 9
    Last Post: 06-16-2007, 03:33 PM
  5. Tutorial Dirty Hack to Custom sprites
    By silabsoft in forum Tutorials
    Replies: 20
    Last Post: 04-27-2007, 12:07 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •