|
|
Hey guys,
It been a while since iv'e contributed towards anything, so i decided to do this simple snippet. I know this is easy to do and has been done before all i'm doing is making a better one, so please try not to flame.
Code:package server.model.players; import server.model.players.Client; import server.event.EventManager; import server.event.Event; import server.event.EventContainer; import server.util.Misc; /* * Author - Ferocious * From Rune-server */ public class MysteryBox { public static boolean Canusebox = true; public static int Common [] = {1323, 1313, 1315, 1321, 1109}; // Add more item Id's public static int Uncommon [] = {10828, 4587, 4586, 9185}; // Add more item Id's public static int Rare [] = {4151, 14484, 11700, 11694, 11696, 11698}; // Add more item Id's public static int GenerateMyrsteryPrize(final Client c) { EventManager.getSingleton().addEvent(new Event() { int BoxTimer = 2; int Coins = 50000 + Misc.random(25000); public void execute(EventContainer Box) { Canusebox = false; if (BoxTimer == 2) { c.sendMessage("Calculating prize..."); } if (BoxTimer == 0) { c.getItems().addItem(995, Coins); int Random = Misc.random(100); if (Random <= 64) { c.getItems().addItem(Common[(int) (Math.random() * Common.length)], 1); c.sendMessage("You have recieved a @[email protected] @[email protected] and @[email protected]"+ Coins +" @[email protected]"); } else if (Random >= 65 && Random <= 89) { c.getItems().addItem(Uncommon[(int) (Math.random() * Uncommon.length)], 1); c.sendMessage("You have recieved an @[email protected] @[email protected] and @[email protected]"+ Coins +" @[email protected]"); } else if (Random >= 90 && Random <= 100) { c.getItems().addItem(Rare[(int) (Math.random() * Rare.length)], 1); c.sendMessage("You have recieved a @[email protected] @[email protected] and @[email protected]"+ Coins +" @[email protected]"); } } if (c == null || BoxTimer <= 0) { Box.stop(); Canusebox = true; return; } if (BoxTimer >= 0) { BoxTimer--; } } }, 1000); return Common[(int) (Math.random() * Common.length)]; } public static void OpenMysteryBox(int itemID, Client c) { if (itemID == 6199) { if (c.getItems().freeSlots() > 1) { if (Canusebox == true) { c.getItems().deleteItem(6199, 1); GenerateMyrsteryPrize(c); } else { c.sendMessage("Please wait while your current process is finished."); } } else { c.sendMessage("You need atleast 2 slots to open the Mystery box."); } } } }
Enjoy.
Easy but effective![]()
Thanks for this. Good job
thanks guys![]()
Wewt

That has nothing to do with common, uncommon or rare, it just generate a random number and if the number is > or < a certain number you receive the specific amount of coins. Also the event is completely useless.



Or you can simply make dis in the clickitem.java
No need for a whole class for a simple thing..
Code:if(itemId == 6199) { int Common [] = {1323, 1313, 1315, 1321, 1109,181,3026,3022,3021,4153,1261,1079,1093,1113,1127,1147,1156,1173,1117,39,589,552,3011617,526,113,6199,1779,1712,1231,6729,3125,8844,8845,1442,1289,1303,555,554,556,560,1023,4317,491,561,54,542440,1623,52,892,373,371,1277,2309,2311,149,157,163,167,3016,5608,2138,2144,5609,5607,}; // Add more item Id's int Uncommon [] = {10828, 4587, 4586, 9185}; // Add more item Id's int Rare [] = {4151, 6585, 4718, 4720, 4722, 4723}; // Add more item Id's int Coins = 50000 + Misc.random(75000); //Change the 75000 to any amount you want (MONEY) c.getItems().addItem(995, Coins); c.getItems().deleteItem(6199, 1); int Random = Misc.random(100); if (Random <= 764) { c.getItems().addItem(Common[(int) (Math.random() * Common.length)], 1); c.sendMessage("[<col=990000>*</col>] You have recieved a <col=2784FF>common</col> item and <col=990000>"+ Coins +"</col> coins."); c.sendMessage("[<col=990000>*</col>] Good luck next time!"); } else if (Random >= 77 && Random <= 96) { c.getItems().addItem(Uncommon[(int) (Math.random() * Uncommon.length)], 1); c.sendMessage("[<col=990000>*</col>] You have recieved an <col=2784FF>uncommon</col> item and <col=990000>"+ Coins +"</col> coins."); } else if (Random >= 97 && Random <= 100) { c.getItems().addItem(Rare[(int) (Math.random() * Rare.length)], 1); c.sendMessage("[<col=990000>*</col>] You have recieved a <col=990000>rare</col> item and <col=990000>"+ Coins +"</col> coins."); c.sendMessage("[<col=990000>*</col>] Congratulations!"); } }

| « Void Knight Deflector | [RIOT / PI] PVP levels » |
| Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |
| Tags for this Thread |