Thread: [Help] With 718 drop system, only drops items with 100% chance.

Results 1 to 5 of 5
  1. #1 [Help] With 718 drop system, only drops items with 100% chance. 
    Registered Member Archeon's Avatar
    Join Date
    Jun 2015
    Posts
    345
    Thanks given
    17
    Thanks received
    5
    Rep Power
    2
    Hello,
    The problem I encounter is that when I kill an npc, I only get the item that has a 100% drop rate chance.

    Here is my
    drop.java
    Code:
    package com.rs.game.npc;
    
    public class Drop {
    
    	public static Drop create(int itemId, double rate, int minAmount,
    			int maxAmount, boolean rare) {
    		return new Drop((short) itemId, rate, minAmount, maxAmount, rare);
    	}
    
    	private int itemId, minAmount, maxAmount;
    	private double rate;
    	private boolean rare;
    
    	public Drop(int itemId, double rate, int minAmount, int maxAmount,
    			boolean rare) {
    		this.itemId = itemId;
    		this.rate = rate;
    		this.minAmount = minAmount;
    		this.maxAmount = maxAmount;
    		this.rare = rare;
    	}
    
    	public int getExtraAmount() {
    		return maxAmount - minAmount;
    	}
    
    	public int getItemId() {
    		return itemId;
    	}
    
    	public int getMaxAmount() {
    		return maxAmount;
    	}
    
    	public int getMinAmount() {
    		return minAmount;
    	}
    
    	public double getRate() {
    		return rate;
    	}
    
    	public boolean isFromRareTable() {
    		return rare;
    	}
    
    	public void setItemId(short itemId) {
    		this.itemId = itemId;
    	}
    
    	public void setMaxAmount(int amount) {
    		this.maxAmount = amount;
    	}
    
    	public void setMinAmount(int amount) {
    		this.minAmount = amount;
    	}
    
    	public void setRate(double rate) {
    		this.rate = rate;
    	}
    }
    npcdrops.java
    Code:
    package com.rs.utils;
    
    import java.io.RandomAccessFile;
    import java.nio.ByteBuffer;
    import java.nio.channels.FileChannel;
    import java.nio.channels.FileChannel.MapMode;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.LinkedHashMap;
    import java.util.Map;
    
    import com.rs.game.npc.Drop;
    
    public class NPCDrops {
    
    	private final static String PACKED_PATH = "data/npcs/packedDrops.d";
    	private static HashMap<Integer, Drop[]> npcDrops;
    
    	public static final void init() {
    		loadPackedNPCDrops();
    	}
    
    	public static Drop[] getDrops(int npcId) {
    		return npcDrops.get(npcId);
    	}
    
    	private Map<Integer, ArrayList<Drop>> dropMapx = null;
    
    	public Map<Integer, ArrayList<Drop>> getDropArray() {
    
    		if (dropMapx == null)
    			dropMapx = new LinkedHashMap<Integer, ArrayList<Drop>>();
    		// dropMapx = new LinkedHashMap<Integer, ArrayList<Drop>>();
    		for (int i : npcDrops.keySet()) {
    			int npcId = i;
    			ArrayList<Drop> temp = new ArrayList<Drop>();
    			for (Drop mainDrop : npcDrops.get(npcId)) {
    				temp.add(mainDrop);
    			}
    			dropMapx.put(i, temp);
    		}
    
    		return dropMapx;
    	}
    
    	public void insertDrop(int npcID, Drop d) {
    		loadPackedNPCDrops();
    		Drop[] oldDrop = npcDrops.get(npcID);
    		if (oldDrop == null) {
    			npcDrops.put(npcID, new Drop[] { d });
    		} else {
    			int length = oldDrop.length;
    			Drop destination[] = new Drop[length + 1];
    			System.arraycopy(oldDrop, 0, destination, 0, length);
    			destination[length] = d;
    			npcDrops.put(npcID, destination);
    		}
    	}
    
    	private static void loadPackedNPCDrops() {
    		try {
    			RandomAccessFile in = new RandomAccessFile(PACKED_PATH, "r");
    			FileChannel channel = in.getChannel();
    			ByteBuffer buffer = channel.map(MapMode.READ_ONLY, 0,
    					channel.size());
    			int dropSize = buffer.getShort() & 0xffff;
    			npcDrops = new HashMap<Integer, Drop[]>(dropSize);
    			for (int i = 0; i < dropSize; i++) {
    				int npcId = buffer.getShort() & 0xffff;
    				Drop[] drops = new Drop[buffer.getShort() & 0xffff];
    				for (int d = 0; d < drops.length; d++) {
    					if (buffer.get() == 0)
    						drops[d] = new Drop(buffer.getShort() & 0xffff,
    								buffer.getDouble(), buffer.getInt(),
    								buffer.getInt(), false);
    					else
    						drops[d] = new Drop(0, 0, 0, 0, true);
    
    				}
    				npcDrops.put(npcId, drops);
    			}
    			channel.close();
    			in.close();
    		} catch (Throwable e) {
    			Logger.handle(e);
    		}
    	}
    
    	public HashMap<Integer, Drop[]> getDropMap() {
    		return npcDrops;
    	}
    }
    in npc.java the public void drop method.
    Code:
    public void drop() {
    		try {
    			Drop[] drops = NPCDrops.getDrops(id);
    			if (drops == null)
    				return;
    			Player killer = getMostDamageReceivedSourcePlayer();
    			if (killer == null)
    				return;
    			if (isCyclops(getDefinitions().name) && Utils.random(500) > 400) {
    				World.addGroundItem(new Item(whatDefender(), 1), new WorldTile(
    						this.getLastWorldTile()), killer, true, 180, true);			
    			
    			}
    			if (isRevenantNPC(getDefinitions().name) && Utils.random(65) == 0) {
    				World.addGroundItem(
    						new Item(BRAWLING_REWARDS[Utils
    								.random(BRAWLING_REWARDS.length - 1)], 1),
    						new WorldTile(this.getLastWorldTile()), killer, true,
    						180, true);
    			}
    			if (isRevenantNPC(getDefinitions().name)
    					&& killer.checkTotalLevel(350) < 350
    					&& Utils.random(3000) >= 2700) {
    				int pvpItem = PVP_ITEMS[Utils.random(PVP_ITEMS.length - 1)];
    				World.addGroundItem(
    						new Item(pvpItem, pvpItem == 13882 ? Utils.random(30)
    								: pvpItem == 13879 ? Utils.random(30) : 1),
    						new WorldTile(this.getLastWorldTile()), killer, true,
    						180, true);
    				return;
    			} else if (isRevenantNPC(getDefinitions().name)
    					&& killer.checkTotalLevel(1500) > 1000
    					&& Utils.random(1000) >= 900) {
    				int pvpItem = PVP_ITEMS[Utils.random(PVP_ITEMS.length - 1)];
    				World.addGroundItem(
    						new Item(pvpItem, pvpItem == 13882 ? Utils.random(30)
    								: pvpItem == 13879 ? Utils.random(30) : 1),
    						new WorldTile(this.getLastWorldTile()), killer, true,
    						180, true);
    				return;
    			} else if (isRevenantNPC(getDefinitions().name)) {
    				World.addGroundItem(new Item(995, Utils.random(5000)),
    						new WorldTile(this.getLastWorldTile()), killer, true,
    						180, true);
    				return;
    			}
    			if (isLucien(getDefinitions().name) && Utils.random(15) == 0) {
    				World.addGroundItem(
    						new Item(LUCIEN_REWARDS[Utils
    								.random(LUCIEN_REWARDS.length - 1)], 1),
    						new WorldTile(this.getLastWorldTile()), killer, true,
    						180, true);
    			
    			}
    			Drop[] possibleDrops = new Drop[drops.length];
    			Item ring = killer.getEquipment().getItem(Equipment.SLOT_RING);
    			int possibleDropsCount = 0;
    			for (Drop drop : drops) {
    				if (drop.getRate() == 100) {
    					sendDrop(killer, drop);
    				} else {
    					if (Utils.random(1, 100) <=  (drop.getRate() * killer.getDropBoost())) {
    						possibleDrops[possibleDropsCount++] = drop;
    					}
    				}
    			}
    			if (onLowPointsTable(getDefinitions().name)) {
    				killer.setPvmPoints(killer.getPvmPoints() + 10);
    				killer.getPackets().sendGameMessage(
    						"You've been awarded 10 PvM points for your effort, you now have "
    								+ killer.getPvmPoints() + " Points.");
    			} else if (onMedPointsTable(getDefinitions().name)) {
    				killer.setPvmPoints(killer.getPvmPoints() + 35);
    				killer.getPackets().sendGameMessage(
    						"You've been awarded 35 PvM points for your effort, you now have "
    								+ killer.getPvmPoints() + " Points.");
    			} else if (onHighPointsTable(getDefinitions().name)) {
    				killer.setPvmPoints(killer.getPvmPoints() + 100);
    				killer.getPackets().sendGameMessage(
    						"You've been awarded 100 PvM points for your effort, you now have "
    								+ killer.getPvmPoints() + " Points.");
    			}
    			if (possibleDropsCount > 0)
    				sendDrop(killer,
    						possibleDrops[Utils.getRandom(possibleDropsCount - 1)]);
    			if (getCombatLevel() > 100) {
    				if (Utils.random(3) == 0)
    					dropCharm(killer,
    							HIGH_CHARMS_DROP[Utils
    									.random(HIGH_CHARMS_DROP.length)], id);
    				return;
    			} else if (getCombatLevel() > 50) {
    				if (Utils.random(3) == 0)
    					dropCharm(killer,
    							MED_CHARMS_DROP[Utils
    									.random(MED_CHARMS_DROP.length)], id);
    				return;
    			} else if (getCombatLevel() < 50) {
    				if (Utils.random(3) == 0)
    					dropCharm(killer,
    							LOW_CHARMS_DROP[Utils
    									.random(LOW_CHARMS_DROP.length)], id);
    				return;
    			}						
    		} catch (Exception e) {
    			e.printStackTrace();
    		} catch (Error e) {
    			e.printStackTrace();
    		}
    	}
    Reply With Quote  
     

  2. #2  
    Donator


    Join Date
    Sep 2015
    Age
    24
    Posts
    532
    Thanks given
    68
    Thanks received
    115
    Rep Power
    414
    Most likely it's the public void drop() method in NPC


    Code:
    				
    					if (Utils.random(1, 100) <=  (drop.getRate() * killer.getDropBoost())) {
    						possibleDrops[possibleDropsCount++] = drop;
    					}
    try changing this into:

    Code:
    					if ((Utils.random(99) + 1) <= drop.getRate() * dropRate) {
    						if (drop.getRate() == 0) {
    							continue;
    						}
    						if (possibleDrops.length > 0) {
    							if (drop != null && possibleDrops != null && possibleDrops.length > 0) {
    								possibleDrops[possibleDropsCount++] = drop;
    							}
    						}
    					}
    Reply With Quote  
     

  3. Thankful user:


  4. #3  
    Registered Member Archeon's Avatar
    Join Date
    Jun 2015
    Posts
    345
    Thanks given
    17
    Thanks received
    5
    Rep Power
    2
    Quote Originally Posted by GlamourGirl View Post
    Most likely it's the public void drop() method in NPC


    Code:
    				
    					if (Utils.random(1, 100) <=  (drop.getRate() * killer.getDropBoost())) {
    						possibleDrops[possibleDropsCount++] = drop;
    					}
    try changing this into:

    Code:
    					if ((Utils.random(99) + 1) <= drop.getRate() * dropRate) {
    						if (drop.getRate() == 0) {
    							continue;
    						}
    						if (possibleDrops.length > 0) {
    							if (drop != null && possibleDrops != null && possibleDrops.length > 0) {
    								possibleDrops[possibleDropsCount++] = drop;
    							}
    						}
    					}
    Ahh, that pretty much helped! Thanks
    another thing is, I had to add this method: double dropRate = 1;
    Could you explain what happens if I put 1 or 2?
    Does that mean that if I put 2 I will get 2x the drop rate or is it that when I change the droprate in settings to 2x that also you receive 2x the drop rate?
    Reply With Quote  
     

  5. #4  
    Respected Member


    Kris's Avatar
    Join Date
    Jun 2016
    Age
    26
    Posts
    3,638
    Thanks given
    820
    Thanks received
    2,642
    Rep Power
    5000
    Quote Originally Posted by Archeon View Post
    Ahh, that pretty much helped! Thanks
    another thing is, I had to add this method: double dropRate = 1;
    Could you explain what happens if I put 1 or 2?
    Does that mean that if I put 2 I will get 2x the drop rate or is it that when I change the droprate in settings to 2x that also you receive 2x the drop rate?
    1. That's not a method, that's a variable. You do not need it at all, feel free to delete it completely.
    2. Changing the value of that variable will indeed increase the drop rate, but not by how much you'd expect. It'd increase the drop rate for all the drops in the game.
    For example, say you had three drops, A) 70%, B) 50% and C) 5%. If you doubled the rate (multiply by two), the rates would become A) 140%, B) 100% & C) 10%.
    Next up the game would generate a random value between 1 and 100.
    Now due to the design of the Matrix drop system, it would loop over all the drops and check if the random value is below the drop's rate, and if it is so, it would add the given drop to a list of possible drops. At the end of the loop cycle, it simply picks a random entry from the list.
    Because two of the drops are equal or exceed the value of 100, they'd both always be on the possible drops list. So effectively, the chance of receiving drops A & B is the same. However, now comes in the next variable. Drop C). This drop would only become a part of the list at 10% of the occurrences, therefore the true rate of these three drops would be A) 47.619%, B) 47.619% & C) 4.7619%.
    In comparison, the true rate of the drops at the modifier of 1.0 would be A) 56%, B) 40% & C) 4%.
    So yes, the actual drop rate would indeed increase for the drops that are already rare to begin with, however this would be at the cost of the other, common drops, and it would be nowhere near as to what you'd expect. Just because it's being multiplied by two doesn't mean the drop rate would actually become two times as common.


    Edit: I just realized my calculations are slightly off due to the fact that your 'random' variable only amounts up to 99% - it's always between 1 and 100, not 0 and 100; my calculations were based off of the range of 100% therefore the rates are very slightly off.
    Attached image
    Reply With Quote  
     

  6. Thankful user:


  7. #5  
    Registered Member Archeon's Avatar
    Join Date
    Jun 2015
    Posts
    345
    Thanks given
    17
    Thanks received
    5
    Rep Power
    2
    Quote Originally Posted by Kris View Post
    1. That's not a method, that's a variable. You do not need it at all, feel free to delete it completely.
    2. Changing the value of that variable will indeed increase the drop rate, but not by how much you'd expect. It'd increase the drop rate for all the drops in the game.
    For example, say you had three drops, A) 70%, B) 50% and C) 5%. If you doubled the rate (multiply by two), the rates would become A) 140%, B) 100% & C) 10%.
    Next up the game would generate a random value between 1 and 100.
    Now due to the design of the Matrix drop system, it would loop over all the drops and check if the random value is below the drop's rate, and if it is so, it would add the given drop to a list of possible drops. At the end of the loop cycle, it simply picks a random entry from the list.
    Because two of the drops are equal or exceed the value of 100, they'd both always be on the possible drops list. So effectively, the chance of receiving drops A & B is the same. However, now comes in the next variable. Drop C). This drop would only become a part of the list at 10% of the occurrences, therefore the true rate of these three drops would be A) 47.619%, B) 47.619% & C) 4.7619%.
    In comparison, the true rate of the drops at the modifier of 1.0 would be A) 56%, B) 40% & C) 4%.
    So yes, the actual drop rate would indeed increase for the drops that are already rare to begin with, however this would be at the cost of the other, common drops, and it would be nowhere near as to what you'd expect. Just because it's being multiplied by two doesn't mean the drop rate would actually become two times as common.
    Oh wow that's very detailed thanks. I just understand this a bit more lol, still I had an another drop system with always, common, uncommon, rare, very rare and ultra rare. You had possible drops and a rare table, also an accessableraretable this is the reason why I went to % drop system, I didn't understand anything with that drop system lmao. You had to change 3 tables and yet It didn't feel like it changed the drop rates. I don't even know which one would be a better system, but I guess the one that I find easier is the % droprate system.
    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. need help with drop system
    By kaozed in forum Help
    Replies: 2
    Last Post: 08-09-2014, 11:10 PM
  2. Percentage Based Drop System with Item Priority.
    By CTucker in forum Tutorials
    Replies: 28
    Last Post: 03-23-2014, 02:00 PM
  3. Replies: 1
    Last Post: 11-26-2013, 03:54 PM
  4. Replies: 6
    Last Post: 06-15-2013, 12:18 AM
  5. [Delta/PwnScape] Help with Old 317 Drop System [Non-Renamed]
    By Original Majin Goten in forum Help
    Replies: 0
    Last Post: 09-26-2012, 09:26 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •