Thread: npc drops [emulous]

Results 1 to 10 of 10
  1. #1 npc drops [emulous] 
    Registered Member
    Join Date
    Sep 2006
    Posts
    178
    Thanks given
    2
    Thanks received
    7
    Rep Power
    13
    i just started coding using emulous as my source but i cant work out how to make npcs drop items if some1 could give me a link to a tut or mayb give me a hint on what i should be doing.


    thanks hellvgod
    Reply With Quote  
     

  2. #2  
    Registered Member
    Chachi's Avatar
    Join Date
    Sep 2008
    Posts
    1,536
    Thanks given
    49
    Thanks received
    103
    Rep Power
    602
    Config.java
    [/CENTER]
    Reply With Quote  
     

  3. #3  
    Banned

    Join Date
    Jan 2007
    Posts
    260
    Thanks given
    3
    Thanks received
    5
    Rep Power
    0
    Config.java

    There is an example in there.
    Reply With Quote  
     

  4. #4  
    Registered Member
    Join Date
    Sep 2006
    Posts
    178
    Thanks given
    2
    Thanks received
    7
    Rep Power
    13
    thanks for the help guys

    ---------- Post added at 10:02 PM ---------- Previous post was at 09:58 PM ----------

    im not sure if i undertsand do i add all drops in the config.java? or can i make a drop list like most other servers?
    Reply With Quote  
     

  5. #5  
    Registered Member
    Join Date
    Sep 2006
    Posts
    178
    Thanks given
    2
    Thanks received
    7
    Rep Power
    13
    still cant work this out if there any way you can alter it so you have its on cfg or is that alot of work for nothing?
    Reply With Quote  
     

  6. #6  
    Donator
    Nightleaf's Avatar
    Join Date
    Apr 2008
    Posts
    440
    Thanks given
    7
    Thanks received
    18
    Rep Power
    75
    drops are so simple

    Example:

    {NPCID, ITEMID, AMOUNT, CHANCE}

    Chance = 0 if you want it to drop everytime, the higher the chance the more rare it is.

    so for a man that would drop bones:

    {1, 526, 1, 0}
    Reply With Quote  
     

  7. #7  
    Registered Member
    Join Date
    Sep 2006
    Posts
    178
    Thanks given
    2
    Thanks received
    7
    Rep Power
    13
    ye i understand that but it looks messy i was just wondering iff u can make a cfg file for it
    Reply With Quote  
     

  8. #8  
    Registered Member
    Naughty Panda's Avatar
    Join Date
    Dec 2007
    Posts
    631
    Thanks given
    12
    Thanks received
    46
    Rep Power
    347
    Took me about half an hour .

    Replace your npc drops array in Config.java with this:


    Code:
    	/**
    	* NPC DROPS
    	**/
    	//{npc Type, item id , amount, chance}
    	public static int[][] NPC_DROPS = new int[4000][1000];
    Add this method in Config.java:
    Code:
    	public static void loadNpcDrops(String fileName) {
    		String line = "";
    		String token = "";
    		String token2 = "";
    		String token2_2 = "";
    		String[] token3 = new String[10];
    		boolean EndOfFile = false;
    		int ReadMode = 0;
    		BufferedReader dropFile = null;
    		try {
    			dropFile = new BufferedReader(new FileReader("./bin/cfg/"+fileName));
    		} catch(FileNotFoundException fileex) {
    			Misc.println(fileName+": file not found.");
    			return;
    		}
    		try {
    			line = dropFile.readLine();
    		} catch(IOException ioexception) {
    			Misc.println(fileName+": 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("drop")) {
    					NPC_DROPS[Integer.parseInt(token3[0])][0] = Integer.parseInt(token3[0]);
    					for(int i = 0; i < (int)((token3.length) / 3); i++) {
    						if(token3[1 + (i * 3)] != null) {
    							NPC_DROPS[Integer.parseInt(token3[0])][1+(i*3)] = Integer.parseInt(token3[1+(i*3)]);
    							NPC_DROPS[Integer.parseInt(token3[0])][2+(i*3)] = Integer.parseInt(token3[2+(i*3)]);
    							NPC_DROPS[Integer.parseInt(token3[0])][3+(i*3)] = Integer.parseInt(token3[3+(i*3)]);
    						}
    					}
    				}
    			} else {
    				if (line.equals("[ENDOFDROPLIST]")) {
    					try { dropFile.close(); } catch(IOException ioexception) { }
    					return;
    				}
    			}
    			try {
    				line = dropFile.readLine();
    			} catch(IOException ioexception1) { EndOfFile = true; }
    		}
    		try { dropFile.close(); } catch(IOException ioexception) { }
    		return;
    	}
    Open Server.java and find:
    Code:
    clientHandler = new Server();
    and under it add:
    Code:
    Config.loadNpcDrops("drops.cfg");

    Open NpcHandler.java and find your dropItems method and replace it with this:

    Code:
    	public void dropItems(int i) {
    		int count = 0;
    		Client c = (Client)Server.playerHandler.players[npcs[i].killedBy];
    		if(c != null) {
    			int npc = npcs[i].npcType;
    			if(Config.NPC_DROPS[npc][0] <= 0) {
    				return;
    			}
    			for(int x = 0; x < (Config.NPC_DROPS[npc].length); x++) {
    				if(Config.NPC_DROPS[npc][1+(x*3)] <= 0) {
    					return;
    				}
    				if(Misc.random(Config.NPC_DROPS[npc][3+(x*3)]) == 0) {
    					c.getItemHandler().addItem(Config.NPC_DROPS[npc][1+(x*3)], npcs[i].absX, npcs[i].absY, Config.NPC_DROPS[npc][2+(x*3)], c.playerId, false);
    					if(Config.NPC_DROPS[npc][3] > 0) {
    						return;
    					}
    				}
    			}
    		}
    	}
    NOTE: YOU MAY HAVE TO CHANGE THE addItem TO createGroundItem DEPENDING ON WHICH VERSION OF EMULOUS YOU HAVE (THIS IS FOR 1.6.2).

    Now create your drop file and replace it with your other .cfg files in ./bin/cfg:
    Code:
    //drop = npcID	itemId	amount	chance	itemId	amount	chance
    drop = 1	526	1	0	1323	1	0	995	100	0
    [ENDOFDROPLIST]
    That for example would make a man always drop iron scimmy, bones and 100 coins.

    NOTE: You must put drops with a 100% drop rate BEFORE your other drops, otherwise they will not drop. For example if you want to drop a rune scimmy with a 50% chance, but bones with a 100% chance you would put:

    Code:
    drop = npcId	526	1	0	1333	1	1
    Post if you have any problems with it.
    Reply With Quote  
     

  9. #9  
    Registered Member
    Join Date
    Sep 2006
    Posts
    178
    Thanks given
    2
    Thanks received
    7
    Rep Power
    13
    thanks mate this has rly helped
    Reply With Quote  
     

  10. #10  
    Registered Member
    Join Date
    Sep 2006
    Posts
    178
    Thanks given
    2
    Thanks received
    7
    Rep Power
    13
    when i add a npc to my spawn list and then give it a drop it wont drop anything?
    evan if i add the drop using the emulous way it just wont drop it

    ---------- Post added at 03:02 PM ---------- Previous post was at 02:31 PM ----------

    is there any1 who could help me with this?
    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

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