I need help making a chance feature So when u hit players you get a chance to earn +1 health I tried didn't PHP: $chance = mt_rand(1, 100); switch($chance) { case 15: $event->getEntity()->setHealth($event->getEntity()->getHealth() - 1); work
PHP: public function onEntityDamage(EntityDamageEvent $ev) { $damager = $ev->getDamager(); $chance = mt_rand(1,2); switch($chance){ case 1: $damager->setHealth($damager->getHealth() + 1); break; case 2: $damager->sendMessage(""); this is a 50/50 tho. you could just add more cases which are sendMessage to decrease the chance of +1 health. This is the wrong way to do things but it would still work
Whatever case you use, it is still 1% because each number only has one percent chance. You want to test $chance <= 15 rather than $chance === 15.