Don't working

Discussion in 'Development' started by MrSolik123, Feb 14, 2019.

  1. MrSolik123

    MrSolik123 Spider

    Messages:
    10
    Why it might not work?


    public function onDamage(EntityDamageByEntityEvent $ev){
    $dmgr=$ev->getDamager();
    $entity=$ev->getEntity();
    if($dmgr instanceof Player && $entity instanceof Player){



    $dm = $mt_rand(1,10);
    if($dm == 1 ){
    $dmgr->sendMessage('§2Ты не попал по противнику');
    $ev->setCancelled();
    }
    if($dm == 3 ){
    $dmgr->sendMessage('§2Ты не попал по противнику');
    $ev->setCancelled();
    }
    if($dm == 4 ){
    $dmgr->sendMessage('§2Ты не попал по противнику');
    $ev->setCancelled();
    }
    if($dm == 5 ){
    $dmgr->sendMessage('§2Ты не попал по противнику');
    $ev->setCancelled();
    }
    if($dm == 2) {
    $entity->sendMessage('§2От удара по голове у тебя появлось головокружение');
    $entity->addEffect(Effect::getEffect(9)->setAmplifier(3)->setDuration(20 * 6));
    }
    if($dm == 6) {
    $entity->sendMessage('§2От удара по голове у тебя появлось головокружение');
    $entity->addEffect(Effect::getEffect(9)->setAmplifier(3)->setDuration(20 * 6));
    }
    if ($dm == 7 ){
    $entity->sendMessage('§2От удара в глаз ты начал хуже видеть');
    $entity->addEffect(Effect::getEffect(15)->setAmplifier(3)->setDuration(20 * 6));
    }
    if ($dm == 9 ){
    $entity->sendMessage('§2От удара в глаз ты начал хуже видеть');
    $entity->addEffect(Effect::getEffect(15)->setAmplifier(3)->setDuration(20 * 6));
    }
    if ($dm == 8 ){
    $entity->sendMessage('§2От сильного удара у тебя началось кровотечение');
    $entity->addEffect(Effect::getEffect(20)->setAmplifier(3)->setDuration(20 * 7));
    }
    if ($dm == 10 ){
    $entity->sendMessage('§2От сильного удара у тебя началось кровотечение');
    $entity->addEffect(Effect::getEffect(20)->setAmplifier(3)->setDuration(20 * 7));
    }
    }
    }
     
  2. KielKing

    KielKing Baby Zombie

    Messages:
    158
    GitHub:
    kielking
    syntax error
     
  3. MrSolik123

    MrSolik123 Spider

    Messages:
    10
    The debugger does not throw an error. In the game nothing happens
     
  4. Trxgically

    Trxgically Spider

    Messages:
    13
    GitHub:
    trxgically
    Try elseif after your first if.
     
  5. MrSolik123

    MrSolik123 Spider

    Messages:
    10
    dont working
     
  6. Trxgically

    Trxgically Spider

    Messages:
    13
    GitHub:
    trxgically
    Show me the code.
     
  7. MrSolik123

    MrSolik123 Spider

    Messages:
    10
    public function onDamage(EntityDamageByEntityEvent $ev){
    $dmgr=$ev->getDamager();
    $entity=$ev->getEntity();
    if($dmgr instanceof Player && $entity instanceof Player){



    $dm = $mt_rand(1,10);
    if($dm == 1 || $dm == 3 || $dm == 4 || $dm == 5); {
    $dmgr->sendMessage('§2Ты не попал по противнику');
    $ev->setCancelled();
    }

    elseif($dm == 2 || $dm == 5) {
    $entity->sendMessage('§2От удара по голове у тебя появлось головокружение');
    $entity->addEffect(Effect::getEffect(9)->setAmplifier(3)->setDuration(20 * 6));
    }

    elseif ($dm == 7 || $dm == 9 ){
    $entity->sendMessage('§2От удара в глаз ты начал хуже видеть');
    $entity->addEffect(Effect::getEffect(15)->setAmplifier(3)->setDuration(20 * 6));
    }

    elseif ($dm == 8 || $dm == 10 ){
    $entity->sendMessage('§2От сильного удара у тебя началось кровотечение');
    $entity->addEffect(Effect::getEffect(20)->setAmplifier(3)->setDuration(20 * 7));
    }

    }
     
  8. Trxgically

    Trxgically Spider

    Messages:
    13
    GitHub:
    trxgically
    Try

    public function onDamage(EntityDamageByEntityEvent $ev)
    {
    $dmgr = $ev->getDamager();
    $entity = $ev->getEntity();
    if ($dmgr instanceof Player && $entity instanceof Player) {
    $dm = $mt_rand(1, 10);
    if ($dm == 1 || $dm == 2 || $dm == 3 || $dm == 4) {
    $dmgr->sendMessage('§2Ты не попал по противнику');
    }
    elseif ($dm == 5 || $dm == 6) {
    $entity->sendMessage('§2От удара по голове у тебя появлось головокружение');
    $entity->addEffect(Effect::getEffect(9)->setAmplifier(3)->setDuration(20 * 6));
    }
    elseif ($dm == 7 || $dm == 8) {
    $entity->sendMessage('§2От удара в глаз ты начал хуже видеть');
    $entity->addEffect(Effect::getEffect(15)->setAmplifier(3)->setDuration(20 * 6));
    }
    elseif ($dm == 9 || $dm == 10) {
    $entity->sendMessage('§2От сильного удара у тебя началось кровотечение');
    $entity->addEffect(Effect::getEffect(20)->setAmplifier(3)->setDuration(20 * 7));
    }
    }
     
  9. MrSolik123

    MrSolik123 Spider

    Messages:
    10
    ok. thanks
     
  10. Trxgically

    Trxgically Spider

    Messages:
    13
    GitHub:
    trxgically
    Did it work?
     
  11. Aericio

    Aericio Slime

    Messages:
    99
    GitHub:
    aericio
    jasonwynn10 likes this.
  12. KielKing

    KielKing Baby Zombie

    Messages:
    158
    GitHub:
    kielking
    it will not add the effect and it will throw a typehint error
     
  13. Aericio

    Aericio Slime

    Messages:
    99
    GitHub:
    aericio
    mt_rand() is not a variable, it's a function (unless you made it a variable).
     
  14. KielKing

    KielKing Baby Zombie

    Messages:
    158
    GitHub:
    kielking
    here, try this:
    PHP:
    /**
    * @param EntityDamageEvent $ev
    * @priority LOWEST
    */
    public function onEntityDamage(EntityDamageEvent $ev): void{
        
    $victim $ev->getEntity();
        if(
    $ev instanceof EntityDamageByEntityEvent){
            
    $damager $ev->getDamager();
            if(
    $victim instanceof Player && $damager instanceof Player){
                
    $effects = [
                    new 
    EffectInstance(Effect::getEffect(Effect::CONFUSION), 20 63),
                    new 
    EffectInstance(Effect::getEffect(Effect::BLINDNESS), 20 63),
                    new 
    EffectInstance(Effect::getEffect(Effect::WITHER), 20 63)
                ];
                if(
    mt_rand(110) > 4){
                    
    $victim->addEffect($effects[array_rand($effects)]);
                }
            }
        }
    }
     
    jojoe77777 likes this.
  15. MrSolik123

    MrSolik123 Spider

    Messages:
    10
    dont working
     
  16. KielKing

    KielKing Baby Zombie

    Messages:
    158
    GitHub:
    kielking
    register the event
     
  17. MrSolik123

    MrSolik123 Spider

    Messages:
    10
    all events are registered, but the system does not work
     
  18. KielKing

    KielKing Baby Zombie

    Messages:
    158
    GitHub:
    kielking
    did another player hit you?
     
    MrSolik123 likes this.
  19. MrSolik123

    MrSolik123 Spider

    Messages:
    10
    Yes, but effects dont addind
     
  20. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin Noobiest member in the PMMP Team

    Messages:
    1,796
    GitHub:
    sof3
    Tip: you no longer need to check $event instanceof EntityDamageByEntityEvent. You could directly put EntityDamageByEntityEvent in the parameter type.
    (It has actually been fixed for ages)
     
    HimbeersaftLP likes this.

Share This Page

  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.