Thread: [Runesource/2006Scape] Parcel Opening

Results 1 to 4 of 4
  1. #1 [Runesource/2006Scape] Parcel Opening 
    Diligence pays off.

    Venn's Avatar
    Join Date
    Nov 2012
    Age
    22
    Posts
    239
    Thanks given
    205
    Thanks received
    61
    Discord
    View profile
    Rep Power
    88
    Hello, Rune-Server. This is my release of parcel opening for Runesource. I am making this for my server, and it was very simple to make so I thought I would share it here.

    These methods are easily convertible to other sources, if you would like to. Package names of course will be different and will have to be modified.

    Pretty much what I did was change the names of a couple 'Box bauble' items (from the 2005 Christmas events). Now that I think of it, Christmas is coming up and these could just be used as little present items in a server. Huh. Anyways, after I changed the names of the items, i made it so when you use a knife on them, you get a random Item from an array, with a change of you getting a common, uncommon, rare, or very rare item based on a chance rate out of 100.

    It's very simple to do, but some developers may find this useful towards their server, as you may do whatever you want to it, whether it's renaming the items, adding different kinds of parcels/boxes with different rewards, or just changing the chance rates or basic values in general.

    This was also a sort of 'test' of my abilities in writing this code with nice formatting and logical methods of writing it.

    Without further ado, let's get into the code.

    First off, if you'd like to rename the items, open up your ItemDef.java file in your client and add this in the forId method.

    Under
    Code:
            switch(i) {
    Add this:
    Code:
    			case 6830:
    				itemDef.name = "Combat parcel";
    				itemDef.description = "A box containing some combat item. What could be inside?".getBytes();
    
    				break;
    			case 6831:
    				itemDef.name = "Skill parcel";
    				itemDef.description = "A box containing some skilling item. What could be inside?".getBytes();
    				break;
    Next, in your server files, go to model/content/players/items/functions and add in a new package called parcel.

    Your files should look like this:


    Now, in the parcel package, create a new class called ParcelType, and add this code:
    Code:
    /**
     * @author Ventro :: R-S: http://www.rune-server.ee/members/ventro/
     */
    public enum ParcelType {
    
        COMBAT(6830),
    
        SKILL(6831);
    
        private int id;
    
        ParcelType(int id) {
            this.id = id;
        }
    
        public int getId() {
            return id;
        }
    
    }
    Now create a file in the parcel package called Parcel.java and add in this code:
    Code:
    import com.rs2.model.World;
    import com.rs2.model.players.Player;
    import com.rs2.model.players.item.Item;
    import com.rs2.model.players.item.ItemDefinition;
    import com.rs2.util.Misc;
    
    /**
     * @author Ventro :: R-S: http://www.rune-server.ee/members/ventro/
     */
    public class Parcel {
    
        //Put your own items here
        private static final Item[] COMBAT_COMMON = {new Item(1111, 1), new Item(1161, 1), new Item(890, 125), new Item(882, 150)};
        private static final Item[] COMBAT_UNCOMMON = {new Item(1127, 1)};
        private static final Item[] COMBAT_RARE = {new Item(1305, 1), new Item(1377, 1), new Item(4587, 1), new Item(3205, 1)};
        private static final Item[] COMBAT_VERY_RARE = {new Item(4151, 1)};
    
        private static final Item[] SKILL_COMMON = {};
        private static final Item[] SKILL_UNCOMMON = {};
        private static final Item[] SKILL_RARE = {};
        private static final Item[] SKILL_VERY_RARE = {};
    
        private Player player;
        private ParcelType type;
    
        public Parcel(Player player, ParcelType type) {
            this.player = player;
            this.type = type;
            openParcel(type);
        }
    
        private void openParcel(ParcelType type) {
            if (!player.getInventory().playerHasItem(type.getId())) {
                return;
            }
            player.getInventory().removeItem(new Item(type.getId()));
            ParcelItem item;
            switch (type) {
                case COMBAT:
                    item = ParcelItem.COMBAT_ITEM;
                    break;
                case SKILL:
                    item = ParcelItem.SKILL_ITEM;
                    break;
                default: //idk why i'm doing this
                    item = ParcelItem.SKILL_ITEM;
                    break;
    
            }
            Item reward = new Item(995, 1);
            int rand = Misc.random(100);
            if (rand < 5) {
                World.messageToAll("@[email protected]" + Misc.formatPlayerName(player.getUsername()) + " has just received a very rare reward from a parcel!");
                reward = item.getVeryRare()[Misc.randomMinusOne(item.getVeryRare().length)];
            }
            if (rand < 15 && rand >= 5) {
                reward = item.getRare()[Misc.randomMinusOne(item.getRare().length)];
            }
            if (rand < 45 && rand >= 15) {
                reward = item.getUncommon()[Misc.randomMinusOne(item.getUncommon().length)];
            }
            if (rand <= 100 && rand >= 45) {
                reward = item.getCommon()[Misc.randomMinusOne(item.getCommon().length)];
            } else if (reward == null) {
                reward = new Item(995, 25000);
            }
            ItemDefinition def = ItemDefinition.forId(reward.getId());
            int id = reward.getId();
            int count = reward.getCount();
            int count1 = Misc.random(count);
            player.getInventory().addOrDropItem(new Item(id, ((def.isStackable() && count > 1) ? count1 : 1 )));
            player.getActionSender().sendMessage("You cut open your parcel and receive" + (count1 > 1 ? " " + count1 + "x" : " a"
                    + (def.getName().startsWith("A") || def.getName().startsWith("E") || def.getName().startsWith("I") || def.getName().startsWith("O") || def.getName().startsWith("U") ? "n" : "")) + " " +
                    "" + Misc.formatPlayerName(def.getName()) + "" + (reward.getCount() > 1 ? "s" : "") + ".");
            return;
    
        }
    
        public enum ParcelItem {
    
            COMBAT_ITEM(COMBAT_COMMON, COMBAT_UNCOMMON, COMBAT_RARE, COMBAT_VERY_RARE),
            SKILL_ITEM(SKILL_COMMON, SKILL_UNCOMMON, SKILL_RARE, SKILL_VERY_RARE);
    
            private Item[] common;
            private Item[] uncommon;
            private Item[] rare;
            private Item[] veryRare;
    
            ParcelItem(Item[] common, Item[] uncommon, Item[] rare, Item[] veryRare) {
                this.common = common;
                this.uncommon = uncommon;
                this.rare = rare;
                this.veryRare = veryRare;
            }
    
            public Item[] getCommon() {
                return common;
            }
    
            public Item[] getUncommon() {
                return uncommon;
            }
    
            public Item[] getRare() {
                return rare;
            }
    
            public Item[] getVeryRare() {
                return veryRare;
            }
    
        }
    
    }
    Finally, in ItemPacketHandler (located in net/packet/packets/), find your useItemOnItem method and add in this code:

    Code:
            if (firstItem == 946 && (secondItem == 6830 || secondItem == 6831) || (firstItem == 6830 || firstItem == 6831) && secondItem == 946) {
                new Parcel(player, (secondItem == 6830) ? ParcelType.COMBAT : ParcelType.SKILL);
                return;
            }
    And you're done. Compile and run your server and you should be able to use a knife on one of the items and receive a random reward!

    Please note that you will have to add in new Item ID's into the constant variables inside of Parcel.java. If you do not add them in, you may receive errors.

    Thanks!
    Quote Originally Posted by Therandomkid View Post
    if you wanna hate just remember i fucked your mom
    Reply With Quote  
     

  2. Thankful users:


  3. #2  
    RS Veteran

    Apex's Avatar
    Join Date
    Dec 2015
    Posts
    478
    Thanks given
    10
    Thanks received
    78
    Rep Power
    124
    nice contribution, hope some uses this.
    Reply With Quote  
     

  4. #3  
    Banned
    Join Date
    Aug 2014
    Posts
    518
    Thanks given
    88
    Thanks received
    21
    Rep Power
    0
    Nice... I might take a look into this thanks
    Reply With Quote  
     

  5. #4  
    Banned
    Join Date
    Jun 2012
    Posts
    510
    Thanks given
    33
    Thanks received
    50
    Rep Power
    0
    Could be cleaned up quite a bit. but good 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. Replies: 9
    Last Post: 06-17-2015, 04:22 PM
  2. Replies: 2
    Last Post: 12-21-2014, 07:16 PM
  3. runesource(2006scape) player loading passwords
    By FredoKruger2 in forum Help
    Replies: 6
    Last Post: 02-19-2013, 08:02 PM
  4. Replies: 31
    Last Post: 08-04-2011, 03:28 PM
  5. Replies: 15
    Last Post: 04-02-2011, 10:30 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
  •