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...
|
Is there a cleaner/simpler way of doing things like this with action buttons?
I was looking to maybe load it from another class ?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;
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)
thank you i did just make
quickly but thought arrays would be so much better so i made an array for what you saidCode: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."); } }
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?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} };
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.
Thats what i done with the method aboveCode:case 93: //one ticket for experience agilityArenaExperienceRewards(player, 1, 240); break;
« Previous Thread | Next Thread » |
Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |