Need some code

Discussion in 'Plugin Development' started by jeussa, Jun 3, 2013.

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

    jeussa

    Hey there. I have been trying to create a randomly generated event for ages, but can't figure out how it works. That's why I'd like to ask you if you do know how. And if yes, please leave a reply telling me how.

    Let me explain the problem:

    I need two randomly generated events. The first one: if you use a magmacream on the ground, you can get several items. Item 1 has for example a chance of 100% on appearing in your inventory. And item 2 has 50%.
    The second randomly chosen event is when a player places a block. There should be about 5% chance for the player to get a certain amount of items.

    Thanks for reading, hope I can finish my plugin now :)
     
  2. Offline

    chasechocolate

    1. If you mean "interact" instead of "use" then use PlayerInteractEvent.
    2. Use BlockPlaceEvent.
    For getting a percentage of happening, I think it would look something like this:
    Code:java
    1. Random random = new Random();
    2. int chance = 5;
    3. int percentage = random.nextInt(99) + 1; //From 1 - 100
    4. if(chance < percentage){
    5. //Do something
    6. }
     
    jeussa likes this.
Thread Status:
Not open for further replies.

Share This Page