|
hi guys, ive had a loong break from RSPS's. and decided to come back.
ive been messing around with this for 30 mins or so but cnt find the solution.
im trying to make it so that when u thieve there is a "chance" to get a special item.
right now its on 50% but it should be 5 its just higher so i can make sure it works.
im pretty sure u can see what i want to do when u see the code. so here it is
Code:public static int ChestRewards[] = {1039, 995}; public static int ChestRewardsA[] = {1, 1000000}; public static int randomChestRewards() { return ChestRewards[(int)(Math.random()*ChestRewards.length)]; } public static int randomChestAmount(){ return ChestRewardsA[(int)(Math.random()*ChestRewards.length)]; }so the problem is that sometimes i get the special item. but the amount is just f'ed up.Code:public void stealFromStall(int lev, int loot, int amount, int exp, String name) { int chance = 0; int rare = 0; if(playerLevel[17] >= lev) { chance = 3 + (playerLevel[17] - lev); if(actionTimer == 0) { if(misc.random(chance) >= 3) { rare = misc.random(99)+1; addSkillXP(exp, 17); sendMessage("You Steal from the "+name); addItem(loot, amount); actionTimer = 5; startAnimation(881); updateRequired = true; appearanceUpdateRequired = true; if (rare <= 50){ addItem(randomChestRewards(), randomChestAmount()); sendMessage("@red@You got lucky there and got a special item"); rare = 100; } } else { sendMessage("You fail to Steal from the "+name); stunDelay = 10; actionTimer = 10; stillgfx(80, absY, absX); startAnimation(881); updateRequired = true; appearanceUpdateRequired = true; } } } else if(playerLevel[17] < lev) { sendMessage("You need a thieving level of "+lev+" to Steal from the: "+name); } }
sometimes i get 1m red phats and sometimes i get 1 gp.
its supposed to give me 1 red phat and 1m cash only
so guys please help me
the problem is that you're calling the Array's slots seperately. do it this way:
Code:/*handles item and amount at the same time. Format: {Item, Amount}, {Item,Amount} ..... */ public static int[][] ChestRewards = {{1039, 1}, {995, 1000000}}; public static int[] randomChestRewards() { return ChestRewards[(int)(Math.random()*ChestRewards.length)]; //Now returns an Array containing the item and amount at the same time }
then just adjust the following code
Code:public void stealFromStall(int lev, int loot, int amount, int exp, String name) { int chance = 0; int rare = 0; if(playerLevel[17] >= lev) { chance = 3 + (playerLevel[17] - lev); if(actionTimer == 0) { if(misc.random(chance) >= 3) { rare = misc.random(99)+1; addSkillXP(exp, 17); sendMessage("You Steal from the "+name); addItem(loot, amount); actionTimer = 5; startAnimation(881); updateRequired = true; appearanceUpdateRequired = true; if (rare <= 50){ int[] tmpItem = randomChestRewards(); //call for the Array containing item and amt addItem(tmpItem[0], tmpItem[1]); //splits the array into two ints sendMessage("@red@You got lucky there and got a special item"); rare = 100; } } else { sendMessage("You fail to Steal from the "+name); stunDelay = 10; actionTimer = 10; stillgfx(80, absY, absX); startAnimation(881); updateRequired = true; appearanceUpdateRequired = true; } } } else if(playerLevel[17] < lev) { sendMessage("You need a thieving level of "+lev+" to Steal from the: "+name); } }
Code:public static int randomChestRewards(int i) { return ChestRewards[i]; } public static int randomChestAmount(int i){ return ChestRewardsA[i]; }Though wondering why u making int arrays like that, when it would be much simpler to store them as items..Code:int loot = Math.random()*ChestRewards.length; addItem(randomChestRewards(loot), randomChestAmount(loot));
Code:public static Item[] ChestRewards = {new Item(995, 1000000), new Item(1038, 1)};
« Previous Thread | Next Thread » |
Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |