Thread: How I handle RuneZ Item Spawns - With teaching explanation

Page 1 of 2 12 LastLast
Results 1 to 10 of 11
  1. #1 How I handle RuneZ Item Spawns - With teaching explanation 
    Donator

    Old Oak's Avatar
    Join Date
    May 2011
    Age
    29
    Posts
    1,552
    Thanks given
    542
    Thanks received
    435
    Rep Power
    189
    I'm posting this for 2 reasons:
    1 - if anyone is interested to see how this is handled and if they could apply it to themselves, or learn the infrastructure of loot spawns on a good zombie sever.
    2 - if anyone could give me some advice/tips on any ways I could handle it better

    *posting this in tutorial section because I think I'm 'teaching' people the logic behind this code rather than just copy-paste which is what Snippets is for.*


    So, what this does is hold the information for each specific item that has the ability to be spawned within this certain loot category. In this example the loot category that we are dealing with is Low Supplies. The Low means the given severity, or sub-category, within the main category, which in this case is Supplies (the other three categories are equipment, weapons, and armor). Then, within the subcategory we have a subsubcategory (we're gettin deep ) that specifies it even further, but the uncommon loot isn't technically better or worse than common, it's just that those specific uncommon items I've chosen don't 100% fit under the specific main category I've chosen, but may share some characteristics. By using this system I have allowed my self to create a more realistic environment (for example, this essentially means you wont always find exactly food in the same spot, but if it's a good environment for food, like say, a house, then there is a BETTER chance for food to be there than say a blacksmith's shop). Hopefully this isn't too far over anyone's heads. Also trash loot is just junk, to create, once again, a more realistic environment.

    This class also holds within it the capabilities of randomly selecting a value from the specific subsubcategory enum, when called upon by the main spawning class. When the main class calls upon these subcategory classes it'll randomly decide if it wants a common, uncommon, or trash. Then, depending on which subsubcategory it has chosen, it will randomly pick an item from the specific enum, and return it to the main spawning class. If you can't tell by the code, trash loot has a 10% chance of being selected, uncommon has a 20% chance, and common has a 70% chance of being spawned.

    Code:
    package com.rs.utils.spawning.itemspawning.Supplies;
    
    import java.util.Arrays;
    import java.util.Collections;
    import java.util.List;
    import java.util.Random;
    
    import com.rs.game.item.Item;
    
    public class LowSupplies {
    
    	public enum Common {
    		TUNA(361, 1), TROUT(333, 1), RAW_LOBSTER(377, 1), RAW_MEAT(2132, 1), RAW_CHICKEN(
    				2138, 1), POTATO(1942, 1), CABBAGE(1965, 1), WATER_BOTTLE(6953,
    				1), EMPTY_WATER_BOTTLE(3377, 1), SALMON(329, 1), RAW_TUNA(359,
    				1), BANANA(1963, 1), JUG_OF_WATER(1937, 1), BUCKET(1925, 1), REDBERRY_PIE(
    				2325, 1), BANDAGE(4049, 1), COOKED_RABBIT(3228, 1), MEAT_PIZZA(
    				2293, 1), ANCHOVY_PIZZA_HALF(2299, 1);
    
    		/**
    		 * The specific item ID
    		 */
    		private int itemId;
    
    		/**
    		 * Amount of item being spawned.
    		 */
    		private int amount;
    
    		private Common(int itemId, int amount) {
    			this.itemId = itemId;
    			this.amount = amount;
    		}
    
    		public int getItemId() {
    			return itemId;
    		}
    
    		public int getAmount() {
    			return amount;
    		}
    
    		private static final List<Common> VALUES = Collections
    				.unmodifiableList(Arrays.asList(values()));
    		private static final int SIZE = VALUES.size();
    		private static final Random RANDOM = new Random();
    
    		public static Common randomCommon() {
    			return VALUES.get(RANDOM.nextInt(SIZE));
    		}
    	}
    
    	public enum Uncommon {
    		KNIFE(5605, 1), SMALL_FISHING_NET(6209, 1), PLANK(960, 1), IRON_NAILS(
    				4820, 25), STEEL_CHAIN(1105, 1), STEEL_SWORD(1281, 1), IRON_PICKAXE(
    				1267, 1);
    
    		/**
    		 * The specific item ID
    		 */
    		private int itemId;
    
    		/**
    		 * Amount of item being spawned.
    		 */
    		private int amount;
    
    		private Uncommon(int itemId, int amount) {
    			this.itemId = itemId;
    			this.amount = amount;
    		}
    
    		public int getItemId() {
    			return itemId;
    		}
    
    		public int getAmount() {
    			return amount;
    		}
    
    		private static final List<Uncommon> VALUES = Collections
    				.unmodifiableList(Arrays.asList(values()));
    		private static final int SIZE = VALUES.size();
    		private static final Random RANDOM = new Random();
    
    		public static Uncommon randomUncommon() {
    			return VALUES.get(RANDOM.nextInt(SIZE));
    		}
    	}
    
    	public enum Trash {
    		BROKEN_ARROW(687, 1), RUSTY_SWORD(686, 1), OLD_BOOT(685, 1), CAKE_TIN(
    				1887, 1), BEER_GLASS(1919, 1);
    
    		/**
    		 * The specific item ID
    		 */
    		private int itemId;
    
    		/**
    		 * Amount of item being spawned.
    		 */
    		private int amount;
    
    		private Trash(int itemId, int amount) {
    			this.itemId = itemId;
    			this.amount = amount;
    		}
    
    		public int getItemId() {
    			return itemId;
    		}
    
    		public int getAmount() {
    			return amount;
    		}
    
    		private static final List<Trash> VALUES = Collections
    				.unmodifiableList(Arrays.asList(values()));
    		private static final int SIZE = VALUES.size();
    		private static final Random RANDOM = new Random();
    
    		public static Trash randomTrash() {
    			return VALUES.get(RANDOM.nextInt(SIZE));
    
    		}
    	}
    
    	public Item returnItem() {
    
    		Random rand = new Random();
    		int randomNum = rand.nextInt((10 - 1) + 1) + 1;
    
    		if (randomNum > 3)
    			return new Item(Common.randomCommon().getItemId(), Common
    					.randomCommon().getAmount());
    		else if (randomNum > 1)
    			return new Item(Uncommon.randomUncommon().getItemId(), Uncommon
    					.randomUncommon().getAmount());
    		else
    			return new Item(Trash.randomTrash().getItemId(), Trash
    					.randomTrash().getAmount());
    	}
    }
    Attached image
    Reply With Quote  
     

  2. #2  
    Registered Member _Reece's Avatar
    Join Date
    Oct 2014
    Posts
    829
    Thanks given
    176
    Thanks received
    147
    Rep Power
    31
    cool
    Reply With Quote  
     

  3. #3  
    Computer Engineer
    Join Date
    Aug 2014
    Posts
    1,051
    Thanks given
    365
    Thanks received
    215
    Rep Power
    16
    Thanks for contributing mate
    Reply With Quote  
     

  4. #4  
    Success is the worst teacher

    Santa Hat's Avatar
    Join Date
    Oct 2012
    Age
    27
    Posts
    3,334
    Thanks given
    807
    Thanks received
    1,185
    Rep Power
    190
    why would you handle this with an enum? why not an array or even load it from an external file?


    Reply With Quote  
     

  5. #5  
    Registered Member

    Join Date
    Dec 2012
    Posts
    2,999
    Thanks given
    894
    Thanks received
    921
    Rep Power
    2555
    Could all be in one enumeration with the 'type' being defined as part of the parameter. Also, you could change the constructor to not take in the amount, on which it would default to 1
    Attached image
    Reply With Quote  
     

  6. Thankful user:


  7. #6  
    Donator

    Old Oak's Avatar
    Join Date
    May 2011
    Age
    29
    Posts
    1,552
    Thanks given
    542
    Thanks received
    435
    Rep Power
    189
    Quote Originally Posted by Santa Hat View Post
    why would you handle this with an enum? why not an array or even load it from an external file?
    Good point, I have the loot spawn coords being loaded from an external file, so I'll see about loading these as well.

    Quote Originally Posted by Kaleem View Post
    Could all be in one enumeration with the 'type' being defined as part of the parameter. Also, you could change the constructor to not take in the amount, on which it would default to 1
    Thanks, that makes sense as well. I'll change that now.
    Attached image
    Reply With Quote  
     

  8. #7  
    Registered Member
    Join Date
    Jan 2013
    Posts
    610
    Thanks given
    292
    Thanks received
    120
    Rep Power
    39
    Quote Originally Posted by `Luke View Post
    Good point, I have the loot spawn coords being loaded from an external file, so I'll see about loading these as well.



    Thanks, that makes sense as well. I'll change that now.
    What @Santa hat said, it'd be a Hella lot easier. Also, what is your respawn time set to on the ground items?
    Reply With Quote  
     

  9. #8  
    Donator

    Old Oak's Avatar
    Join Date
    May 2011
    Age
    29
    Posts
    1,552
    Thanks given
    542
    Thanks received
    435
    Rep Power
    189
    Quote Originally Posted by Lucifer_ View Post
    What @Santa hat said, it'd be a Hella lot easier. Also, what is your respawn time set to on the ground items?
    25 minutes for now, but that's subject to change. It depends what different approaches I take. I can either do more loot spawn locations, but a lower respawn rate, or less loot spawn locations but a quicker respawn rate. I haven't quite decided yet.

    I have switched this whole system to importing from external files. I haven't really noticed much of a difference either than adding items being easier. And thanks to Kaleem's idea I don't need to enter an amount if that item I want is just an amount of 1
    Attached image
    Reply With Quote  
     

  10. #9  
    Donator


    Join Date
    Jul 2013
    Posts
    1,233
    Thanks given
    1
    Thanks received
    493
    Rep Power
    0
    Good idea, but I would have no use to implement it.
    Reply With Quote  
     

  11. #10  
    Donator

    Join Date
    Oct 2014
    Posts
    587
    Thanks given
    29
    Thanks received
    76
    Rep Power
    26
    Like said above, create a enum with types (common, uncommon, trash) and create one main enum with all the items. If you know that your going to end up with a large enum you might aswell create a XML/Json config for it.
    Programming service - Fast, Cheap & Quality
    http://www.rune-server.org/black-mar...-services.html

    Project that I am currently working on:
    http://www.rune-server.org/runescape...emon-rsps.html

    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. Replies: 1
    Last Post: 04-24-2011, 12:30 AM
  2. Replies: 3
    Last Post: 04-18-2011, 10:29 AM
  3. Replies: 26
    Last Post: 11-01-2009, 11:42 AM
  4. How to create a item with a custom model
    By zachverbeek in forum Help
    Replies: 2
    Last Post: 07-17-2009, 11:27 PM
  5. How to change item spawn limit in rs2hd 525 source
    By sure im crazy in forum Requests
    Replies: 6
    Last Post: 02-21-2009, 02:36 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
  •