Making players bleed

Discussion in 'Plugin Development' started by Vinsanity, Oct 28, 2012.

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

    Vinsanity

    I would like to make it so when a player is hit, he has a 50 percent change of bleeding. The bleeding would give the player 1 damage every 20 ticks. How would I go about doing this?

    This is my *failed* attempt

    Code:
        @EventHandler (priority= EventPriority.NORMAL)
       
        public void onEntityDamageEvent(final EntityDamageEvent e) {
     
            if (plugin.getConfig().getBoolean("bleeding.enabled")) {
                if (e.getCause() == DamageCause.ENTITY_ATTACK) {
                    double c = random.nextDouble();
                    c = random.nextDouble();
                    c = random.nextDouble();
                    if (c  <= ((plugin.getConfig().getDouble("bleeding.chance"))/100)) {
                        this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin, new Runnable() {
                            public void run() {
                                p.damage(1);
                            }
                        }, 20L);
     
                    }
                }
            }
     
  2. Offline

    Codex Arcanum

    Why are you generating a random number 3 times? This looks like it should work, you should do testing by printing a message whenever it fails one of the if statements.
     
  3. Offline

    Kazzababe

    Make bleeding.chance a number 0-100 and remove the /100.
    Then in nextDouble() put the number 100 in between parentheses.
     
  4. Offline

    MYCRAFTisbest

    Are you given an error in the log?

    Maybe you are just really lucky and you always got the 50% chance of not bleeding.
     
    GRPGamer likes this.
Thread Status:
Not open for further replies.

Share This Page