Is it possible to make a Item have a Withereffect, so when I hit someone with the Item they are effected?
EntityDamageEvent, check if hit is by a player, get the item in hand, check the item, if it's the item, give effect
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 )
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.
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
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
Okay. Here's a list of mistakes, so please take a good look at PHP and the PocketMine-API: There is no PlayerDamageEvent. There is only EntityDamageEvent. 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. 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.
Look here: http://jenkins.pocketmine.net/job/PocketMine-MP-doc/doxygen/df/d2c/classpocketmine_1_1_player.html
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}}}}
To add effects see the src of FineJoinEffects or what ever plugin that includes effects. That is half of what github does, ya know.
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); } } }