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?
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;
PHP: $frontPos = $player->add($player->getDirectionVector()->multiply(0.5));// code to spawn snowball at $frontPos
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)); 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.
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.
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 ) Trigger an event when a player is hit by a snowball ONLY shot from the gun
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.");
Handle EntityDamageEvent instead of EntityDamageByEntityEvent There is no Entity::Snowball And $event->getEntity() returns an object.