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

Solved Lightning damage

Discussion in 'Development' started by minijaham, Oct 29, 2020.

  1. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    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->$player->getTargetBlock(20)->getX();
                
    $sound->$player->getTargetBlock(20)->getY();
                
    $sound->$player->getTargetBlock(20)->getZ();
                
    $sound->volume 1;
                
    $sound->pitch 1;
                
    Server::getInstance()->broadcastPacket($player->getLevel()->getPlayers(), $sound);
            }
        }
       
        public function 
    getOwner(): Main{
            return 
    $this->plugin;
        }
     
    Primus likes this.
  2. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    I just created a new entity :D
     
  3. Primus

    Primus Zombie Pigman

    Messages:
    749
    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)
     
    minijaham 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.