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

Lightning

Comments in 'Plugin Development' started by CaptainKenji17, Nov 8, 2015.

  1. CaptainKenji17
    Offline

    CaptainKenji17 Active Member

    Joined:
    Apr 22, 2014
    Posts:
    252
    Minecraft User:
    CaptainKenji17
    Yes, creeper already posted the code for lightning, but it only shows to your self.

    I want a code of lightning that every one can see? I added creeperface's code and made it on playerdeathevent and it only shows to you when you die and when u kill u cnt see lightning, your just able to see it on death screen when u die?


    just the code like on hypixel brawl, player dies, lightning shows public
  2. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    Instead of
    PHP:
    $player->datapacket($pk);
    use
    PHP:
    $this->getServer()->broadcastPacket($player->getLevel()->getPlayers(),$pk);
    Last edited: Nov 9, 2015
  3. Jelly9912
    Offline

    Jelly9912 Active Member

    Joined:
    Aug 8, 2015
    Posts:
    118
    Minecraft User:
    Jelly9912
    Use EntityDeathEvent , not PlayerDeathEvent or try this plugin , you can extract it and edit to your own needs

    Attached Files:

    deot and CaptainKenji17 like this.
  4. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    PHP:
    $this->getServer()->broadcastPacket($pk);
    or
    PHP:
    foreach($this->getServer()->getOnlinePlayers() as $p){
    $p->dataPacket($pk);
    }
    or
    PHP:
    foreach($p->getLevel()->getPlayers() as $p){
    $p->dataPacket($p);
    }
    Timmpann likes this.
  5. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    I would personally only send the packet to the players viewers.

    PHP:
    foreach($player->getViewers() as $v) {
        
    $v->dataPacket($pk);
    }
  6. CaptainKenji17
    Offline

    CaptainKenji17 Active Member

    Joined:
    Apr 22, 2014
    Posts:
    252
    Minecraft User:
    CaptainKenji17
    PHP:
         public function onDeath(EntityDeathEvent $ev){
            
    $p $ev->getPlayer();
            
    $level $p->getLevel();
        
    $light = new AddEntityPacket();
            
    $light->type 93;
            
    $light->eid Entity::$entityCount++;
            
    $light->metadata = array();
            
    $light->speedX 0;
            
    $light->speedY 0;
            
    $light->speedZ 0;
            
    $light->yaw $p->getYaw();
            
    $light->pitch $p->getPitch();
            
    $light->$p->x;
            
    $light->$p->y;
            
    $light->$p->z;
            foreach(
    $this->getServer()->getOnlinePlayers() as $p){
                
    $p->dataPacket($pk);
            }
    like this?
    Primus likes this.
  7. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    PHP:
    public function onDeath(EntityDeathEvent $event) {
        
    $victim $event->getEntity();
        if(
    $victim instanceof Player) {
            
    $pk = new AddEntityPacket();
                
    $pk->type 93;
                
    $pk->eid Entity::entityCount++;
                
    $pk->metadata = array();
               
                
    $pk->$victim->x;
                
    $pk->$victim->y;
                
    $pk->$victim->z;
                
    $pk->speedX 0;
                
    $pk->speedY 0;
                
    $pk->speedZ =0;
                
    $pk->yaw $victim->yaw;
                
    $pk->pitch $victim->pitch;
               
            foreach(
    $victim->getViewers() as $viewer) {
                
    $viewer->dataPacket($pk);
            }
        }
    }
    Last edited: Nov 8, 2015
    CaptainKenji17 and Primus like this.
  8. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    I can't remember if the actual player is included in its viewers or not, if you want to send the Lightning to the player as week just add
    PHP:
     $victim->dataPacket($pk); 
  9. CaptainKenji17
    Offline

    CaptainKenji17 Active Member

    Joined:
    Apr 22, 2014
    Posts:
    252
    Minecraft User:
    CaptainKenji17

    still doesnt show ughh
  10. CaptainKenji17
    Offline

    CaptainKenji17 Active Member

    Joined:
    Apr 22, 2014
    Posts:
    252
    Minecraft User:
    CaptainKenji17
    t
    the whole code
    PHP:
    <?php

    namespace Light;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\event\player\PlayerJoinEvent;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\network\protocol\AddEntityPacket;
    use 
    pocketmine\network\protocol\SetTimePacket;
    use 
    pocketmine\network\protocol\TextPacket;
    use 
    pocketmine\network\protocol\AddPlayerPacket;
    use 
    pocketmine\entity\Entity;
    use 
    pocketmine\event\entity\EntityDeathEvent;

    class 
    Main extends PluginBase implements Listener {

        public function 
    onEnable(){
            
    $this->getLogger()->info("LightingJoin enabled!");
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
        }
       public function 
    onCommand(CommandSender $sender,Command $cmd,$label,array $args) {
        if((
    strtolower($cmd->getName()) == "strike") && isset($args[0])) {
          if(
    $this->getServer()->getPlayer($args[0]) instanceof Player) {
            
    $sender->sendMessage("Player not connected");
           } else {
            
    $player $this->getServer()->getPlayer($args[0]);
            
    $level $player->getLevel();
            
    $light = new AddEntityPacket();
            
    $light->type 93;
            
    $light->eid Entity::$entityCount++;
            
    $light->metadata = array();
            
    $light->speedX 0;
            
    $light->speedY 0;
            
    $light->speedZ 0;
            
    $light->yaw $player->getYaw();
            
    $light->pitch $player->getPitch();
            
    $light->$player->x;
            
    $light->$player->y;
            
    $light->$player->z;
            foreach(
    $level->getPlayers() as $pl){
                
    $player->dataPacket($light);
            }
          }
          return 
    true;
        }
      }   
    public function 
    onDeath(EntityDeathEvent $event) {
        
    $victim $event->getEntity();
        if(
    $victim instanceof Player) {
            
    $pk = new AddEntityPacket();
                
    $pk->type 93;
                
    $pk->eid Entity::$entityCount++;
                
    $pk->metadata = array();
               
                
    $pk->$victim->x;
                
    $pk->$victim->y;
                
    $pk->$victim->z;
                
    $pk->speedX 0;
                
    $pk->speedY 0;
                
    $pk->speedZ =0;
                
    $pk->yaw $victim->yaw;
                
    $pk->pitch $victim->pitch;
               
            foreach(
    $victim->getViewers() as $viewer) {
                
    $viewer->dataPacket($pk);
                 }
            }
        }
    }
  11. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    Make sure your "using" all the classes that are required :p
  12. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    PHP:
    use pocketmine\Player;
  13. CaptainKenji17
    Offline

    CaptainKenji17 Active Member

    Joined:
    Apr 22, 2014
    Posts:
    252
    Minecraft User:
    CaptainKenji17
    still nope ;(

Share This Page

Advertisement