Configurable chances for events

Discussion in 'Plugin Development' started by u_mad_bros, Jun 24, 2017.

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

    u_mad_bros

    Already got the base idea down, I don't really want to share the code unless I completely have too, because once I'm done I'm gonna throw it on the website. I already got this 100% working, until I realized the percentage system I was using isn't actually accurate.
    @timtower (I know you're an amazing developer, just came to mind)
    I'll give you a snippet of what I was doing:
    Code:
    Random r = new Random();
                          int  n = r.nextInt(100) + 1;
                          if (n<= emerald) {
                              blocktobe = Material.EMERALD_ORE;
                          }
                          else if (n<= diamond) {
                              blocktobe = Material.DIAMOND_ORE;
                          }
                          else if (n<= gold) {
                              blocktobe = Material.GOLD_ORE;
                          }
                          else if (n<= iron) {
                              blocktobe = Material.IRON_ORE;
                          }
                          else if (n<= redstone) {
                              blocktobe = Material.IRON_ORE;
                          }
                          else if (n<= lapis) {
                              blocktobe = Material.LAPIS_ORE;
                          }
                          else if (n<= coal) {
                              blocktobe = Material.COAL_ORE;
                          }
                          else if (n<= stone) {
                              blocktobe = Material.STONE;
                          }
                          else {
                              blocktobe = Material.COBBLESTONE;
                          }
                          b.setType(blocktobe);
    
    This, obviously.. doesn't really work percentages. (The "emerald", "diamond" and so on are values inside of the config file)
    Is there a better method for actually calculating proper percentages off of a configuration file input?
    I can throw in the configuration right here, too.
    Code:
    emerald: 3
    diamond: 3
    gold: 15
    iron: 20
    redstone: 25
    lapis: 30
    coal: 35
    stone: 40
    
    I'm not the type you gotta spoonfeed, I just need an idea to build off. I thought this would work, but it doesn't work quite right haha
     
    Last edited: Jun 24, 2017
  2. Offline

    yPedx

  3. Offline

    u_mad_bros

    Last edited: Jun 24, 2017
Thread Status:
Not open for further replies.

Share This Page