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

Custom projectile

Comments in 'Plugin Development' started by SM11, Aug 6, 2015.

  1. SM11
    Offline

    SM11 Active Member

    Joined:
    Jun 21, 2015
    Posts:
    117
    Minecraft User:
    SM11
    Hi, I was recently looking over the forums and found custom projeciles code I tried to make it work but it was no use it kept crashing, heres a Crash log can anyone please help me.

    PocketMine-MP Crash Dump Thu Aug 6 08:08:48 AKDT 2015

    Error: Call to undefined method pocketmine\event\player\PlayerInteractEvent::getDirectionVector()
    File: /EmeraldCannon/src/SM11/EmeraldCannon/Main
    Line: 21
    Type: E_ERROR

    THIS CRASH WAS CAUSED BY A PLUGIN
    BAD PLUGIN: EmeraldCannon v1.0.0

    Code:
    [12] $this->getLogger()->info("EmeraldCannon enabled!");
    [13] }
    [14]
    [15] public function onDisable(){
    [16] $this->getServer()->getPluginManager()->registerEvents($this, $this);
    [17] $this->getLogger()->info("WaterDamage Disabled!");
    [18] }
    [19]
    [20] public function onInteract(PlayerInteractEvent $player){
    [21] $aimPos = $player->getDirectionVector();$nbt = new Compound("", ["Pos" => new Enum("Pos", [
    [22] new Double("", $player->x),
    [23] new Double("", $player->y + $player->getEyeHeight()),
    [24] new Double("", $player->z)
    [25] ]),"Motion" => new Enum("Motion", [
    [26] new Double("", $aimPos->x),
    [27] new Double("", $aimPos->y),
    [28] new Double("", $aimPos->z)
    [29] ]),"Rotation" => new Enum("Rotation", [
    [30] new Float("", $player->yaw),
    [31] new Float("", $player->pitch)

    Backtrace:
    #0 /src/pocketmine/Server__32bit(0): pocketmine\Server->crashDump()
    #1 /src/pocketmine/plugin/MethodEventExecutor(36): SM11\EmeraldCannon\Main->onInteract()
    #2 /src/pocketmine/plugin/RegisteredListener(96): pocketmine\plugin\MethodEventExecutor->execute()
    #3 /src/pocketmine/plugin/PluginManager(673): pocketmine\plugin\RegisteredListener->callEvent()
    #4 /src/pocketmine/Player__32bit(1966): pocketmine\plugin\PluginManager->callEvent()
    #5 /src/pocketmine/network/RakLibInterface(140): pocketmine\Player->handleDataPacket()
    #6 /src/raklib/server/ServerHandler__32bit(90): pocketmine\network\RakLibInterface->handleEncapsulated()
    #7 /src/pocketmine/network/RakLibInterface(79): raklib\server\ServerHandler->handlePacket()
    #8 /src/pocketmine/network/Network(146): pocketmine\network\RakLibInterface->process()
    #9 /src/pocketmine/Server__32bit(2474): pocketmine\network\Network->processInterfaces()
    #10 /src/pocketmine/Server__32bit(2291): pocketmine\Server->tick()
    #11 /src/pocketmine/Server__32bit(2169): pocketmine\Server->tickProcessor()
    #12 /src/pocketmine/Server__32bit(1774): pocketmine\Server->start()
    #13 /src/pocketmine/PocketMine(464): pocketmine\Server->__construct()
    #14 (1): ()
    #15 (0): {main}()

    PocketMine-MP version: 1.5dev #1232 [Protocol 27; API 1.12.0]
    Git commit: 0000000000000000000000000000000000000000
    uname -a: Windows NT ASUS-LAPTOP 6.2 build 9200 (Windows 8 Home Premium Edition) i586
    PHP Version: 5.6.6
  2. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    #TIP: add $player = $player->getPlayer();
    at the beggining of the script
    TheKofola12 and Minecrafter9203 like this.
  3. SM11
    Offline

    SM11 Active Member

    Joined:
    Jun 21, 2015
    Posts:
    117
    Minecraft User:
    SM11
    Crashed Again, Except it happened when I threw it

    PocketMine-MP Crash Dump Thu Aug 6 08:30:38 AKDT 2015

    Error: Undefined class constant 'EMERALD'
    File: /EmeraldCannon/src/SM11/EmeraldCannon/Main
    Line: 40
    Type: E_ERROR

    THIS CRASH WAS CAUSED BY A PLUGIN
    BAD PLUGIN: EmeraldCannon v1.0.0

    Code:
    [31] new Double("", $player->y + $player->getEyeHeight()),
    [32] new Double("", $player->z)
    [33] ]),"Motion" => new Enum("Motion", [
    [34] new Double("", $aimPos->x),
    [35] new Double("", $aimPos->y),
    [36] new Double("", $aimPos->z)
    [37] ]),"Rotation" => new Enum("Rotation", [
    [38] new Float("", $player->yaw),
    [39] new Float("", $player->pitch)
    [40] ]),"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),
    [41] ]),"PickupDelay" => new Short("PickupDelay", 0x7F),
    [42] ]);$f = 1.5;$emerald= Entity::createEntity("Item", $player->getLevel()->getChunk($player->getFloorX() >> 4, $player->getFloorZ() >> 4), $nbt, $player);$emerald->setMotion($snowball->getMotion()->multiply($f));
    [43] if($player->isSurvival()){$item->setCount($item->getCount() - 1);$player->getInventory()->setItemInHand($item->getCount() > 0 ? $item : Item::get(Item::AIR));
    [44] }$player->getLevel()->addSound(new LaunchSound($player), $player->getViewers());$emerald->spawnToAll();
    [45]
    [46] }
    [47] }
    [48]
    [49]
    [50]

    Backtrace:
    #0 /src/pocketmine/Server__32bit(0): pocketmine\Server->crashDump()
    #1 /src/pocketmine/plugin/MethodEventExecutor(36): SM11\EmeraldCannon\Main->onInteract()
    #2 /src/pocketmine/plugin/RegisteredListener(96): pocketmine\plugin\MethodEventExecutor->execute()
    #3 /src/pocketmine/plugin/PluginManager(673): pocketmine\plugin\RegisteredListener->callEvent()
    #4 /src/pocketmine/Player__32bit(1966): pocketmine\plugin\PluginManager->callEvent()
    #5 /src/pocketmine/network/RakLibInterface(140): pocketmine\Player->handleDataPacket()
    #6 /src/raklib/server/ServerHandler__32bit(90): pocketmine\network\RakLibInterface->handleEncapsulated()
    #7 /src/pocketmine/network/RakLibInterface(79): raklib\server\ServerHandler->handlePacket()
    #8 /src/pocketmine/network/Network(146): pocketmine\network\RakLibInterface->process()
    #9 /src/pocketmine/Server__32bit(2474): pocketmine\network\Network->processInterfaces()
    #10 /src/pocketmine/Server__32bit(2291): pocketmine\Server->tick()
    #11 /src/pocketmine/Server__32bit(2169): pocketmine\Server->tickProcessor()
    #12 /src/pocketmine/Server__32bit(1774): pocketmine\Server->start()
    #13 /src/pocketmine/PocketMine(464): pocketmine\Server->__construct()
    #14 (1): ()
    #15 (0): {main}()

    PocketMine-MP version: 1.5dev #1232 [Protocol 27; API 1.12.0]
    Git commit: 0000000000000000000000000000000000000000
    uname -a: Windows NT ASUS-LAPTOP 6.2 build 9200 (Windows 8 Home Premium Edition) i586
    PHP Version: 5.6.6
    Zend version: 2.6.0
    OS : WINNT, win
  4. SM11
    Offline

    SM11 Active Member

    Joined:
    Jun 21, 2015
    Posts:
    117
    Minecraft User:
    SM11
    Here you go.

    <?php

    namespace SM11\EmeraldCannon;
    use pocketmine\plugin\PluginBase;
    use pocketmine\event\Listener;
    use pocketmine\event\player\PlayerInteractEvent;
    use pocketmine\math\Vector2;
    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\entity\Item;


    class Main extends PluginBase implements Listener{

    public function onEnable(){
    $this->getServer()->getPluginManager()->registerEvents($this, $this);
    $this->getLogger()->info("EmeraldCannon enabled!");
    }

    public function onDisable(){
    $this->getServer()->getPluginManager()->registerEvents($this, $this);
    $this->getLogger()->info("EmereldCannon Disabled!");
    }

    public function onInteract(PlayerInteractEvent $player){
    $player = $player->getPlayer();
    $aimPos = $player->getDirectionVector();$nbt = new Compound("", ["Pos" => new Enum("Pos", [
    new Double("", $player->x),
    new Double("", $player->y + $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;$emerald= Entity::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() > 0 ? $item : Item::get(Item::AIR));
    }$player->getLevel()->addSound(new LaunchSound($player), $player->getViewers());$emerald->spawnToAll();

    }
    }
    Minecrafter9203 likes this.
  5. SM11
    Offline

    SM11 Active Member

    Joined:
    Jun 21, 2015
    Posts:
    117
    Minecraft User:
    SM11
    Um, When I use the snowball I end up getting damage, and This is for the emerald on console
    [CRITICAL] "Could not pass event 'pocketmine\event\player\PlayerInteractEvent' to 'EmeraldCannon v1.0.0': Undefined variable: snowball on SM11\EmeraldCannon\Main

    09:24:59[NOTICE] UndefinedVariableException: "Undefined variable: snowball" (E_NOTICE) in "/EmeraldCannon/src/SM11/EmeraldCannon/Main" at line 44

    09:25:01[CRITICAL] "Could not pass event 'pocketmine\event\player\PlayerInteractEvent' to 'EmeraldCannon v1.0.0': Undefined variable: snowball on SM11\EmeraldCannon\Main
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Learn PHP.
    Minecrafter9203 and Legoboy0215 like this.
  7. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Isn't that a @wiez speech?
    PEMapModder likes this.

Share This Page

Advertisement