1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Solved Chance when pvping

Discussion in 'Development' started by iCirgio, Jan 10, 2018.

  1. iCirgio

    iCirgio Slime

    Messages:
    92
    GitHub:
    lolnova
    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(1100);
       switch(
    $chance) {

              case 
    15:

      
    $event->getEntity()->setHealth($event->getEntity()->getHealth() - 1);
    work
     
  2. rektpixel

    rektpixel Baby Zombie

    Messages:
    186
    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 :D
     
    Last edited: Jan 10, 2018
  3. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    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.
     
    HyGlobalHD likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.