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

Solved Rotation + Throwing emeralds

Comments in 'Plugin Development' started by Kvetinac97, Jul 18, 2015.

  1. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    -_- I know but what should I set » $emerald->setMotion(HERE); « ?
  2. ahoj_truhliku
    Offline

    ahoj_truhliku Banned

    Joined:
    Jul 9, 2015
    Posts:
    89
    Minecraft User:
    Creeperface001
  3. ahoj_truhliku
    Offline

    ahoj_truhliku Banned

    Joined:
    Jul 9, 2015
    Posts:
    89
    Minecraft User:
    Creeperface001
  4. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    So:
    PHP:
    if($item -> getId() === Item::EMERALD){
    $nbt = new Compound"" , [
    "Pos" => new Enum"Pos" , [
    new 
    Double("" $this -> x),
    new 
    Double("" $this -> $this -> getEyeHeigh
    new Double("" $this -> z)
    ]),
    "Motion" => new Enum"Motion" , [
    new 
    Double("" $aimPos -> x),
    new 
    Double("" $aimPos -> y),
    new 
    Double("" $aimPos -> z)
    ]),
    "Rotation" => new Enum"Rotation" , [
    new 
    Float"" $this -> yaw),
    new 
    Float"" $this -> pitch)
    ]),
    ]);
    $f 1.5 ;
    $emerald Entity:: createEntity"Snowball" $this -> chunk$n
    $emerlad 
    -> setMotion($emerald -> getMotion()-> multiply($f));
    if(
    $this -> isSurvival()){
    $item-> setCount($item -> getCount() - 1);
    $this-> inventory -> setItemInHand($item -> getCount() > 0
    }
    if(
    $emerald instanceof Projectile){
    $this-> server-> getPluginManager()-> callEvent($project
    if($projectileEv -> isCancelled()){
    $emerald -> kill();
    }else{
    $emerald -> spawnToAll();
    $this -> level -> addSound( new LaunchSound ($this)
    }
    } else{
    $emerald-> spawnToAll();
    }
    ?
  5. ahoj_truhliku
    Offline

    ahoj_truhliku Banned

    Joined:
    Jul 9, 2015
    Posts:
    89
    Minecraft User:
    Creeperface001
    yes now you should only edit it for your plugin :D (good to know: Your plugin is not Player)
    PEMapModder likes this.
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    PHP:
                            $aimPos $player->getDirectionVector();
                            
    $nbt = new Compound("", [
                                
    "Pos" => new Enum("Pos", [
                                    new 
    Double(""$player->x),
                                    new 
    Double(""$player->$player->getEyeHeight()),
                                    new 
    Double(""$player->z)
                                ]),
                                
    "Motion" => new Enum("Motion", [
                                    new 
    Double(""$aimPos->x),
                                    new 
    Double(""$aimPos->y),
                                    new 
    Double(""$aimPos->z)
                                ]),
                                
    "Rotation" => new Enum("Rotation", [
                                    new 
    Float(""$player->yaw),
                                    new 
    Float(""$player->pitch)
                                ]),
                               
    "Health" => new Short("Health"5),
                               
    "Item" => new Compound("Item", [
                                   
    "id" => new Short("id"Item::EMERALD),
                                   
    "Damage" => new Short("Damage"0),
                                   
    "Count" => new Byte("Count"1),
                               ]),
                               
    "PickupDelay" => new Short("PickupDelay"0x7F),
                            ]);
                            
    $f 1.5;
                            
    $emeraldEntity::createEntity("Item"$player->getLevel()->getChunk($player->getFloorX() >> 4$player->getFloorZ() >> 4), $nbt$player);
                            
    $emerald->setMotion($snowball->getMotion()->multiply($f));
                            if(
    $player->isSurvival()){
                                
    $item->setCount($item->getCount() - 1);
                                
    $player->getInventory()->setItemInHand($item->getCount() > $item Item::get(Item::AIR));
                            }
                            
    $player->getLevel()->addSound(new LaunchSound($player), $player->getViewers());
                            
    $emerald->spawnToAll();
                            }
  7. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    Will this work?
    PHP:
    public function onBoom(EntityDamageByEntityEvent $ev){
    if (
    $ev->getDamager() instanceof Item and $ev->getDamager() === Item::EMERALD and $ev-
    >
    getTaker() instanceof Player){
    $ev->getTaker()->setHealth($ev->getTaker()->getHealth()-1);
    }
    }
  8. ahoj_truhliku
    Offline

    ahoj_truhliku Banned

    Joined:
    Jul 9, 2015
    Posts:
    89
    Minecraft User:
    Creeperface001
    no xD and getTaker doesn´t exist :D you can not invent your own methods
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    For the millionth time you can register an event handler for EntityDamageByEntityEvent, only EntityDamageEvent...
    iksaku and ahoj_truhliku like this.
  10. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    BAM! PEMapModder you forgot the :
    PHP:
    $player $event->getPlayer();
    in the code :p
    SeifValkierks likes this.
  11. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Why must the $player be from an event? I can make it be passed from the function parameter directly.
  12. FuryTacticz
    Offline

    FuryTacticz New Member

    Joined:
    Aug 31, 2015
    Posts:
    23
    Minecraft User:
    FuryTacticz
    hmmm I tried to use this code to shoot out a emerald whilst holding a diamond sword.
    Heres what I did:

    PHP:
    <?php

    namespace TestPlugin;

    use 
    pocketmine\Server;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandExecutor;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\PluginCommand;
    use 
    pocketmine\Player;
    use 
    pocketmine\item\Item;
    use 
    pocketmine\event\player\PlayerChatEvent;
    use 
    pocketmine\event\player\PlayerInteractEvent;
    use 
    pocketmine\event\player\PlayerDeathEvent;
    use 
    pocketmine\event\entity\EntityDamageEvent;
    use 
    pocketmine\event\entity\EntityDamageByEntityEvent;
    use 
    pocketmine\event\entity\EntityLevelChangeEvent;
    use 
    pocketmine\event\block\BlockPlaceEvent;
    use 
    pocketmine\event\block\BlockBreakEvent;
    use 
    pocketmine\event\EventExecutor;
    use 
    pocketmine\event\EventPriority;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\plugin\Plugin;
    use 
    pocketmine\tile\Sign;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\utils\TextFormat;
    use 
    pocketmine\scheduler\PluginTask;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\math\Vector3;
    use 
    pocketmine\Player\getName;
    use 
    pocketmine\command\ConsoleCommandSender;
    use 
    pocketmine\event\player\PlayerQuitEvent;
    use 
    pocketmine\event\player\PlayerJoinEvent;
    use 
    pocketmine\block\Block;
    use 
    pocketmine\event\player\PlayerMoveEvent;
    use 
    pocketmine\pocketmine\Level;
    use 
    pocketmine\entity\Effect;
    use 
    pocketmine\event\player\PlayerPreLoginEvent;
    use 
    pocketmine\entity\Entity;
    use 
    pocketmine\nbt\tag\Compound;
    use 
    pocketmine\nbt\tag\Enum;
    use 
    pocketmine\nbt\tag\Double;
    use 
    pocketmine\nbt\tag\Float;
    use 
    pocketmine\nbt\tag\Short;
    use 
    pocketmine\nbt\tag\Byte;
    use 
    pocketmine\nbt\tag\Long;
    use 
    pocketmine\nbt\tag\NamedTag;
    use 
    pocketmine\nbt\tag\String;
    use 
    pocketmine\nbt\tag\IntArray;
    use 
    pocketmine\nbt\tag\Int;


    class 
    TestPlugin extends PluginBase implements Listener{




                 
        public function 
    onLoad(){
            
    $this->getLogger()->info(TextFormat::YELLOW."Loaded.");
        }

        public function 
    onEnable(){
        
    $this->getServer()->getPluginManager()->registerEvents($this$this);
        }
      
        public function 
    onInteract(PlayerInteractEvent $event){
            
    $player $event->getPlayer();
            if (
    $event->getAction() == PlayerInteractEvent::RIGHT_CLICK_AIR and $event->getItem()->getId() === 276){
                
    $event->getPlayer()->sendMessage("Test");
              
                
    $aimPos $player->getDirectionVector();
                            
    $nbt = new Compound("", [
                                
    "Pos" => new Enum("Pos", [
                                    new 
    Double(""$player->x),
                                    new 
    Double(""$player->$player->getEyeHeight()),
                                    new 
    Double(""$player->z)
                                ]),
                                
    "Motion" => new Enum("Motion", [
                                    new 
    Double(""$aimPos->x),
                                    new 
    Double(""$aimPos->y),
                                    new 
    Double(""$aimPos->z)
                                ]),
                                
    "Rotation" => new Enum("Rotation", [
                                    new 
    Float(""$player->yaw),
                                    new 
    Float(""$player->pitch)
                                ]),
                               
    "Health" => new Short("Health"5),
                               
    "Item" => new Compound("Item", [
                                   
    "id" => new Short("id"Item::EMERALD),
                                   
    "Damage" => new Short("Damage"0),
                                   
    "Count" => new Byte("Count"1),
                               ]),
                               
    "PickupDelay" => new Short("PickupDelay"0x7F),
                            ]);
                            
    $f 1.5;
                            
    $emeraldEntity::createEntity("Item"$player->getLevel()->getChunk($player->getFloorX() >> 4$player->getFloorZ() >> 4), $nbt$player);
                            
    $emerald->setMotion($snowball->getMotion()->multiply($f));
                            if(
    $player->isSurvival()){
                                
    $item->setCount($item->getCount() - 1);
                                
    $player->getInventory()->setItemInHand($item->getCount() > $item Item::get(Item::AIR));
                            }
                            
    $player->getLevel()->addSound(new LaunchSound($player), $player->getViewers());
                            
    $emerald->spawnToAll();
                            }
            }

          
    }


    The code that I took from Pemapmodder has a undefined variable which is:
    PHP:
    $emerald->setMotion($snowball->getMotion()->multiply($f));
    And im not sure what to define it as.
    Anyone know what to define it as.
    PHP:
    $snowball
    SeifValkierks likes this.
  13. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    replace it with $emerald
    SeifValkierks likes this.
  14. FuryTacticz
    Offline

    FuryTacticz New Member

    Joined:
    Aug 31, 2015
    Posts:
    23
    Minecraft User:
    FuryTacticz
    Ok thanks il try that :)
  15. FuryTacticz
    Offline

    FuryTacticz New Member

    Joined:
    Aug 31, 2015
    Posts:
    23
    Minecraft User:
    FuryTacticz
    Thanks that worked! :)
    Now how would I make it so that if a person is hit by my desired item he will be damaged?
    What event shall I use?
    :)
    SeifValkierks likes this.
  16. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    it's
    PHP:
    public function onBoom(EntityDamageByEntityEvent $ev){
    if (
    $ev->getDamager() instanceof Item and $ev->getDamager() === Item::EMERALD and $ev-
    >
    getTaker() instanceof Player){$ev->getTaker()->setHealth($ev->getTaker()->getHealth()-1);
    }
    }
    and don't forget to add
    PHP:
    pocketmine\event\entity\EntityDamageByEntityEvent;
    and the -1 is how much health he will get. so add the - to be as lose :p


    Thanks
    Last edited: Sep 5, 2015
    SeifValkierks likes this.
  17. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    and it will never work until you add the
    PHP:
    $id $item->getId;
    After the
    PHP:
    $player $event->getPlayer();
    Thanks
    SeifValkierks likes this.
  18. FuryTacticz
    Offline

    FuryTacticz New Member

    Joined:
    Aug 31, 2015
    Posts:
    23
    Minecraft User:
    FuryTacticz
    Whats getTaker()?
    :p
    It should be $event->getEntity()
  19. FuryTacticz
    Offline

    FuryTacticz New Member

    Joined:
    Aug 31, 2015
    Posts:
    23
    Minecraft User:
    FuryTacticz
    it didnt work.
  20. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    hmm i understand you incorrectly.sorry i have no idea for that.but i will find the code.

Share This Page

Advertisement