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. SM11
    Offline

    SM11 Active Member

    Joined:
    Jun 21, 2015
    Posts:
    117
    Minecraft User:
    SM11
    How would I make it so that when a player collides with a certain block they take damage and die? I've got some code I just need some help with How its possible. I could PM anyone the code
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    PHP:
    foreach($player->getBlocksAround() as $block){
      if(
    $block->getId() === Block::CACTUS$player->attack(1, new EntityDamageEvent(...));
    }
  3. SM11
    Offline

    SM11 Active Member

    Joined:
    Jun 21, 2015
    Posts:
    117
    Minecraft User:
    SM11
    Would I put a Public function or something
  4. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    You can do it on timer
    or on PlayerMoveEvent:
    PHP:
    public function onMove(PlayerMoveEvent $event){
    // @PEMapModder code
    }
    PEMapModder likes this.
  5. SM11
    Offline

    SM11 Active Member

    Joined:
    Jun 21, 2015
    Posts:
    117
    Minecraft User:
    SM11
    Thanks
  6. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Well... 'Thanks' === $post->like(); ^_^
  7. SM11
    Offline

    SM11 Active Member

    Joined:
    Jun 21, 2015
    Posts:
    117
    Minecraft User:
    SM11
    This is my code, Something isn't right

    namespace SM11\WaterDamage;
    use pocketmine\event\entity\EntityDamageEvent;
    use pocketmine\event\entity\EntityDamageByBlockEvent;
    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 onMove(PlayerMoveEvent $event){
    foreach($player->getBlocksAround() as $block){
    if($block->getId() === Block::CACTUS) $player->attack(1, new EntityDamageEvent(...));
    }
    }
    }
  8. GmWM
    Offline

    GmWM Active Member Plugin Developer

    Joined:
    Sep 8, 2013
    Posts:
    181
    Plugins:
    3
    Learn PHP and the PocketMine API.
  9. SM11
    Offline

    SM11 Active Member

    Joined:
    Jun 21, 2015
    Posts:
    117
    Minecraft User:
    SM11
    I have I just don't understand this, I tried using the Cactus Collision but when I tested it didn't do anything
  10. GmWM
    Offline

    GmWM Active Member Plugin Developer

    Joined:
    Sep 8, 2013
    Posts:
    181
    Plugins:
    3
  11. SM11
    Offline

    SM11 Active Member

    Joined:
    Jun 21, 2015
    Posts:
    117
    Minecraft User:
    SM11
    You know what, Instead of helping your just trying to repeat yourself you ignorant man, I have learned PHP and If something is wrong why not just help me,
  12. GmWM
    Offline

    GmWM Active Member Plugin Developer

    Joined:
    Sep 8, 2013
    Posts:
    181
    Plugins:
    3
    Because you will not understand from my help my friend, if you don't know what you're doing. :)
  13. SM11
    Offline

    SM11 Active Member

    Joined:
    Jun 21, 2015
    Posts:
    117
    Minecraft User:
    SM11
    I know what I'm doing I just don't understand how PlayerMovement has anything to do with this.
  14. SM11
    Offline

    SM11 Active Member

    Joined:
    Jun 21, 2015
    Posts:
    117
    Minecraft User:
    SM11
    I tried it and this came up when I swim in water
    [CRITICAL] "Could not pass event 'pocketmine\event\player\PlayerMoveEvent' to 'WaterDamage v1.0.0': Undefined variable: player on SM11\WaterDamage\Main

    11:08:42[NOTICE] UndefinedVariableException: "Undefined variable: player" (E_NOTICE) in "/WaterDamage/src/SM11/WaterDamage/Main" at line 26
  15. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Ok look:
    attack ($damage, $source=EntityDamageEvent::CAUSE_MAGIC);
    if you put nothing in second paramater then it will work. But if you do you must do it properly
    PHP:
    public function onMove(PlayerMoveEvent $event){
    $player $event->getPlayer();
    foreach(
    $player->getBlocksAround() as $block){
    if(
    $block->getId() === Block::CACTUS$player->attack(1, new EntityDamageEvent($player/*ATTACKER*//*CAUSE_CONTACT*/1/*DAMAGE*/));
    }
    }
    }
  16. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    It is the victim not the attacker..

    And please use the constants instead of their values like 0 and 1. The values can be changed anytime.
    Primus likes this.
  17. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Wass planing to but screwed up somewhere :D
    Victim, that make sense
  18. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    It not only makes sense, that's contradictory if you don't. EntityDamageEvent only means an entity gets hurt. If you someone gets hurt, you are only interested in who it is, what type of damage it is and how seriously it hurts. You wouldn't presume there is an attacker. Maybe that person simply tripped himself.
    EntityDamageByEntityEvent is an extension of EntityDamageEvent. It states that there is some attacker, and therefore you will also know who the attacker is.
  19. SM11
    Offline

    SM11 Active Member

    Joined:
    Jun 21, 2015
    Posts:
    117
    Minecraft User:
    SM11
    one question Do I replace the attacker with Victim
  20. SM11
    Offline

    SM11 Active Member

    Joined:
    Jun 21, 2015
    Posts:
    117
    Minecraft User:
    SM11
    So Then What Would I change

Share This Page

Advertisement