Hello once again.... Any ideas of how to get players that are hit by the lightning and damage them? PHP: public function Lightning(Player $player) :void{ if(in_array($player->getLevel()->getFolderName(), ["spawnfinished"])){ $light = new AddActorPacket(); $light->type = "minecraft:lightning_bolt"; $light->entityRuntimeId = Entity::$entityCount++; $light->metadata = []; $light->motion = null; $light->yaw = $player->getYaw(); $light->pitch = $player->getPitch(); $light->position = new Vector3($player->getTargetBlock(20)->getX(), $player->getTargetBlock(20)->getY(), $player->getTargetBlock(20)->getZ()); Server::getInstance()->broadcastPacket($player->getLevel()->getPlayers(), $light); $block = $player->getLevel()->getBlock($player->getPosition()->floor()->down()); $particle = new DestroyBlockParticle(new Vector3($player->getTargetBlock(20)->getX(), $player->getTargetBlock(20)->getY(), $player->getTargetBlock(20)->getZ()), $block); $player->getLevel()->addParticle($particle); $sound = new PlaySoundPacket(); $sound->soundName = "ambient.weather.thunder"; $sound->x = $player->getTargetBlock(20)->getX(); $sound->y = $player->getTargetBlock(20)->getY(); $sound->z = $player->getTargetBlock(20)->getZ(); $sound->volume = 1; $sound->pitch = 1; Server::getInstance()->broadcastPacket($player->getLevel()->getPlayers(), $sound); } } public function getOwner(): Main{ return $this->plugin; }
I do like tracing. However in this case you just look if anyone was close enough to be hit. Performance wise, loop through entities/players in a chunk(s) intersecting the path to the most furthest point ( 20 in this case, as shown above ). So yea: Hit if = target.distance(player) <= lightning.affectRadius (pseudocode, for the one who called me out on writing in non existing language)