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

KnockBack for PitchOut

Discussion in 'Development' started by Bluzzi, Nov 24, 2016.

  1. Bluzzi

    Bluzzi Spider Jockey

    Messages:
    46
    Hello, I would like to do something like a Pitchout game, but I don't know how to set the knockback:
    PHP:
    public function onDamage(EntityDamageEvent $ev) {
            
    $damaged $ev->getEntity();
            if(
    $ev instanceof EntityDamageByEntityEvent){
                
    $player $ev->getDamager();
                
    $entity $ev->getEntity();
                
    $level $player->getLevel();
                if(
    $entity instanceof Player && $player instanceof Player){
                    if(
    $ev->getEntity()->getLevel()->getName() == "pitchout") {
                        if(
    $player->getInventory()->getItemInHand()->getId() == 269){
                            
    $ev->setDamage(0);
                            
    $ev->setKnockBack(0);
                        }
                    }
                }
            }
        }
    By using this, the player is sending in the air
    How to do to don't get send in the air ?
    Thanks :D
     
  2. Reid

    Reid Spider Jockey

    Messages:
    43
    Wait so you want no knockBack or you want it where nobody can hit eachother at all?
     
    Bluzzi likes this.
  3. TxnnerOS

    TxnnerOS Creeper

    Messages:
    3
    Why not just cancel the event if you don't want the player to be damaged or knocked back?
    PHP:
    public function onDamage(EntityDamageEvent $ev) {
            
    $damaged $ev->getEntity();
            if(
    $ev instanceof EntityDamageByEntityEvent) {
                
    $player $ev->getDamager();
                
    $entity $ev->getEntity();
                
    $level $player->getLevel();
                if(
    $entity instanceof Player && $player instanceof Player){
                    if(
    $ev->getEntity()->getLevel()->getName() == "pitchout") {
                        if(
    $player->getInventory()->getItemInHand()->getId() == 269){
                            
    $ev->setCancelled(true);
                        }
                    }
                }
            }
        }
     
    Last edited: Nov 25, 2016
    Bluzzi likes this.
  4. Reid

    Reid Spider Jockey

    Messages:
    43
    May thoughts exactly and then if he still wants to damage the player just use like $entity->setHealth($entity->getHealth - 1);
     
    Bluzzi and TxnnerOS like this.
  5. Bluzzi

    Bluzzi Spider Jockey

    Messages:
    46
    Do you know PushMe game?
    I want to the player get knockback just on x or on z, not on y, i don't know if you understand me
     
    TxnnerOS likes this.
  6. tuff

    tuff Creeper

    Messages:
    2
    GitHub:
    tuffdev
    I see what you're saying, you want to throw them out of the arena when they get hit by a wood shovel. My advice would be to teleport them out.
     
    Bluzzi and TxnnerOS like this.
  7. TxnnerOS

    TxnnerOS Creeper

    Messages:
    3
    Hmm, the only thing I can think of is to set the player's motion.
    PHP:
    public function onDamage(EntityDamageEvent $ev) {
            
    $damaged $ev->getEntity();
            if(
    $ev instanceof EntityDamageByEntityEvent) {
                
    $player $ev->getDamager();
                
    $entity $ev->getEntity();
                
    $level $player->getLevel();
                if(
    $entity instanceof Player && $player instanceof Player){
                    if(
    $ev->getEntity()->getLevel()->getName() == "pitchout") {
                        if(
    $player->getInventory()->getItemInHand()->getId() == 269){
                            
    $player->setMotion(new Vector3($player->motionX 2$player->motionY 0$player->motionZ 2));
                        }
                    }
                }
            }
        }
    Make sure you include this as well:
    PHP:
    use pocketmine\math\Vector3;
     
    Bluzzi and Reid like this.
  8. tuff

    tuff Creeper

    Messages:
    2
    GitHub:
    tuffdev
    That's probably better since it makes the game feel more realistic, instead of having the player teleported out. I think the next step would be to somehow send the player that was hit off in the direction that they were hit instead of moving them two blocks over.
     
    Bluzzi and TxnnerOS like this.
  9. Reid

    Reid Spider Jockey

    Messages:
    43
    dont forget to cancel the event too if you don't want the players to be damaged or have the normal knockBack
     
    Bluzzi, TxnnerOS and tuff like this.
  10. Bluzzi

    Bluzzi Spider Jockey

    Messages:
    46
    Hum.. this code is fonctionnal but your code is fonctionnal only that in one sense can you help me for use this code for it to be all the senses ??
     
  11. TutoGamerWalid

    TutoGamerWalid Spider Ban Evader

    Messages:
    11
    GitHub:
    wiligangster
    for you'r pitchOut i recommanded you to use in PlayerDeathEvent
    $player->teleportImmediate(Vector3 $pos, $yaw, $pitch);
     
    Bluzzi likes this.
  12. Bluzzi

    Bluzzi Spider Jockey

    Messages:
    46
    Oui mais je met quoi ?
    $pos = ?
    $yaw = ?
    $pitch = ?
     
  13. TutoGamerWalid

    TutoGamerWalid Spider Ban Evader

    Messages:
    11
    GitHub:
    wiligangster
    $pos = $x, $y, $z
    $yaw = $player->getYaw();
    $pitch = $player->getPitch();
     
    Bluzzi likes this.
  14. Bluzzi

    Bluzzi Spider Jockey

    Messages:
    46
    Je comprend pas... :c tu m'a pas assez appris..
     
  15. TutoGamerWalid

    TutoGamerWalid Spider Ban Evader

    Messages:
    11
    GitHub:
    wiligangster
    $player->teleportImmediate(new Vector3($x,$y,$z,$player->getYaw(),$player->getPitch()));
     
    Bluzzi likes this.
  16. Bluzzi

    Bluzzi Spider Jockey

    Messages:
    46
    Mais
    Comment set le recul du KnockBack ?
     
  17. TutoGamerWalid

    TutoGamerWalid Spider Ban Evader

    Messages:
    11
    GitHub:
    wiligangster
    No it's for the PlayerDeathEvent... please dm me i solve you'r problem
     
    Bluzzi likes this.
  18. TutoGamerWalid

    TutoGamerWalid Spider Ban Evader

    Messages:
    11
    GitHub:
    wiligangster
    $from = $event->getFrom();
    $to = $event->getTo();
    $entity->setMotion((new Vector3($to->x - $from->x, $to->y - $from->y, $to->z - $from->z))->multiply(5));
     
    Bluzzi 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.