Thread: Simpler ways to do things like this?

Results 1 to 6 of 6
  1. #1 Simpler ways to do things like this? 
    Registered Member

    Join Date
    Jun 2007
    Age
    29
    Posts
    3,003
    Thanks given
    52
    Thanks received
    98
    Rep Power
    3208
    Is there a cleaner/simpler way of doing things like this with action buttons?

    Code:
    		/*
    		 * Agility arena ticket exchange
    		 */
    		case 6:
    			switch (buttonId) {
    			case 93: //one ticket for experience
    				if(player.getInventory().contains(2996, 1)) {
    					player.getSkills().addXp(Skills.AGILITY, 240);
    					player.getInventory().deleteItem(2996, 1);
    					player.getActionSender().sendMessage("You exchange 1 agility arena ticket for 240 agility experience.");
    				}
    				else {
    					player.getActionSender().sendMessage("You don't have enough agility arena tickets.");
    				}
    				break;
    			case 95: //ten tickets for experience
    				if(player.getInventory().contains(2996, 10)) {
    					player.getSkills().addXp(Skills.AGILITY, 2480);
    					player.getInventory().deleteItem(2996, 10);
    					player.getActionSender().sendMessage("You exchange 10 agility arena tickets for 2,480 agility experience.");
    
    				}
    				else {
    					player.getActionSender().sendMessage("You don't have enough agility arena tickets.");
    				}
    				break;
    			case 96: //twenty five tickets for experience
    				if(player.getInventory().contains(2996, 25)) { 
    					player.getSkills().addXp(Skills.AGILITY, 6500);
    					player.getInventory().deleteItem(2996, 25);
    					player.getActionSender().sendMessage("You exchange 25 agility arena tickets for 6,500 agility experience.");
    				}
    				else {
    					player.getActionSender().sendMessage("You don't have enough agility arena tickets.");
    				}
    				break;
    			case 97: //one hundred tickets for experience
    				if(player.getInventory().contains(2996, 100)) {
    					player.getSkills().addXp(Skills.AGILITY, 28000);
    					player.getInventory().deleteItem(2996, 100);
    					player.getActionSender().sendMessage("You exchange 100 agility arena tickets for 28,000 agility experience.");
    				}
    				else {
    					player.getActionSender().sendMessage("You don't have enough agility arena tickets.");
    				}
    				break;
    			case 98: //one thousand tickets for experience
    				if(player.getInventory().contains(2996, 1000)) {
    					player.getSkills().addXp(Skills.AGILITY, 320000);
    					player.getInventory().deleteItem(2996, 1000);
    					player.getActionSender().sendMessage("You exchange 1000 agility arena tickets for 320,000 agility experience.");
    				}
    				else {
    					player.getActionSender().sendMessage("You don't have enough agility arena tickets.");
    				}
    				break;
    			case 89: //toadflax
    				if(player.getInventory().contains(2996, 3)) {
    					player.getInventory().deleteItem(2996, 3);
    					player.getInventory().addItem(2998, 1);
    					player.getActionSender().sendMessage("You exchange 3 agility arena tickets for a Toadflax.");
    				}
    				else {
    					player.getActionSender().sendMessage("You don't have enough agility arena tickets.");
    				}
    				break;
    			case 99: //snapdragon
    				if(player.getInventory().contains(2996, 10)) {
    					player.getInventory().deleteItem(2996, 10);
    					player.getInventory().addItem(3000, 1);
    					player.getActionSender().sendMessage("You exchange 10 agility arena tickets for a Snapdragon.");
    				}
    				else {
    					player.getActionSender().sendMessage("You don't have enough agility arena tickets.");
    				}
    				break;
    			case 88: //pirate's hook
    				if(player.getInventory().contains(2996, 800)) {
    					player.getInventory().deleteItem(2996, 800);
    					player.getInventory().addItem(2997, 1);
    					player.getActionSender().sendMessage("You exchange 800 agility arena tickets for a Pirate's hook.");
    				}
    				else {
    					player.getActionSender().sendMessage("You don't have enough agility arena tickets.");
    				}
    				break;
    			}
    			break;
    I was looking to maybe load it from another class ?
    Reply With Quote  
     

  2. #2  
    Community Veteran

    mige5's Avatar
    Join Date
    Aug 2008
    Posts
    5,528
    Thanks given
    573
    Thanks received
    1,410
    Rep Power
    2114
    Dont know would it be any better, but I guess it would be a lot smaller if u made it with arrays, as they are pretty much copies of each other...
    Number of page #1 releases with most views & posts: (Updated: 2023)
    RS2 server section: 1
    RS2 client section: 2
    Reply With Quote  
     

  3. #3  
    Chemist

    Advocatus's Avatar
    Join Date
    Dec 2009
    Posts
    2,622
    Thanks given
    201
    Thanks received
    813
    Rep Power
    1462
    Quote Originally Posted by mige5 View Post
    Dont know would it be any better, but I guess it would be a lot smaller if u made it with arrays, as they are pretty much copies of each other...
    This.

    if you look at your code, you have a few things that can be easily put into an array.

    The ticket amount needed.
    The button Id.

    You also have
    The experience reward (in Agility)
    The item id of the item reward.

    Personally, if i was doing this, I would do an int array with

    { button id, ticket cost, data },

    if the button id is 93 -> 98 I would add experience, otherwise I would add an item (with the item id being 'data' and the amount being one)
    Quote Originally Posted by blakeman8192 View Post
    Quitting is the only true failure.
    Reply With Quote  
     

  4. #4  
    Registered Member

    Join Date
    Jun 2007
    Age
    29
    Posts
    3,003
    Thanks given
    52
    Thanks received
    98
    Rep Power
    3208
    thank you i did just make

    Code:
    public void agilityArenaExperienceRewards(Player player, int amountofTickets, int amountofExperienceAdded) {
    		if(player.getInventory().contains(2996, amountofTickets)) {
    			player.getInventory().deleteItem(2996, amountofTickets);
    			player.getSkills().addXp(Skills.AGILITY, amountofExperienceAdded);
    		}
    		else {
    			player.getActionSender().sendMessage("You don't have enough agility arena tickets.");
    		}
    	}
    quickly but thought arrays would be so much better so i made an array for what you said

    Code:
    	int agilityArenaAwards[][] = { 
    			//buttonid, amount of tickets, data(the item or experience being given)
    			{93, 1, 240}, 
    			{95, 10, 2480}, 
    			{96, 25, 6500},
    			{97, 100, 28000}, 
    			{98, 1000, 320000},
    			
    			{89, 3, 2998},
    			{99, 10, 3000}, 
    			{88, 800, 2997}
    	};
    How would I make it so it would check the button id thats being pressed so that it can give the person the right data?
    Reply With Quote  
     

  5. #5  
    PokeNation! Xaves's Avatar
    Join Date
    Dec 2007
    Age
    32
    Posts
    3,476
    Thanks given
    356
    Thanks received
    788
    Rep Power
    646
    Code:
    if(player.getInventory().contains(2996, 10)) {
    					player.getInventory().deleteItem(2996, 10);
    					player.getInventory().addItem(3000, 1);
    					player.getActionSender().sendMessage("You exchange 10 agility arena tickets for a Snapdragon.");
    				}
    				else {
    					player.getActionSender().sendMessage("You don't have enough agility arena tickets.");
    				}

    youa re always repeating this code, make a method with this inside and call it instead.
    Reply With Quote  
     

  6. #6  
    Registered Member

    Join Date
    Jun 2007
    Age
    29
    Posts
    3,003
    Thanks given
    52
    Thanks received
    98
    Rep Power
    3208
    Code:
    			case 93: //one ticket for experience
    				agilityArenaExperienceRewards(player, 1, 240);
    				break;
    Thats what i done with the method above
    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. Simpler add starter
    By Zuyi in forum Snippets
    Replies: 4
    Last Post: 09-12-2011, 10:19 PM
  2. Simpler Findcachedir
    By Mister Maggot in forum Snippets
    Replies: 5
    Last Post: 08-14-2010, 04:25 AM
  3. Simpler Saving
    By Mister Maggot in forum Snippets
    Replies: 12
    Last Post: 07-03-2010, 05:47 AM
  4. Simpler headIcons
    By mige5 in forum Snippets
    Replies: 4
    Last Post: 04-09-2010, 02:01 AM
  5. Simpler Scrollbars
    By Stewie in forum Snippets
    Replies: 17
    Last Post: 08-03-2009, 04:15 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
  •