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

Player Damage Event Water Collosion

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

  1. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    PHP:
    public function onMove(PlayerMoveEvent $event){
    $player $event->getPlayer(); // This was causing: 'Undefined variable: player'
    foreach($player->getBlocksAround() as $block){ // Loop through all blocks around
    if($block->getId() === Block::WATER/*BLOCK*/){ // If that block is water do damage or whatever
    $player->attack(1, new EntityDamageEvent($player/*VICTIM*/CAUSE_CONTACT /* VALUE: 0*/1/*DAMAGE*/));
    }
    }
    }
    }
    Right code i supose. Comments should be deleted if you dont want them but they may help later.
  2. SM11
    Offline

    SM11 Active Member

    Joined:
    Jun 21, 2015
    Posts:
    117
    Minecraft User:
    SM11
    Still it shows error here it is
    14:52:58[CRITICAL] ClassNotFoundException: "Class SM11\WaterDamage\Block not found" (EXCEPTION) in "/src/spl/BaseClassLoader" at line 144

    14:52:59[CRITICAL] "Could not pass event 'pocketmine\event\player\PlayerMoveEvent' to 'WaterDamage v1.0.0': Class SM11\WaterDamage\Block not found on SM11\WaterDamage\Main
  3. SM11
    Offline

    SM11 Active Member

    Joined:
    Jun 21, 2015
    Posts:
    117
    Minecraft User:
    SM11
    Here is my code

    <?php

    namespace SM11\WaterDamage;
    use pocketmine\event\entity\EntityDamageEvent;
    use pocketmine\event\player\PlayerMoveEvent;
    use pocketmine\Player;
    use pocketmine\plugin\PluginBase;
    use pocketmine\event\Listener;

    class Main extends PluginBase implements Listener{

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

    public function onDisable(){
    $this->getLogger()->info("WaterDamage disabled!");
    }

    public function hasEntityCollision(){
    return true;
    }

    public function onMove(PlayerMoveEvent $event){
    $player = $event->getPlayer(); // This was causing: 'Undefined variable: player'
    foreach($player->getBlocksAround() as $block){ // Loop through all blocks around
    if($block->getId() === Block::WATER/*BLOCK*/){ // If that block is water do damage or whatever
    $player->attack(1, new EntityDamageEvent($player/*VICTIM*/, CAUSE_CONTACT /* VALUE: 0*/, 1/*DAMAGE*/));
    }
    }
    }
    }
  4. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    PHP:
    public function hasEntityCollision(){
    return 
    true;
    }
    Whats this?
    Is plugin working properly?
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    1. Please use [PHP][/PHP] to contain your code.
    2. Please learn PHP. Don't copy code blindly. If you read the code, you would find that you need to import the correct classes.
    EntityDamageEvent::CAUSE_CONTACT
    CaptainKenji17 likes this.
  6. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    PHP:
    use pocketmine\block\Block;
    ?
  7. SM11
    Offline

    SM11 Active Member

    Joined:
    Jun 21, 2015
    Posts:
    117
    Minecraft User:
    SM11
    Sorry, I just started Learning it, Made a mistake there, but I've learned it
  8. SM11
    Offline

    SM11 Active Member

    Joined:
    Jun 21, 2015
    Posts:
    117
    Minecraft User:
    SM11
    Tried it works for people who are new but it doesn't for the existing players. also when you die water damage will no longer effect you
  9. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Sounds something impossible. Off course if you're dead you cant recieve damage :D
  10. SM11
    Offline

    SM11 Active Member

    Joined:
    Jun 21, 2015
    Posts:
    117
    Minecraft User:
    SM11
    My bad , I meant after you Respawn your invincible to Damage
  11. CaptainKenji17
    Offline

    CaptainKenji17 Active Member

    Joined:
    Apr 22, 2014
    Posts:
    252
    Minecraft User:
    CaptainKenji17
    The most hated word
  12. CaptainKenji17
    Offline

    CaptainKenji17 Active Member

    Joined:
    Apr 22, 2014
    Posts:
    252
    Minecraft User:
    CaptainKenji17

    is the (...) is the place where u add the event code? like this

    if($block->getId() === Block::CACTUS) $player->attack(1, new EntityDamageEvent(

    $event->setKnockback() === 1);

    and should I add if($block->getId() === Block::CACTUS) $player->attack(1, new EntityDamageEvent $event(...));


    $event on EntityDamageEvent? I actually wanna add the entity damage event inside another event
  13. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    No. Pass the relevant arguments to the EntityDamageEvent constructor. https://github.com/PocketMine/Pocke...etmine/event/entity/EntityDamageEvent.php#L67
  14. CaptainKenji17
    Offline

    CaptainKenji17 Active Member

    Joined:
    Apr 22, 2014
    Posts:
    252
    Minecraft User:
    CaptainKenji17
  15. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    GmWM likes this.
  16. CaptainKenji17
    Offline

    CaptainKenji17 Active Member

    Joined:
    Apr 22, 2014
    Posts:
    252
    Minecraft User:
    CaptainKenji17
  17. Nawaf_Craft1b
    Offline

    Nawaf_Craft1b Active Member Plugin Developer

    Joined:
    May 8, 2015
    Posts:
    232
    Plugins:
    1
    Minecraft User:
    Nawaf_Craft1b
    why do you want die xD
  18. GmWM
    Offline

    GmWM Active Member Plugin Developer

    Joined:
    Sep 8, 2013
    Posts:
    181
    Plugins:
    3
    1. Ultra necro-posting.
    2. Is a sentence, not a word.
    3. That sentence is valid for you too. :)
    PocketKiller and PEMapModder like this.
  19. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    You can make damage so too $event->getPlayer()->setHealth($event->getPlayer()->getHealth() - 2); //2 = 2 half hearts = 1 heart

Share This Page

Advertisement