Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Solved Help Anyone

Comments in 'Plugin Development' started by TryoneLegendZzz, Aug 14, 2015.

  1. TryoneLegendZzz
    Offline

    TryoneLegendZzz Active Member

    Joined:
    May 31, 2015
    Posts:
    201
    Minecraft User:
    SavionLegendZzz
    ok so i am trying to give $killer a arrow when when they kill a player using a bow but the thing is i set the CAUSE_PROJECTILE to make it be one hit kill how can i do this while still using the one hit kill method?
    thebigsmileXD likes this.
  2. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    I also try to make one hit kill bows for OneInTheChamber, if you have any code please post it, then i can have a look at this
  3. TryoneLegendZzz
    Offline

    TryoneLegendZzz Active Member

    Joined:
    May 31, 2015
    Posts:
    201
    Minecraft User:
    SavionLegendZzz
    PHP:
    public function onHitByArrow(EntityDamageEvent $event){
         if(
    $this->gameStatus===0){
         if(
    $event->getCause() === 2){
         
    $event->getEntity()->setHealth(20);
            }
             }else{
         if(
    $this->gameStatus===3){
         if(
    $event->getCause() === 2){
         
    $event->getEntity()->setHealth(0);
            }
            }
            }
            if(
    $this->gameStatus===1){
            if(
    $event->getCause() === 2){
         
    $event->getEntity()->setHealth(20);
            }
            }
            }
           
    i need a new method because it i need to give a arrow to the person who shot the bow :/
    thebigsmileXD likes this.
  4. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    This looks good, but i think setHealth wouldn't kill a player..
    Give me a minute, i'll have a look over it and check it.

    (by the way.. what do you want to create? xD it really sounds like OITC ^^)
  5. TryoneLegendZzz
    Offline

    TryoneLegendZzz Active Member

    Joined:
    May 31, 2015
    Posts:
    201
    Minecraft User:
    SavionLegendZzz
    its kills them as if they did /kill
    Thunder33345 and thebigsmileXD like this.
  6. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    Take a look at my code for this ;P
    PHP:
    public function onDamage(EntityDamageEvent $event){
        if(
    $event instanceof EntityDamageByChildEntityEvent) {
                if(
    $event->getChild() instanceof Arrow) {
                    
    $victim $event->getEntity();
                    if(
    $event->getEntity()->getLastDamageCause() instanceof EntityDamageByEntityEvent and $victim->isSurvival() or $victim->isAdventure()) {
                        
    $killer $event->getEntity()->getLastDamageCause()->getDamager();
                        if(
    $killer instanceof Player and $victim instanceof Player) {
                            
    $this->kill($this->victim);
                            
    $this->giveItems($this->killer);
                            
    $this->resetHealth($this->killer);
                        }
                    }
                }
            }
        }

    public function 
    giveItems(Player $player) {
            
    $inv $player->getInventory();
            if(
    $inv instanceof PlayerInventory) {
                
    $inv->clearAll();
                
    $inv->addItem(Item::get(272), Item::get(261), Item::get(262), Item::get(378));
            }
        }

    public function 
    resetHealth(Player $player) {
            
    $player->setMaxHealth(20);
            
    $player->setHealth($player->getMaxHealth());
        }

    public function 
    kill(Player $player) {
            
    $player->setHealth(0);
        }
    I put all this in a 2 tick delayed task to give the damager time to update, I'm pretty sure it doesn't need to be in the task but if you get any crashes then you might have to.
  7. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    This looks really nice, thank you
  8. TryoneLegendZzz
    Offline

    TryoneLegendZzz Active Member

    Joined:
    May 31, 2015
    Posts:
    201
    Minecraft User:
    SavionLegendZzz
    nvm i found a different and better way (my opinion) thx for the help :)

Share This Page

Advertisement