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

Wither Effect on an Item

Comments in 'Plugin Development' started by SM11, Aug 11, 2015.

  1. SM11
    Offline

    SM11 Active Member

    Joined:
    Jun 21, 2015
    Posts:
    117
    Minecraft User:
    SM11
    Is it possible to make a Item have a Withereffect, so when I hit someone with the Item they are effected?
  2. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    EntityDamageEvent, check if hit is by a player, get the item in hand, check the item, if it's the item, give effect
  3. XEmAX32
    Offline

    XEmAX32 Active Member

    Joined:
    Feb 1, 2015
    Posts:
    80
    Minecraft User:
    XEmAX32
    yes its possible:
    public function OnDamage(PlayerDamageEvent $e){
    $player->getInventory()->getItemInHand()->getId() == Item::IRON_SWORD{
    $player->addEffect (here i don't remember how to do for the effect event :p)
  4. Gamecrafter
    Offline

    Gamecrafter Notable Member Plugin Developer

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Learn PHP.
    PEMapModder and CraftYourBukkit like this.
  5. XEmAX32
    Offline

    XEmAX32 Active Member

    Joined:
    Feb 1, 2015
    Posts:
    80
    Minecraft User:
    XEmAX32
    I'm learning it ....
  6. Gamecrafter
    Offline

    Gamecrafter Notable Member Plugin Developer

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    If you're learning it as of now, then please don't help other people. You are misleading them, therefore doing more harm than help.
    CraftYourBukkit likes this.
  7. XEmAX32
    Offline

    XEmAX32 Active Member

    Joined:
    Feb 1, 2015
    Posts:
    80
    Minecraft User:
    XEmAX32
    ok but the problem isn't php but pocketmine api because i don't know how to use the effect event if i have made other mistakes please tell me
  8. Gamecrafter
    Offline

    Gamecrafter Notable Member Plugin Developer

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    You sure you want me to tell you every mistake you've made?
  9. XEmAX32
    Offline

    XEmAX32 Active Member

    Joined:
    Feb 1, 2015
    Posts:
    80
    Minecraft User:
    XEmAX32
    yes
    because if you tell me all mistakes what i have made i can improve
    if you think i didn't putted the <?php, namespace and uses is because i have made it for the function not for other
  10. Gamecrafter
    Offline

    Gamecrafter Notable Member Plugin Developer

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Okay. Here's a list of mistakes, so please take a good look at PHP and the PocketMine-API:
    1. There is no PlayerDamageEvent. There is only EntityDamageEvent.
    2. What is $player? That's an undefined variable. You should've added a $player = $event->getPlayer(). But there is no such thing as PlayerDamageEvent, like I said.
    3. What is $player->getInventory()->getItemInHand()->getId() == Item::IRON_SWORD{ supposed to do? You need a control structure(learn about it here) to check the item.
  11. XEmAX32
    Offline

    XEmAX32 Active Member

    Joined:
    Feb 1, 2015
    Posts:
    80
    Minecraft User:
    XEmAX32
    ok excuseme and thank's for the guide :D you can explane to me how to use addEffect event please
  12. Gamecrafter
    Offline

    Gamecrafter Notable Member Plugin Developer

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    CraftYourBukkit and XEmAX32 like this.
  13. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    If this code contains mistakes, comment. I'm writing it on my phone.
    PHP:
    public function onHit(EntityDamageEvent $event){
    $entity $event->getEntity();
    if(
    $entity instanceof Player){
    $cause $entity->getLastDamageCause();
    if(
    $cause instanceof EntityDamageByEntityEvent){
    $hitter $event->getDamager();
    if(
    $hitter instanceof Player){
    // Add Effect to $hitter
    }
    }
    }
    }
  14. SM11
    Offline

    SM11 Active Member

    Joined:
    Jun 21, 2015
    Posts:
    117
    Minecraft User:
    SM11
  15. SM11
    Offline

    SM11 Active Member

    Joined:
    Jun 21, 2015
    Posts:
    117
    Minecraft User:
    SM11
    How would I add the Id of the Material That hits the Player
  16. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    To add effects see the src of FineJoinEffects or what ever plugin that includes effects. That is half of what github does, ya know.
    jojoe77777 likes this.
  17. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    public function onHit(EntityDamageEvent $e){
    $target = $e->getEntity();
    if($target instanceof Player){
    $cause = $target->getLastDamageCause()->getCause();
    if($cause === 1){
    $damager = $event->getEntity()->getLastDamageCause()->getDamager();
    }
    if($damager instanceof Player && $damager->getInventory()->getItemInHand()->getID() === Item::STICK){
    $effect = Effect::getEffectByName("Wither");
    $target->addEffect($effect);
    }

    }
    }
    IcePL likes this.
  18. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    And remember import pocketmine\effect\Effect;
  19. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Guys, please use [PHP][/PHP]...
  20. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    lol. Only @Artide is not using this amazing feature :)
    jojoe77777 likes this.

Share This Page

Advertisement