Make a reward system?

Discussion in 'Plugin Development' started by spurkle, Aug 11, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    spurkle

    Hi. I am making a plugin that will give player a reward if he meets some conditions.

    I want to make a config with rewards & percentage chance of getting it, but i can't figure out how i would make it.
    E.g:
    Config file:
    32 Diamonds: 30%
    64 Diamonds: 5%
    16 Diamonds: 10%

    So, if player gets a reward it should not be nothing and it should be calculated by %.


    Sorry for my poor explaining, lol
    And thanks for reading.
     
  2. Offline

    JoeyDevs

    What do you have tried to do?
    Maybe give more of you own work now it likes we need to code the plugin for you.
     
  3. Offline

    spurkle

    I am not asking for a code, i am wanting a way of doing it.

    And i can not even figure out how a system like this could work. I am not very good with math, so yeah.
     
  4. Offline

    Prothean_IGS

    Explain more on exactly what some of these conditions are. For example, if you wanted to reward a player for say, having 32 diamonds in their inventory at one time, you would just need to do various checks to see if they actually meet the requirements, and if so, then get the percentage of chance to get the reward, that is saved in the config, and go from there.

    Without any of your own code, or a little more explanation, there isn't much we can do for you.
     
  5. Offline

    spurkle

    I need some kind of a formula that will give the player reward depending on chance of receiving it.
    I can check the conditions, etc. I just can not figure out how to give the player an item depending on chance of receiving a diamonds reward for example.

    Like how can i get the item that player should receive?

    -> that is saved in the config, and go from there.
     
  6. Offline

    Skionz

    spurkle generate a random number between 0 and 99 with this
    Code:
    Random r = new Random()
    int randomNumber = r.nextInt(100);
    if(randomNumber <= 5) {
      //give 64 diamonds
    }
    else if(randomNumber <= 35 && randomNumber >= 5) {
      //give 32 diamonds
    }
    correct me if im wrong but this generates a random number between 0 and 99, not 0 to 100
    Code:
    r.nextInt(100);
     
  7. Offline

    artish1

    spurkle

    Code:
    public boolean canReward(int chance){
            Random r = new Random();
            int rNum = r.nextInt(100) + 1;
            return rNum < chance;
        }
     
     
    if(canReward(10)){//If 10% chance gone by and passed
    //reward player...
    reward(player);
    }
    
     
  8. Offline

    kurtv

    spurkle
    1. you have to take the % and divide it by 100, we will call it dividedBy
    2. then you have to generate a random number that returns an Integer between 0 and dividedBy, and we will call it finalNumber
    3. then if(dividedBy == finalNumber) you give the reward
    thats how i would do it
    :D

    Skionz
    yes thats why you have to put +1

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  9. Offline

    Skionz

    kurtv Wow I can't believe I never though of that
     
  10. Offline

    kurtv

    Skionz lol im good at maths xD
     
  11. Offline

    spurkle

    That's exactly what i wanted! Thanks!

    Now ill just loop until player gets his reward, so it wont happen that he will get nothing.
     
Thread Status:
Not open for further replies.

Share This Page