Thread: How to make Custom NPC spawns in 667/704

Page 1 of 2 12 LastLast
Results 1 to 10 of 12
  1. #1 How to make Custom NPC spawns in 667/704 
    † Skyotic 639 †
    64Bit's Avatar
    Join Date
    Dec 2011
    Age
    31
    Posts
    624
    Thanks given
    93
    Thanks received
    37
    Rep Power
    4
    Hey this was told to me by [Only registered and activated users can see links. ]

    Simply it is just so u can make new npcs spawn somewhere u want them to spawn every time the server loads up,

    ok first go to

    src\com\rs\utils

    in there ur going to add a new file called NPCSpawning.java

    in there add

    Code:
    package com.rs.utils;
    
    import java.io.IOException;
    import java.lang.reflect.InvocationTargetException;
    import java.util.HashMap;
    import java.util.Map;
    import com.rs.game.World;
    import com.rs.game.WorldObject;
    import com.rs.game.WorldTile;
    import com.rs.game.npc.NPC;
    
    public class NPCSpawning {
    
    	/**
    	 * Contains the custom npc spawning
    	 */
    
    	public static void spawnNPCS() {
    		/**
    		 * NPCS
    		 */;
    		World.spawnNPC(554, new WorldTile(3091, 3502, 0), -1, true, true);
    
    		/**
    		 * Object custom add
    		 */
    		World.spawnObject(new WorldObject(17010, 10, 0, 3154, 3484, 0), true);
    	}
    
    	/**
    	 * The NPC classes.
    	 */
    	private static final Map<Integer, Class<?>> CUSTOM_NPCS = new HashMap<Integer, Class<?>>();
    
    	public static void npcSpawn() {
    		int size = 0;
    		boolean ignore = false;
    		try {
    			for (String string : FileUtilities
    					.readFile("data/npcs/npcspawns.txt")) {
    				if (string.startsWith("//") || string.equals("")) {
    					continue;
    				}
    				if (string.contains("/*")) {
    					ignore = true;
    					continue;
    				}
    				if (ignore) {
    					if (string.contains("*/")) {
    						ignore = false;
    					}
    					continue;
    				}
    				String[] spawn = string.split(" ");
    				@SuppressWarnings("unused")
    				int id = Integer.parseInt(spawn[0]), x = Integer
    						.parseInt(spawn[1]), y = Integer.parseInt(spawn[2]), z = Integer
    						.parseInt(spawn[3]), faceDir = Integer
    						.parseInt(spawn[4]);
    				NPC npc = null;
    				Class<?> npcHandler = CUSTOM_NPCS.get(id);
    				if (npcHandler == null) {
    					npc = new NPC(id, new WorldTile(x, y, z), -1, true, false);
    				} else {
    					npc = (NPC) npcHandler.getConstructor(int.class)
    							.newInstance(id);
    				}
    				if (npc != null) {
    					WorldTile spawnLoc = new WorldTile(x, y, z);
    					npc.setLocation(spawnLoc);
    					World.spawnNPC(npc.getId(), spawnLoc, -1, true, false);
    					size++;
    				}
    			}
    		} catch (NumberFormatException e1) {
    			e1.printStackTrace();
    		} catch (IllegalArgumentException e1) {
    			e1.printStackTrace();
    		} catch (SecurityException e1) {
    			e1.printStackTrace();
    		} catch (IOException e1) {
    			e1.printStackTrace();
    		} catch (InstantiationException e1) {
    			e1.printStackTrace();
    		} catch (IllegalAccessException e1) {
    			e1.printStackTrace();
    		} catch (InvocationTargetException e1) {
    			e1.printStackTrace();
    		} catch (NoSuchMethodException e1) {
    			e1.printStackTrace();
    		}
    		System.err.println("Loaded " + size + " custom npc spawns!");
    	}
    
    }
    then your going to add another file called FileUtilities.java
    in it add this

    Code:
    package com.rs.utils;
    
    import java.io.*;
    import java.nio.ByteBuffer;
    import java.util.LinkedList;
    
    
    /**
     * @author 'Mystic Flow
     */
    public class FileUtilities {
    
        public static final int BUFFER = 1024;
    
        public static boolean exists(String name) {
            File file = new File(name);
            return file.exists();
        }
    
        public static ByteBuffer fileBuffer(String name) throws IOException {
        	File file = new File(name);
        	if(!file.exists())
        		return null;
            FileInputStream in = new FileInputStream(name);
            	
                byte[] data = new byte[BUFFER];
            	int read;
            	try {
                ByteBuffer buffer = ByteBuffer.allocate(in.available() + 1);
                while ((read = in.read(data, 0, BUFFER)) != -1) {
                    buffer.put(data, 0, read);
                }
                buffer.flip();
                return buffer;
            } finally {
                if (in != null)
                    in.close();
                in = null;
            }
        }
    
        public static void writeBufferToFile(String name, ByteBuffer buffer) throws IOException {
        	File file = new File(name);
        	if(!file.exists())
        		file.createNewFile();
            FileOutputStream out = new FileOutputStream(name);
            out.write(buffer.array(), 0, buffer.remaining());
            out.flush();
            out.close();
        }
    
        public static LinkedList<String> readFile(String directory) throws IOException {
            LinkedList<String> fileLines = new LinkedList<String>();
            BufferedReader reader = null;
            try {
                reader = new BufferedReader(new FileReader(directory));
                String string;
                while ((string = reader.readLine()) != null) {
                    fileLines.add(string);
                }
            } finally {
                if (reader != null) {
                    reader.close();
                    reader = null;
                }
            }
            return fileLines;
        }
    
    }
    then open Launcher.java and look for

    Code:
    ServerChannelHandler.init();
    under that add

    Code:
    NPCSpawning.spawnNPCS();
    and in launcher add this

    Code:
    import com.rs.utils.NPCSpawning;
    then go back to NPCSpawning and where it says

    Code:
    	public static void spawnNPCS() {
    		/**
    		 * NPCS
    		 */
    under it is

    Code:
    		World.spawnNPC(554, new WorldTile(3091, 3502, 0), -1, true, true);
    now thats ur npc so the 554 is the npc id and (3091, 3502, 0) is coords and true is if it walks or stays still so true walks false stays still!
    IGNORANCE WILL BE IGNORED

    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  2. Thankful users:


  3. #2  
    Registered Member
    Join Date
    Oct 2010
    Posts
    359
    Thanks given
    152
    Thanks received
    17
    Rep Power
    11
    Great Tut for some people (:
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  4. #3  
    You only get one shot.

    `Lubricant's Avatar
    Join Date
    Jun 2008
    Age
    26
    Posts
    1,611
    Thanks given
    96
    Thanks received
    86
    Rep Power
    126
    Give credits.


    [Only registered and activated users can see links. ]
    Neuro-X Supporter
    Helios Supporter
    Matrix RSPS Supporter
    Reply With Quote  
     

  5. #4  
    Registered Member OverHated's Avatar
    Join Date
    Apr 2010
    Posts
    292
    Thanks given
    63
    Thanks received
    14
    Rep Power
    32
    Good job mate

    [Only registered and activated users can see links. ]

    My previous names:
    Perfect
    Dubstep+
    Reply With Quote  
     

  6. Thankful user:


  7. #5  
    † Skyotic 639 †
    64Bit's Avatar
    Join Date
    Dec 2011
    Age
    31
    Posts
    624
    Thanks given
    93
    Thanks received
    37
    Rep Power
    4
    Quote Originally Posted by `Lubricant View Post
    Give credits.
    i did
    IGNORANCE WILL BE IGNORED

    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  8. #6  
    Officially Retired


    Join Date
    Oct 2007
    Age
    27
    Posts
    5,456
    Thanks given
    558
    Thanks received
    122
    Rep Power
    1364
    nice work mate.
    Reply With Quote  
     

  9. #7  
    You only get one shot.

    `Lubricant's Avatar
    Join Date
    Jun 2008
    Age
    26
    Posts
    1,611
    Thanks given
    96
    Thanks received
    86
    Rep Power
    126
    Quote Originally Posted by skyotic View Post
    i did
    Ownaaja didn't make it.
    Tyluur / 'Mystic Flow did.


    [Only registered and activated users can see links. ]
    Neuro-X Supporter
    Helios Supporter
    Matrix RSPS Supporter
    Reply With Quote  
     

  10. Thankful users:


  11. #8  
    † Skyotic 639 †
    64Bit's Avatar
    Join Date
    Dec 2011
    Age
    31
    Posts
    624
    Thanks given
    93
    Thanks received
    37
    Rep Power
    4
    i dont know who made it i just gave credits who showed me, so yer
    IGNORANCE WILL BE IGNORED

    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  12. #9  
    Mug Club


    Join Date
    Jul 2011
    Age
    26
    Posts
    1,873
    Thanks given
    509
    Thanks received
    890
    Discord
    View profile
    Rep Power
    332
    Yeah guys.. This is definitely the way to use Matrix lmao. There is a filereader for NPC spawns for a reason you know. You don't have to hardcode every single freaking NPC in. Just add it to the npcspawns text file and pack it.


    My Open Source Projects
    [Only registered and activated users can see links. ]
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  13. Thankful user:


  14. #10  
    † Skyotic 639 †
    64Bit's Avatar
    Join Date
    Dec 2011
    Age
    31
    Posts
    624
    Thanks given
    93
    Thanks received
    37
    Rep Power
    4
    Quote Originally Posted by TitanPK View Post
    Yeah guys.. This is definitely the way to use Matrix lmao. There is a filereader for NPC spawns for a reason you know. You don't have to hardcode every single freaking NPC in. Just add it to the npcspawns text file and pack it.
    like i said its like my way of doing it,
    IGNORANCE WILL BE IGNORED

    [Only registered and activated users can see links. ]
    Reply With Quote  
     

Page 1 of 2 12 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. 667/704
    By 64Bit in forum Help
    Replies: 3
    Last Post: 06-05-2012, 12:38 AM
  2. Need 667/704
    By vtothef in forum Buying
    Replies: 4
    Last Post: 03-22-2012, 03:10 PM
  3. 667/704
    By 64Bit in forum Help
    Replies: 3
    Last Post: 03-06-2012, 12:14 PM
  4. 667/704
    By OverHated in forum Help
    Replies: 4
    Last Post: 03-05-2012, 04:23 AM
  5. 667/704
    By Born For Tds in forum Help
    Replies: 2
    Last Post: 03-05-2012, 03:50 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
  •