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

Create entity in front of a player

Comments in 'Plugin Development' started by minebuilder0110, Oct 11, 2015.

  1. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    I am attempting to create a gun plugin, and I am having trouble where I noticed that snowballs are created in you, which is completely useless. How can make it so that the plugin calculated the coordinate of 0.5 block from you in the direction of you facing?
  2. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    Bump. Help?
    TryoneLegendZzz likes this.
  3. TryoneLegendZzz
    Offline

    TryoneLegendZzz Active Member

    Joined:
    May 31, 2015
    Posts:
    201
    Minecraft User:
    SavionLegendZzz
  4. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    umm great, but it only blows you up when you use it, not firing any bullets. I really need a way to calculate a coordinate 0.5 away from a player in a way player is facing, when the directions are:
    $dir = $player->getDirectionVector();
    $dir->x = $dir->x * $speed;
    $dir->y = $dir->y * $speed;
    $dir->z = $dir->z * $speed;
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    PHP:
    $frontPos $player->add($player->getDirectionVector()->multiply(0.5));
    // code to spawn snowball at $frontPos
    minebuilder0110 likes this.
  6. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    Already did.
    I had trouble when I noticed snowballs spawned behind me until I made:
    $frontPos = $player->add($player->getDirectionVector()->multiply(0.5));

    into:
    $frontPos = $player->add($player->getDirectionVector()->multiply(1.5)); :p

    Also, is it possible to detect if a player is holding the screen (== holding right click for a long time on minecraft pc), and repeat certain task whilst holding it? When I tried making one, the event is triggered only once, when I held the right click.
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I don't think it is possible. Holding a bow is an exception, as the client will send a PLAYER_ACTION_PACKET when he has stopped holding the screen.
  8. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    Awwww... (bye bye machine gun idea)
    But is it possible to do these?
    Repeat certain task with delay (I'm going to try burst shots because of the post above :p)
    Trigger an event when a player is hit by a snowball ONLY shot from the gun
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Yes, but you need to find a way to insert the data about the gun into the arrow shot.
  10. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    Insert the data? So is it adding new configuration to it? (sorry, I never tried something like that)
  11. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    OK, so I tried to test out whether an event will be called when a player is hit by a general snowball but this happened.
    pocketmine\utils\PluginException: "pocketmine\event\entity\EntityDamageByEntityEvent does not have a handler list" (EXCEPTION) in "/src/pocketmine/plugin/PluginManager" at line 759
    I have never seen this error before, and I don't know what it means by it.
    This is the handler code (Though the fact that it says 'does not have a handler list' might be why it is not being triggered)
    PHP:
        public function onHitBySnowballs(EntityDamageByEntityEvent $event){
            if(
    $event->getEntity() === Entity::Snowball){
                
    $event->getPlayer()->sendMessage("You have been hit by a bullet from other player.");
  12. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Handle EntityDamageEvent instead of EntityDamageByEntityEvent
    There is no Entity::Snowball
    And $event->getEntity() returns an object.
    Legoboy0215 likes this.
  13. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    Hmm ok Ill try that
    (That code snippet now sounds like a hell of a derp.)

Share This Page

Advertisement