1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

using EntityDamage to set a knockback

Discussion in 'Development' started by Vaxrp, Oct 27, 2017.

  1. Vaxrp

    Vaxrp Witch

    Messages:
    73
    GitHub:
    Vaxrp
    Hey, today I wanted to see if this is a way that I can actually make this function work. Would actually doing this work? I dont have a server to test this on so thats why I am asking i want to get it done by the time I get a test server. Thanks also what does the “z” do? I just set it the same to the x cause I heard they are the same thanks heres my code:
    PHP:
    class Main extends PluginBase implements Listener{

      public function 
    onEnable() {
         
    $this->getServer()->getPluginManager()->registerEvents($this,$this);      
      }

      
    $mot = new Vector3($this->motionX$this->motionY$this->motionZ);
     
      
    $mot->0.3;
      
    $mot->0.5;
      
    $mot->0.3;//UNSURE OF THIS HELP?
     
      
    public function onDamage(EntityDamageEvent $daddy) {
        if(
    $daddy instanceof EntityDamagebyEntityEvent){
          
    $event-setMotion($mot);
        }
      }
    }
     
  2. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    Naming the event daddy and then using event anyways won’t work. Also setMotion isn’t what you want, you want setKnockback (setMotion is only availible for Entities anyways. Also your $mot variable declaration is out of scope.
    PHP:
    class Main extends PluginBase implements Listener{

      public function 
    onEnable() {
         
    $this->getServer()->getPluginManager()->registerEvents($this,$this);     
      }

      public function 
    onDamage(EntityDamageByEntitiyEvent $daddy) {
          
    $daddy->setKnockback(0.5);
      }
    }
     
    Vaxrp likes this.
  3. Vaxrp

    Vaxrp Witch

    Messages:
    73
    GitHub:
    Vaxrp
    I made that exact plugin a couple weeks ago but I want to use setMotion so that I can change the x and y values diffrently. Can you help me find a way?
     
  4. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    If you want to use setMotion it has to look like this:
    PHP:
    class Main extends PluginBase implements Listener{

      public function 
    onEnable() {
         
    $this->getServer()->getPluginManager()->registerEvents($this,$this);   
      }

      public function 
    onDamage(EntityDamageByEntitiyEvent $daddy) {
          
    $daddy->getEntitiy()->setMotion(new Vector3(0.3,0.5,0.3));
      }
    }
     
    Vaxrp likes this.
  5. Vaxrp

    Vaxrp Witch

    Messages:
    73
    GitHub:
    Vaxrp
    Oh okay, now I understand. Thanks dude!
     
  6. Vaxrp

    Vaxrp Witch

    Messages:
    73
    GitHub:
    Vaxrp
    Code:
    Server thread/CRITICAL ReflectionException: "Class Knockback\EntityDamageEvent does not exist" (EXCEPTION) in "src/pocketmine/plugin/PluginManager" at line 769
    27.10 01:41:02 [Server] Server thread/DEBUG #0 src/pocketmine/plugin/PluginManager(769): ReflectionParameter->getClass()
    27.10 01:41:02 [Server] Server thread/DEBUG #1 Knockback/src/Knockback/Main(16): pocketmine\plugin\PluginManager->registerEvents(Knockback\Main object, Knockback\Main object)
    27.10 01:41:02 [Server] Server thread/DEBUG #2 src/pocketmine/plugin/PluginBase(90): Knockback\Main->onEnable()
    27.10 01:41:02 [Server] Server thread/DEBUG #3 PocketMine-DevTools_dev-63.phar/src/FolderPluginLoader/FolderPluginLoader(125): pocketmine\plugin\PluginBase->setEnabled(boolean 1)
    27.10 01:41:02 [Server] Server thread/DEBUG #4 src/pocketmine/plugin/PluginManager(610): FolderPluginLoader\FolderPluginLoader->enablePlugin(Knockback\Main object)
    27.10 01:41:02 [Server] Server thread/DEBUG #5 src/pocketmine/Server(1940): pocketmine\plugin\PluginManager->enablePlugin(Knockback\Main object)
    27.10 01:41:02 [Server] Server thread/DEBUG #6 src/pocketmine/Server(1926): pocketmine\Server->enablePlugin(Knockback\Main object)
    27.10 01:41:02 [Server] Server thread/DEBUG #7 src/pocketmine/Server(1712): pocketmine\Server->enablePlugins(integer 1)
    27.10 01:41:02 [Server] Server thread/DEBUG #8 src/pocketmine/PocketMine(558): pocketmine\Server->__construct(BaseClassLoader object, pocketmine\utils\MainLogger object, string phar:///custom-php7.2.phar/, string /, string /plugins/)
    27.10 01:41:02 [Server] Server thread/DEBUG #9 /custom-php7.2.phar(1): require(string phar:///custom-php7.2.phar/src/pocketmine/PocketMine.php)
    27.10 01:41:02 [Server] Server thread/INFO Disabling Knockback v1.0.2
     
  7. Vaxrp

    Vaxrp Witch

    Messages:
    73
    GitHub:
    Vaxrp
    I got this error when I treied the function I tried reading the error a couple times but cant find out what it actually means can you help? @robske_110 (Tim)
     
  8. Vaxrp

    Vaxrp Witch

    Messages:
    73
    GitHub:
    Vaxrp
    Nvm im an idiot. Fixed it
     
    jasonwynn10 and robske_110 (Tim) like this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.