Thread: [PI] Crystal Chest and Key with Rewards

Page 1 of 2 12 LastLast
Results 1 to 10 of 20
  1. #1 [PI] Crystal Chest and Key with Rewards 
    Registered Member

    Join Date
    Sep 2008
    Age
    19
    Posts
    1,673
    Thanks
    579
    Thanked 643 Times in 273 Posts
    Rep Power
    364
    Preview .GIF

    Make new class CrystalChest.java in Minigames package.

    Code:
    package server.model.minigames;
    
    import server.event.Event;
    import server.event.EventContainer;
    import server.event.EventManager;
    import server.model.players.Client;
    import server.util.Misc;
    
    /*
     * @author Liberty / Robbie
     */
    
    public class CrystalChest {
    
    	private static final int[] CHEST_REWARDS = { 1079, 1093, 526, 1969, 371, 2363, 451 };
    	public static final int[] KEY_HALVES = { 985, 987 };
    	public static final int KEY = 989;
    	private static final int DRAGONSTONE = 1631;
    	private static final int OPEN_ANIMATION = 881;
    
    	public static void makeKey(Client c) {
    		if (c.getItems().playerHasItem(toothHalf(), 1)
    				&& c.getItems().playerHasItem(loopHalf(), 1)) {
    			c.getItems().deleteItem(toothHalf(), 1);
    			c.getItems().deleteItem(loopHalf(), 1);
    			c.getItems().addItem(KEY, 1);
    		}
    	}
    
    	public static boolean canOpen(Client c) {
    		if (c.getItems().playerHasItem(KEY)) {
    			return true;
    		} else {
    			c.sendMessage("The chest is locked");
    			return false;
    		}
    	}
    
    	public static void searchChest(final Client c, final int id, final int x,
    			final int y) {
    		if (canOpen(c)) {
    			c.sendMessage("You unlock the chest with your key.");
    			c.getItems().deleteItem(KEY, 1);
    			c.startAnimation(OPEN_ANIMATION);
    			c.getPA().checkObjectSpawn(id + 1, x, y, 2, 10);
    			EventManager.getSingleton().addEvent(new Event() {
    				public void execute(EventContainer e) {
    					c.getItems().addItem(DRAGONSTONE, 1);
    					c.getItems().addItem(995, Misc.random(8230));
    					c.getItems().addItem(
    							CHEST_REWARDS[Misc.random(getLength() - 1)], 1);
    					c.sendMessage("You find some treasure in the chest.");
    					c.getPA().checkObjectSpawn(id, x, y, 2, 10);
    
    					e.stop();
    				}
    			}, 1800);
    		}
    	}
    
    	public static int getLength() {
    		return CHEST_REWARDS.length;
    	}
    	public static int toothHalf(){
    		return KEY_HALVES[0];
    	}
    	public static int loopHalf(){
    		return KEY_HALVES[1];
    	}
    }
    Then in UseItem.java

    Import
    Code:
    import server.model.minigames.CrystalChest;
    Inside the method
    Code:
     public static void ItemonItem(Client c, int itemUsed, int useWith)
    Add
    Code:
    		if (itemUsed == CrystalChest.toothHalf()
    				&& useWith == CrystalChest.loopHalf()
    				|| itemUsed == CrystalChest.loopHalf()
    				&& useWith == CrystalChest.toothHalf()) {
    			CrystalChest.makeKey(c);
    		}
    and Finally under
    Code:
    switch (objectID) {
    Add
    Code:
    		case 172:
    			if(itemId == CrystalChest.KEY)
    				CrystalChest.searchChest(c, objectID, objectX, objectY);
    			break;
    Reply With Quote  
     

  2. Thankful users:


  3. #2  
    Registered Member XxNinjaxX's Avatar
    Join Date
    Aug 2010
    Posts
    193
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Rep Power
    0
    First post! , thanks for this
    Reply With Quote  
     

  4. #3  
    Registered Member

    Join Date
    Jun 2011
    Posts
    1,301
    Thanks
    160
    Thanked 106 Times in 88 Posts
    Rep Power
    252
    Thanks, added and will be using .

    A good advantage for players to make money!
    Reply With Quote  
     

  5. #4  
    Trusted Gold Seller
    Treq's Avatar
    Join Date
    Aug 2010
    Posts
    454
    Thanks
    69
    Thanked 65 Times in 40 Posts
    Rep Power
    22
    Good job. this is something that was never meant to be thrown in to many classes (as alot of sources did). I like everything neat and organized
    ~Treq~ (Previously Spetsnaz)

    Reply With Quote  
     

  6. #5  
    help! i have fallen and can't get up!
    Pegasus's Avatar
    Join Date
    Mar 2011
    Age
    19
    Posts
    1,802
    Thanks
    874
    Thanked 399 Times in 233 Posts
    Rep Power
    443
    Goodjob on this Liberty.
    Reply With Quote  
     

  7. #6  
    Donator


    Join Date
    Dec 2010
    Posts
    5,255
    Thanks
    632
    Thanked 2,112 Times in 1,134 Posts
    Rep Power
    2204
    Does this really need it's own class
    Reply With Quote  
     

  8. #7  
    Registered Member

    Join Date
    Sep 2008
    Age
    19
    Posts
    1,673
    Thanks
    579
    Thanked 643 Times in 273 Posts
    Rep Power
    364
    Quote Originally Posted by Harlan View Post
    Does this really need it's own class
    You probably cram everything into the same 500kb class, I find this a cleaner alternative.
    Reply With Quote  
     

  9. Thankful user:


  10. #8  
    Registered Member
    Join Date
    Dec 2010
    Posts
    541
    Thanks
    63
    Thanked 25 Times in 24 Posts
    Rep Power
    4
    Pretty basic, but still , good job.
    Reply With Quote  
     

  11. #9  
    Registered Member
    Join Date
    Apr 2011
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    1
    yeh nice evry DSPK has it standard.
    Reply With Quote  
     

  12. #10  
    Banned

    Join Date
    Sep 2010
    Age
    18
    Posts
    580
    Thanks
    149
    Thanked 201 Times in 105 Posts
    Rep Power
    0
    looks clean man
    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)

Similar Threads

  1. [pi]Fully working Crystal Chest
    By deadsoul in forum Tutorials
    Replies: 2
    Last Post: 01-04-2011, 05:17 PM
  2. Replies: 4
    Last Post: 02-07-2010, 09:09 PM
  3. Adding rare Crystal chest
    By Jukk in forum Tutorials
    Replies: 18
    Last Post: 02-18-2008, 06:40 PM
  4. Crystal chest V2
    By Volcom in forum Tutorials
    Replies: 18
    Last Post: 12-10-2007, 11:54 PM
  5. fully working crystal chest!
    By Volcom in forum Tutorials
    Replies: 32
    Last Post: 09-11-2007, 01:58 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
  •