Thread: quite basic stuff i forgot and now need help with (int array)?

Results 1 to 6 of 6
  1. #1 quite basic stuff i forgot and now need help with (int array)? 
    Registered Member
    Join Date
    Mar 2009
    Posts
    14
    Thanks given
    0
    Thanks received
    1
    Rep Power
    1
    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)];
    }
    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("@[email protected] 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);
    }
    }
    so the problem is that sometimes i get the special item. but the amount is just f'ed up.
    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
    Reply With Quote  
     

  2. #2  
    Android/Java/Meteor/Node
    Orbyt's Avatar
    Join Date
    Oct 2013
    Posts
    335
    Thanks given
    25
    Thanks received
    21
    Rep Power
    11
    Quote Originally Posted by julie View Post
    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)];
    }
    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("@[email protected] 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);
    }
    }
    so the problem is that sometimes i get the special item. but the amount is just f'ed up.
    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
    Looks like here :
    Code:
     
    public static int randomChestAmount(){
    return ChestRewardsA[(int)(Math.random()*ChestRewards.length)];
    }
    your randomizing the amount given.
    Reply With Quote  
     

  3. #3  
    Registered Member
    Join Date
    Mar 2009
    Posts
    14
    Thanks given
    0
    Thanks received
    1
    Rep Power
    1
    Quote Originally Posted by Charles View Post
    Looks like here :
    Code:
     
    public static int randomChestAmount(){
    return ChestRewardsA[(int)(Math.random()*ChestRewards.length)];
    }
    your randomizing the amount given.
    so the
    Code:
    public static int randomChestAmount(){
    return ChestRewardsA[(int)(Math.random()*ChestRewards.length)]
    Has to be ? im so confused right now lol
    Reply With Quote  
     

  4. #4  
    Registered Member
    Join Date
    Jun 2014
    Posts
    58
    Thanks given
    2
    Thanks received
    4
    Rep Power
    11
    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("@[email protected] 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);
    }
    }
    Reply With Quote  
     

  5. Thankful user:


  6. #5  
    Community Veteran

    mige5's Avatar
    Join Date
    Aug 2008
    Posts
    5,358
    Thanks given
    557
    Thanks received
    1,181
    Discord
    View profile
    Rep Power
    1862
    Code:
    	public static int randomChestRewards(int i) {
    		return ChestRewards[i];
    	}
    public static int randomChestAmount(int i){
     return ChestRewardsA[i];
    }
    Code:
    int loot = Math.random()*ChestRewards.length;
    addItem(randomChestRewards(loot), randomChestAmount(loot));
    Though wondering why u making int arrays like that, when it would be much simpler to store them as items..
    Code:
    public static Item[] ChestRewards = {new Item(995, 1000000), new Item(1038, 1)};
    ...
    Reply With Quote  
     

  7. Thankful user:


  8. #6  
    Registered Member
    Join Date
    Jun 2014
    Posts
    58
    Thanks given
    2
    Thanks received
    4
    Rep Power
    11
    Quote Originally Posted by mige5 View Post
    Code:
    	public static int randomChestRewards(int i) {
    		return ChestRewards[i];
    	}
    public static int randomChestAmount(int i){
     return ChestRewardsA[i];
    }
    Code:
    int loot = Math.random()*ChestRewards.length;
    addItem(randomChestRewards(loot), randomChestAmount(loot));
    Though wondering why u making int arrays like that, when it would be much simpler to store them as items..
    Code:
    public static Item[] ChestRewards = {new Item(995, 1000000), new Item(1038, 1)};
    true, I didn't know that was possible as I'm new to coding PI
    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. Need help with ints.
    By a box in forum Help
    Replies: 0
    Last Post: 12-11-2010, 12:35 AM
  2. Replies: 3
    Last Post: 08-15-2010, 09:35 PM
  3. My Godsword, need help with Int.
    By Magepro in forum Help
    Replies: 8
    Last Post: 10-18-2009, 11:14 PM
  4. Replies: 0
    Last Post: 08-14-2009, 09:15 AM
  5. [508] Need help with an array list, will rep+
    By EndlessZombies in forum Help
    Replies: 5
    Last Post: 04-22-2009, 03:08 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
  •