Thread: 667-718 Mystery Box Release

Page 1 of 3 123 LastLast
Results 1 to 10 of 22
  1. #1 667-718 Mystery Box Release 
    Registered Member
    Join Date
    Jan 2013
    Posts
    610
    Thanks given
    292
    Thanks received
    120
    Rep Power
    39
    Deciding to release the mystery box that I had for sale, since someone that I sold it to decided to tweak it a little bit and then re-sell it.

    This is very OLD code, so please do not expect it to be 100% perfect, but it does function as it should.

    Features:
    - Spins the box with items that the person chooses
    - Displays the last few items that the player has won from the box
    - Shows the number of spins that the player has left
    - Opens a pop-up which shows the item that the player has won, after the spin has completed.

    I will put all the necessary code needed to add this to a server, but I will not explain how to add it, since this is supposed to be a snippet.

    Spoiler for MysteryBox.java:

    Code:
    package org.nova.kshan.content;
    
    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.List;
    
    import org.nova.Constants;
    import org.nova.game.item.Item;
    import org.nova.game.item.ItemsContainer;
    import org.nova.game.player.Player;
    import org.nova.game.player.controllers.impl.Wilderness;
    
    /**
     * Handles the mystery box
     * 
     * @author K-Shan
     *
     */
    public class MysteryBox {
    	
    	public static int[] commonItems = { 
    		20135, 20139, 20143, 22440, 22441, 22442, 21793, 21787, 21793, 21790,
    		4151, 11694, 11726, 11698, 13738, 13740, 19784, 11283, 1050, 6585,
    		11283, 4151, 11726, 11732, 11730, 14484, 2434, 2434, 2434, 2434 
    	};
    	
    	/**
    	 * Opens the mystery box for the player
    	 * They won't be able to spin if they don't have spins (lol)
    	 * @param player
    	 */
    	public static void openBox(Player player) {
    		player.interfaces().sendInterface(1161);
    		ItemsContainer<Item> asContainer = new ItemsContainer<Item>(30, false);
    		for(int i = 0; i < commonItems.length; i++) {
    			player.getPackets().sendItemOnIComponent(1161, 71 + i, commonItems[i], 1);
    			asContainer.add(new Item(commonItems[i], 1));
    		}
    		player.getPackets().sendItems(90, false, asContainer);
    		player.getPackets().sendInterSetItemsOptionsScript(1161, 104, 90, 4, 9, "Examine");
    		player.getPackets().sendUnlockIComponentOptionSlots(1161, 104, 0, 160, 0);
    		for(int i = 0; i < 6; i++)
    			player.getPackets().sendIComponentText(1161, 108 + i, "");
    		List<String> recent = new ArrayList<String>(player.getRecentMBoxRewards());
    		Collections.reverse(recent);
    		for(int i = 0; i < recent.size(); i++) {
    			player.getPackets().sendIComponentText(1161, 108 + i, recent.get(i));
    		}
    		player.getPackets().sendIComponentText(1161, 101, "Get more spins ("+player.getMBoxSpins()+")");
    	}
    	
    	/**
    	 * Spins the mystery box
    	 * @param player
    	 */
    	public static void spin(Player player) {
    		if(Wilderness.isAtWild(player)) {
    			player.sm("You cannot use this in the wilderness.");
    			player.sm("Also, you are cheating. Stahp.");
    			return;
    		}
    		if(player.getMBoxSpins() < 1) {
    			player.sm("The box is unable to spin. Please get more spins first.");
    			return;
    		}
    		if(player.spinningMBox) {
    			player.sm("You are already using the mystery box, please wait.");
    			return;
    		}
    		if(!player.getInventory().hasFreeSlots()) {
    			player.sm("Please clear up your inventory before using the box.");
    			return;
    		}
    		player.getPackets().spinMysteryBox(commonItems.length);
    		
    		ItemsContainer<Item> asContainer = new ItemsContainer<Item>(30, false);
    		for(int i = 0; i < commonItems.length; i++) {
    			player.getPackets().sendItemOnIComponent(1161, 71 + i, commonItems[i], 1);
    			asContainer.add(new Item(commonItems[i], 1));
    		}
    		player.getPackets().sendItems(90, false, asContainer);
    		player.getPackets().sendInterSetItemsOptionsScript(1161, 104, 90, 4, 9, "Examine");
    		player.getPackets().sendUnlockIComponentOptionSlots(1161, 104, 0, 160, 0);
    		for(int i = 0; i < 6; i++)
    			player.getPackets().sendIComponentText(1161, 108 + i, "");
    		List<String> recent = new ArrayList<String>(player.getRecentMBoxRewards());
    		Collections.reverse(recent);
    		for(int i = 0; i < recent.size(); i++) {
    			player.getPackets().sendIComponentText(1161, 108 + i, recent.get(i));
    		}
    		
    		List<Integer> asList = new ArrayList<Integer>();
    		for(int i = 0; i < commonItems.length; i++)
    			asList.add(commonItems[i]);
    		Collections.shuffle(asList);
    		for(int i = 0; i < 30; i++)
    			player.getPackets().sendItemOnIComponent(1161, 71 + i, asList.get(i), 1);
    		player.getPackets().sendHideIComponent(1161, 13, true);
    		player.getPackets().sendHideIComponent(1161, 38, true);
    		player.getPackets().sendHideIComponent(1161, 39, true);
    		player.getPackets().sendHideIComponent(1161, 122, true);
    		player.getPackets().sendHideIComponent(1161, 123, true);
    		player.spinningMBox = true;
    		player.getPackets().sendHideIComponent(1161, 114, true);
    		for(int i = 116; i <= 121; i++)
    			player.getPackets().sendHideIComponent(1161, i, true);
    		player.getPackets().sendIComponentText(1161, 101, "Get more spins ("+player.getMBoxSpins()+")");
    		player.getPackets().sendBlackOut(5);
    		player.setInfiniteStopDelay();
    		player.doAfterDelay(Constants.WORLD_CYCLE_TIME * 8, () -> {
    			player.getPackets().sendHideIComponent(1161, 13, false);
    			player.getPackets().sendHideIComponent(1161, 38, false);
    			player.getPackets().sendHideIComponent(1161, 39, false);
    			player.getPackets().sendHideIComponent(1161, 122, false);
    			player.getPackets().sendHideIComponent(1161, 123, false);
    			player.addMBoxReward(asList.get(12));
    			player.getPackets().sendIComponentText(1161, 101, "Get more spins ("+player.getMBoxSpins()+")");
    			player.getPackets().sendBlackOut(0);
    			player.spinningMBox = false;
    			List<String> recentRewards = new ArrayList<String>(player.getRecentMBoxRewards());
    			Collections.reverse(recentRewards);
    			for(int i = 0; i < recentRewards.size(); i++) {
    				player.getPackets().sendIComponentText(1161, 108 + i, recentRewards.get(i));
    			}
    			// TODO add the "You've won" interface
    			player.getPackets().sendHideIComponent(1161, 114, false);
    			for(int i = 116; i <= 121; i++)
    				player.getPackets().sendHideIComponent(1161, i, false);
    			player.getPackets().sendIComponentText(1161, 120, new Item(asList.get(12), 1).getName());
    			player.getPackets().sendItemOnIComponent(1161, 121, asList.get(12), 1);
    			//player.getRecentMBoxRewards().clear();
    			player.resetStopDelay();
    		});
    	}
    
    	public static void click(Player player, int interfaceId, int cId, int slotId, int packetId) {
    		if(cId == 122)
    			MysteryBox.spin(player);
    		if(cId == 101)
    			player.getPackets().sendExecMessage("https://google.com");
    	}
    
    }


    Spoiler for Stuff to put in Player.java:

    Code:
    /**
    	 * Executes this runnable after the specified delay has passed.
    	 * Note: Only makes one cycle and ends.
    	 * @param delay
    	 * @param r
    	 */
    	public void doAfterDelay(double delay, Runnable r) {
    		Game.submit(new GameTick(delay) {
    			@Override public void run() {
    				r.run();
    				stop();
    			}
    		});
    	}
    	
    	public transient boolean spinningMBox;
    	
    	private byte mboxSpins;
    	
    	public byte getMBoxSpins() {
    		return mboxSpins;
    	}
    	
    	public void setMBoxSpins(int spins) {
    		mboxSpins = (byte) spins;
    	}
    	
    	private List<String> recentMBoxRewards;
    	
    	public List<String> getRecentMBoxRewards() {
    		return recentMBoxRewards;
    	}
    	
    	public void addMBoxReward(int id) {
    		Item item = new Item(id, 1);
    		getRecentMBoxRewards().add(item.getName());
    		if(this.getRecentMBoxRewards().size() > 6)
    			this.getRecentMBoxRewards().remove(0); // Removes the first element
    		sm("Congratulations! You've won x1 "+item.getName()+"!");
    		inventory.addItem(item);
    		mboxSpins--;
    		sm("You have "+mboxSpins+" spins left.");
    	}


    Spoiler for In PacketSender.java (Server Sided):

    Code:
    public void spinMysteryBox(int itemsLength) {
    		OutputStream stream = new OutputStream();
    		stream.writePacketVarShort(153);
    		stream.writeByte(itemsLength);
    		stream.endPacketVarShort();
    		session.write(stream);
    	}


    Spoiler for To put into ClientPacketDecoder.java:

    Code:
    // Spins the mystery box.
    		if(packetHolder.incomingPacket == IncomingPacket.SPIN_MYSTERY_BOX) {
    			// TODO
    			byte itemsLength = packet.readByte();
    			
    			// Reset positions
    			WidgetEditor.sendInterface(1161);
    			
    			Utils.data.put("mbox_stop", false);
    			for(int index = 0; index < itemsLength; index++) {
    				WCDef def = WCDef.get(1161, 41 + index);
    				WCDef items = WCDef.get(1161, 71 + index);
    				if((boolean) Utils.data.get("mbox_stop"))
    					break;
    				Ticks.add(new Tick(0.01) {
    					int x = def.basePositionX;
    					int y = def.basePositionY;
    					int itx = items.basePositionX;
    					int ity = items.basePositionY;
    					int ticks = 0;
    					public void run() {
    						if((boolean) Utils.data.get("mbox_stop")) {
    							stop();
    							return;
    						}
    						int subtract = 15;
    						subtract = subtract - (1 * ((int) ticks / 10));
    						if(subtract <= 1)
    							subtract = 1;
    						x -= subtract;
    						itx -= subtract;
    						if(x <= -(38 * 20)) {
    							x = 380;
    						}
    						if(itx <= -(38 * 20)) {
    							itx = 380;
    						}
    						WidgetPackets.setPosition(1161, def.getComponentId(), x, y, 0, 0);
    						WidgetPackets.setPosition(1161, items.getComponentId(), itx, ity, 0, 0);
    						ticks++;
    						if(ticks == (375)) {
    							Utils.data.put("mbox_stop", true);
    						}
    					}
    				});
    			}
    			
    			packetHolder.incomingPacket = null;
    			return true;
    		}


    Spoiler for From Utils.java client sided:

    Code:
    /**
    	 * Temporary data that can be used in this session.
    	 */
    	public static Map<String, Object> data = new HashMap<String, Object>();


    Spoiler for Send interface from "WidgetEditor.java":

    Code:
    /**
    	 * Resets the current interface on the screen and then
    	 * re-sends it.
    	 * @param wId
    	 */
    	public static void sendInterface(int wId) {
    		int windowId = 548;
    		int windowChildId = 9;
    		int sendingHash = windowId << 16 | windowChildId;
    		Node_Sub2 node_sub2 = (Node_Sub2) Class289.aHashTable3630.getNode(3512, sendingHash);
    		if (node_sub2 != null)
    			Class243.method3060((byte) -91, false, true, node_sub2);
    		if (Node_Sub25_Sub3.aWidget9990 != null) {
    			ClientScript.method2321(-1, Node_Sub25_Sub3.aWidget9990);
    			Node_Sub25_Sub3.aWidget9990 = null;
    		}
    		Class93.method1047(0, wId, sendingHash, 0, false);
    	}


    Spoiler for setPosition from 'WidgetPackets.java':

    Code:
    /**
    	 * Changes the position of a widget component.
    	 * @param wId
    	 * @param cId
    	 * @param newX
    	 * @param newY
    	 */
    	public static void setPosition(int wId, int cId, int newX, int newY,
    			int xOffset, int yOffset) {
    		WCDef widget = WCDef.get(wId, cId);
    		widget.basePositionX = newX;
    		widget.basePositionY = newY;
    		if (xOffset < 0)
    			xOffset = 0;
    		else if (xOffset > 5)
    			xOffset = 5;
    		if (yOffset < 0)
    			yOffset = 0;
    		else if (yOffset > 5)
    			yOffset = 5;
    		widget.xAspectRatio = (byte) xOffset;
    		widget.yAspectRatio = (byte) yOffset;
    		ClientScript.method2321(-1, widget);
    		Class28.method332(0, widget);
    		if (widget.anInt4687 == -1)
    			Class224.method2105(widget.ihash, 1315);
    	}


    And finally, here is a download for the components of the interface. This involves custom sprite IDs, so you will have to adjust it to make it work. These components are for interface 1161.
    Download: https://mega.nz/#!SNcTACJA!ejsfYW25p...5KM0ymrWabL5ag

    Not really sure if I am missing anything, but oh well.

    This is the finished product:

    Attached image

    (Original MP4 link to view it in better quality: https://i.gyazo.com/53ac191ffa714ca8...3c3eb8f67c.mp4)

    In theory, this SHOULD be quite useful for people who know what they are doing, or a nice learning experience for everyone else, but there will be people who have their own opinion about this.

    If anyone has any questions, feel free to ask, and if I am available, I will try my best to answer. Happy Sunday!
    Reply With Quote  
     


  2. #2  
    Registered Member
    Join Date
    Aug 2015
    Posts
    130
    Thanks given
    1
    Thanks received
    19
    Rep Power
    42
    Looks decent, GJ!
    Reply With Quote  
     

  3. #3  
    Registered Member
    Join Date
    Jan 2013
    Posts
    610
    Thanks given
    292
    Thanks received
    120
    Rep Power
    39
    Quote Originally Posted by alexsmith1097 View Post
    Looks decent, GJ!
    Thanks man. This is what was sitting in my backups, I have since then changed it up and modified it quite a bit; however, I hope some people will find it useful.
    Reply With Quote  
     

  4. #4  
    Registered Member

    Join Date
    Oct 2011
    Posts
    2,084
    Thanks given
    0
    Thanks received
    1,043
    Rep Power
    3608
    nice one.
    Reply With Quote  
     

  5. #5  
    Extreme Donator 667-718 Mystery Box Release Market Banned



    Join Date
    Aug 2011
    Age
    28
    Posts
    3,589
    Thanks given
    1,402
    Thanks received
    1,620
    Rep Power
    5000
    Good to see things released for higher revisions, nice work.

    Attached image

    Attached image
    Discord: Roy#2382

    Reply With Quote  
     

  6. Thankful user:


  7. #6  
    Registered Member
    Join Date
    Jan 2013
    Posts
    610
    Thanks given
    292
    Thanks received
    120
    Rep Power
    39
    Quote Originally Posted by Roy X D View Post
    Good to see things released for higher revisions, nice work.
    Thank you! This should work for other revisions too, 503+, up until 718, but I haven't tried it on anything except 562, 667 and 718 loading RS3 stuff.
    Reply With Quote  
     

  8. #7  
    Banned

    Join Date
    Mar 2015
    Age
    31
    Posts
    1,332
    Thanks given
    215
    Thanks received
    329
    Rep Power
    0
    thanks man
    Reply With Quote  
     

  9. Thankful user:


  10. #8  
    Development Services √

    Oogle's Avatar
    Join Date
    Apr 2012
    Age
    25
    Posts
    3,976
    Thanks given
    650
    Thanks received
    516
    Rep Power
    483
    Nice little snippet, thank you for the release.


    Attached image

    Attached image
    Reply With Quote  
     

  11. #9  
    van 't stad

    Shnek's Avatar
    Join Date
    Oct 2013
    Posts
    1,065
    Thanks given
    343
    Thanks received
    297
    Rep Power
    109
    Nice release, it really sucks when people sell your hard work
    Attached image

    Do not use the vps from ovh, blocking vps without reason and no customer support
    Reply With Quote  
     

  12. #10  
    Registered Member
    rebecca's Avatar
    Join Date
    Aug 2017
    Posts
    1,071
    Thanks given
    862
    Thanks received
    915
    Rep Power
    5000
    bit hypocritical that u are claiming my free release of the interface as your own

    Attached image
    Last edited by rebecca; 01-28-2019 at 05:26 AM.
    Reply With Quote  
     

Page 1 of 3 123 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. 667/718+ itemdef editor(release)
    By Cocaine in forum Downloads
    Replies: 59
    Last Post: 03-29-2016, 05:26 PM
  2. [667/***]Adding Mystery Boxes
    By Coruption in forum Snippets
    Replies: 24
    Last Post: 07-17-2015, 11:36 PM
  3. [718] Mystery Box Help
    By Vulcan in forum Help
    Replies: 10
    Last Post: 09-22-2014, 02:13 AM
  4. 718 Mystery box Codes
    By L3git in forum Requests
    Replies: 12
    Last Post: 12-23-2012, 06:47 PM
  5. Replies: 41
    Last Post: 11-08-2012, 11:40 PM
Tags for this Thread

View Tag Cloud

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