Thread: [508] NPC Drops

Results 1 to 4 of 4
  1. #1 [508] NPC Drops 
    Registered Member
    Join Date
    Apr 2012
    Posts
    9
    Thanks given
    0
    Thanks received
    0
    Rep Power
    0
    I noticed recently that DangerZone's 508 DOES NOT have a npcdrops.cfg/xml to make drops from. So here is a little tutorial on how to add them.

    Difficulty: 2

    In this tutorial I will use a Chicken as the NPC (id 41) so replace the 41s with your NPC id.

    1. navigate to palidino76.rs2.npcs in your source folder.

    2. open up NPC.java with your editor of choice.

    3. search this:

    Code:
    public void appendNpcDrops() {
    4. Then scroll down to this:

    Code:
    		case 5253:
    			if (Misc.random(10) == 5)
    				Server.engine.items.createGroundItem(10581, 1, absX, absY, heightLevel, p.username);
    		break;
    5. Under the break type this:

    Code:
                    case 41:
    	                Engine.items.createGroundItem(526, 1, absX, absY, heightLevel, p.username);	
    	                Engine.items.createGroundItem(995, Misc.random(25), absX, absY, heightLevel, p.username);
                    break;
    6. Now I'll explain this a little bit more.
    Code:
    case 41:
    - REMEMBER 41 is the id of a Chicken, so change this to your NPC's id.

    Code:
    Engine.items.createGroundItem(526, 1, absX, absY, heightLevel, p.username);
    - Tells the system to create 1 pile of bones (id 526) at the height, and coordinates of the dead chicken.

    Code:
    Engine.items.createGroundItem(995, Misc.random(25), absX, absY, heightLevel, p.username);
    - Same as above except with gold (id 995). IMPORTANT The (25) means its drops UP TO 25 gold in random amounts.

    Code:
    break;
    - I shouldn't even have to explain.

    Just edit this code to your liking and you are done!

    PLEASE DON'T LEAVE JERK COMMENTS I AM ONLY TRYING TO HELP PEOPLE!!!

    CREDITS:

    90% William'

    10% Me
    Reply With Quote  
     

  2. #2  
    Donator

    Join Date
    Oct 2010
    Posts
    685
    Thanks given
    49
    Thanks received
    67
    Rep Power
    63
    Great job I will add you to credits
    Reply With Quote  
     

  3. #3  
    Registered Member

    Join Date
    Jul 2011
    Posts
    698
    Thanks given
    191
    Thanks received
    125
    Rep Power
    184
    This isn't npcdrops.cfg/xml, this is just a very simple way of adding drops, but takes up a lot more space, isn't as efficient and such. Not the best way of doing it, here's how to implement the npcdrops.cfg file, from my older source, (xml is actually better), if you can find a tutorial for that. But here's what you need to do for npcdrops.cfg:


    Go to Engine.java and find "getPlayerCount()" or "rebuildNPCs()", underneath add the following (may need some converting for your source), this works on any codeusa source.

    Spoiler for Engine.java npcdrops:

    Code:
    	public static NPCDrops NpcDrops[] = new NPCDrops[10000];
    	public static double[][] drops = new double[9000][150]; // 45 drops per NPC
    	public static int[] dropCount = new int[9000];
    
    	public static void dropNPCItems(int NPCID, NPC npc, Player killer) {
    		try {
    			int totalDrops = dropCount[NPCID] / 3;
    			if (totalDrops > 0) {
    				// Random roller = new Random();
    				for (int i = 0; i < dropCount[NPCID]; i += 3) {
    					double roll = Math.random() * 100;
    					if (roll <= drops[NPCID][i + 2]) {
    						if ((drops[NPCID] != null) && (npc != null))
    							items.createGroundItem((int) drops[NPCID][i], (int) drops[NPCID][i + 1], npc.absX,
    									npc.absY, npc.heightLevel, killer.username);
    					}
    				}
    			}
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    
    	}
    	public static int GetNPCDropArrayID(int NPCID, int DropType) {
    		for (int i = 0; i < 10000; i++) {
    			if (NpcDrops[i] != null) {
    				if ((NpcDrops[i].npcId == NPCID)
    						&& (NpcDrops[i].DropType == DropType)) {
    					return i;
    				}
    			}
    		}
    		return -1;
    	}
    	public void loadNPCDrops() {
    		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("./data/npcs/npcdrops.cfg"));
    		} catch (FileNotFoundException fileex) {
    			System.out.println("[LOAD NPC DROPS] File not found.");
    			return;
    		}
    		try {
    			line = characterfile.readLine();
    		} catch (IOException ioexception) {
    			System.out.println("[LOAD NPC DROPS] Error loading file.");
    			return;
    		}
    		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("npcdrop")) {
    					if (Integer.parseInt(token3[0]) <= -1)
    						continue;
    					drops[Integer.parseInt(token3[0])][dropCount[Integer.parseInt(token3[0])]] = Integer
    							.parseInt(token3[1]);
    					drops[Integer.parseInt(token3[0])][dropCount[Integer
    					                                             .parseInt(token3[0])] + 1] = Integer
    					                                             .parseInt(token3[2]);
    					drops[Integer.parseInt(token3[0])][dropCount[Integer
    					                                             .parseInt(token3[0])] + 2] = Integer
    					                                             .parseInt(token3[3]);
    					dropCount[Integer.parseInt(token3[0])] += 3;
    				}
    			}
    			try {
    				line = characterfile.readLine();
    			} catch (IOException ioexception1) {
    				EndOfFile = true;
    			}
    		}
    		try {
    			characterfile.close();
    		} catch (IOException ioexception) { }
    	}


    EDIT: in NPC.java, find your appendNpcDrops() method, add at the bottom of the method:

    Engine.dropNPCItems(npcType, this, p); // Drops items from the npcdrops.cfg file

    Next add this file in build->data->npcs
    npcdrops.cfg

    That is your npcdrops.cfg file, add all your drops in there, i've added a line at the top of the file on how to format. DONT USE ANY SPACES, ONLY TABS

    If you run into any problems, let me know, i might have left out some things not sure, just threw this together in a few mins.

    Goodluck.
    Reply With Quote  
     

  4. #4  
    Gunner4Life [508] NPC Drops Market Banned



    Join Date
    Jun 2011
    Posts
    2,357
    Thanks given
    132
    Thanks received
    667
    Rep Power
    648
    Great Job
    Reply With Quote  
     


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. NPC Drops in 508?
    By Jared1 in forum Help
    Replies: 12
    Last Post: 04-28-2012, 10:47 PM
  2. [508] Help on NPC drops
    By Skill S2 Me in forum Help
    Replies: 3
    Last Post: 06-21-2009, 03:38 AM
  3. Npc Drops [508]
    By 0v3rc0m3 in forum Help
    Replies: 2
    Last Post: 02-01-2009, 12:05 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
  •