Thread: Adding Autospawn to your server

Page 1 of 3 123 LastLast
Results 1 to 10 of 21
  1. #1 Adding Autospawn to your server 
    ⚓Manic-Owner⚓


    Join Date
    Nov 2007
    Posts
    2,711
    Thanks given
    47
    Thanks received
    9
    Rep Power
    650
    Description: Adding autospawn npc's

    Difficulty: 0/10

    Assumed Knowledge: none

    Tested Server: cellkyborg's 474 server
    Files/Classes Modified: I don't feel like listing them

    Procedure

    Step 1: Replace your whole npchandler with this.
    Code:
    package net.cellkyborg.server;
    
    import net.cellkyborg.RSInstances.RSNPC;
    import java.io.*;
    
    public class NPCHandler {
           
            public static int maxNPC = 10000;
            public static int maxListedNPCs = 10000;
    	public RSNPC[] npcs = new RSNPC[maxNPC];
    
    	public NPCHandler() {
    		for (int i = 0; i < maxNPC; i++)
    			npcs[i] = null;
                      loadAutoSpawn("/autospawn.cfg");
    	}
    
    	private int getFreeSlot() {
    		for (int i = 1; i < maxNPC; i++)
    			if (npcs[i] == null)
    				return i;
    		return -1;
    	}
    
    	public boolean addNPC(RSNPC npc) {
    		int slot = getFreeSlot();
    		if (slot < 1)
    			return false;
    		npc.slot = slot;
    		npcs[slot] = npc;
    		return true;
    	}
            public int GetNpcListHP(int NpcID) {
    	return 0;	
    	}
           public boolean loadAutoSpawn(String FileName) {
    		String line = "";
    		String token = "";
    		String token2 = "";
    		String token2_2 = "";
    		String[] token3 = new String[10];
    		boolean EndOfFile = false;
    		BufferedReader characterfile = null;
    		try {
    			characterfile = new BufferedReader(new FileReader("./"+FileName));
    		} catch(FileNotFoundException fileex) {
    			misc.println(FileName+": file not found.");
    			return false;
    		}
    		try {
    			line = characterfile.readLine();
    		} catch(IOException ioexception) {
    			misc.println(FileName+": error loading file.");
    			return false;
    		}
    		while(EndOfFile == false && line != null) {
    			line = line.trim();
    			int spot = line.indexOf("=");
    			if (spot > -1) {
    				token = line.substring(0, spot);
    				token = token.trim();
    				token2 = line.substring(spot + 1);
    				token2 = token2.trim();
    				token2_2 = token2.replaceAll("\t\t", "\t");
    				token2_2 = token2_2.replaceAll("\t\t", "\t");
    				token2_2 = token2_2.replaceAll("\t\t", "\t");
    				token2_2 = token2_2.replaceAll("\t\t", "\t");
    				token2_2 = token2_2.replaceAll("\t\t", "\t");
    				token3 = token2_2.split("\t");
    				if (token.equals("spawn")) {
    					newNPC(Integer.parseInt(token3[0]), Integer.parseInt(token3[1]), Integer.parseInt(token3[2]), Integer.parseInt(token3[3]), Integer.parseInt(token3[4]), Integer.parseInt(token3[5]), Integer.parseInt(token3[6]), Integer.parseInt(token3[7]), Integer.parseInt(token3[8]), GetNpcListHP(Integer.parseInt(token3[0])));
    				}
    			} else {
    				if (line.equals("[ENDOFSPAWNLIST]")) {
    					try { characterfile.close(); } catch(IOException ioexception) { }
    					return true;
    				}
    			}
    			try {
    				line = characterfile.readLine();
    			} catch(IOException ioexception1) { EndOfFile = true; }
    		}
    		try { characterfile.close(); } catch(IOException ioexception) { }
    		return false;
    	} 
            boolean invul;
            public boolean newNPC(int npcID, int x, int y, int heightLevel, int rangex1, int rangey1, int rangex2, int rangey2, int WalkingType, int HP) {
    		int slot = getFreeSlot();
    		if (slot < 1)
    			return false;
    
    		RSNPC npc = new RSNPC();
    		npc.npcID = npcID;
    		npc.location[0] = x;
    		npc.location[1] = y;
    		npc.location[2] = heightLevel;
    		npc.invulnerable = invul;
    
    		npc.slot = slot;
    
    		npc.mapRegion[0] = x >> 3;
    		npc.mapRegion[1] = y >> 3;
    		npc.currentLocation[0] = x - (npc.mapRegion[0] - 6) * 8;
    		npc.currentLocation[1] = y - (npc.mapRegion[1] - 6) * 8;
    
    		npcs[slot] = npc;
    		return true;
    	}
    	public boolean addNewNPC(int npcID, int x, int y, int h, boolean invul) {
    		int slot = getFreeSlot();
    		if (slot < 1)
    			return false;
    
    		RSNPC npc = new RSNPC();
    		npc.npcID = npcID;
    		npc.location[0] = x;
    		npc.location[1] = y;
    		npc.location[2] = h;
    		npc.invulnerable = invul;
    
    		npc.slot = slot;
    
    		npc.mapRegion[0] = x >> 3;
    		npc.mapRegion[1] = y >> 3;
    		npc.currentLocation[0] = x - (npc.mapRegion[0] - 6) * 8;
    		npc.currentLocation[1] = y - (npc.mapRegion[1] - 6) * 8;
    
    		npcs[slot] = npc;
    		return true;
    	}
    
    	public void process() {
    		for (int i = 1; i < maxNPC; i++) {
    			if (npcs[i] != null) {
    				npcs[i].process();
    				if (npcs[i].destroy) {
    					npcs[i] = null;
    				}
    			}
    		}
    	}
    
    	public void shutdown() {
    
    	}
    }
    Step 2: Make a new file called NPCList.java then paste this into it
    Code:
    public class NPCList {
    	public int npcId;
    	public String npcName;
    	public int npcCombat;
    	public int npcHealth;
    	
    	public NPCList(int _npcId) {
    		npcId = _npcId;
    	}
    }
    Step 3: Go to your main server folder and create a new file called autospawn.cfg.

    Step 4. Paste this into it
    Code:
    //------NpcID---CoordX--CoordY--Height--RangeX1-RangeY1-RangeX2-RangeY2-WalkType-Descrption
    [ENDOFSPAWNLIST]
    
    You know the drill on adding npc's ;)

    Credits: Me

    Comment you dirty leechers!
     

  2. #2  
    Banned
    Join Date
    Sep 2006
    Posts
    375
    Thanks given
    0
    Thanks received
    3
    Rep Power
    0
    Nice but doesn't this look like 317? The loadautospawn bit...
     

  3. #3  
    ⚓Manic-Owner⚓


    Join Date
    Nov 2007
    Posts
    2,711
    Thanks given
    47
    Thanks received
    9
    Rep Power
    650
    Yes it's the method from 317 servers. But it works. That's the main thing.
     

  4. #4  
    Banned
    Join Date
    Sep 2006
    Posts
    375
    Thanks given
    0
    Thanks received
    3
    Rep Power
    0
    Yep, works great. Thanks hehe
     

  5. #5  
    owner mosta
    Guest
    hahah nice find rep
     

  6. #6  
    ⚓Manic-Owner⚓


    Join Date
    Nov 2007
    Posts
    2,711
    Thanks given
    47
    Thanks received
    9
    Rep Power
    650
    Oh hmm yes I will that was an uneeded int.
     

  7. #7  
    Registered Member nicf17's Avatar
    Join Date
    Jun 2008
    Age
    28
    Posts
    183
    Thanks given
    1
    Thanks received
    1
    Rep Power
    26
    Hmm, Very Nice For Finding This REP++
     

  8. #8  
    Registered Member

    Join Date
    Feb 2007
    Age
    28
    Posts
    6,414
    Thanks given
    354
    Thanks received
    323
    Rep Power
    5000
    i knew this already

    but good job.
     

  9. #9  
    kinwizzard1
    Guest
    gj on this rep++
     

  10. #10  
    HcoFlame
    Guest
    Wow...how about instead of ripping something out of a 317, do it on your own? It takes less than 5 minutes to do it in SQL. And you dont have all those **** 'cfg' files everywhere.
     

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

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