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

stuck O_o

Comments in 'Plugin Development' started by zombie_Power, Oct 2, 2015.

  1. zombie_Power
    Offline

    zombie_Power Active Member

    Joined:
    Sep 7, 2015
    Posts:
    239
    Minecraft User:
    Zombie_Power
    hey guys, so I am trying to create a basic plugin (private), where $n is the killer and $s is the person who died
    PHP:
    $this->getServer()->broadcastMessage($n "killed" $s);
    but I am a little unsure how to define $n and $s, I am currently stuck at (I have already define $player):
    PHP:
    $n $player->getName();
    $s $player->getName();
    Sorry I am still learning Pocketmine API and Thanks for the help :)
    Last edited: Oct 3, 2015
  2. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    How should $n and $s be different Players as you define it with the same name?
    PianoPlayer38 and HotFireyDeath like this.
  3. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    Maybe get the last damage cause and get player from it? I have seen quite a lot of examples on the forum.
    Legoboy0215 likes this.
  4. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    PHP:
    public function onDeath(PlayerDeathEvent $event) {
            
    $player $event->getEntity();
            if (
    $player instanceof Player) {
                if (
    $cause instanceof EntityDamageByEntityEvent) {
                    
    $killer $cause->getDamager();
                    if (
    $killer instanceof Player) {
                        
    $name $killer->getName();
                        
    $killer->sendPopup("Killed " $player->getName());
                        
    $player->sendMessage("You've been killed by " $name);
                    }
                }
            }
        }
    Configure that as you want.
  5. FlamingGenius
    Offline

    FlamingGenius Active Member

    Joined:
    Sep 23, 2015
    Posts:
    173
    Minecraft User:
    FlamingGenius
    You u post a code you should provide an explanation
  6. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Why so? He says he doesn't know how to define them, he's not asking for any explanation of PlayerDeathEvent or EntityDamageEvent. If he knows PHP and the PM-API, he will understand it. And if I would post the correct code, he will just copy and paste.
    PianoPlayer38 likes this.
  7. FlamingGenius
    Offline

    FlamingGenius Active Member

    Joined:
    Sep 23, 2015
    Posts:
    173
    Minecraft User:
    FlamingGenius
    What about people who view this thread in the future
  8. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    They'll have to learn it like everyone else
    PianoPlayer38 likes this.
  9. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Good job, you gave him wrong code. $cause is undefined. It should be:
    PHP:
    public function onDeath(PlayerDeathEvent $event) {
            
    $player $event->getEntity();
            if (
    $player instanceof Player) {
                    
    $cause $event->getCause();
                if (
    $cause instanceof EntityDamageByEntityEvent) {
                    
    $killer $cause->getDamager();
                    if (
    $killer instanceof Player) {
                        
    $name $killer->getName();
                        
    $killer->sendPopup("Killed " $player->getName());
                        
    $player->sendMessage("You've been killed by " $name);
                    }
                }
            }
        }
    Not really, you have to use your brain to figure out how it works, not everyone can assist you sometimes. You can't depend on other people to tell you how to do things. EDIT: Code is wrong. Silly me. :p
    Last edited: Oct 3, 2015
    zombie_Power and HotFireyDeath like this.
  10. FlamingGenius
    Offline

    FlamingGenius Active Member

    Joined:
    Sep 23, 2015
    Posts:
    173
    Minecraft User:
    FlamingGenius
    Some people lea best by being taught :/
  11. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Good Job, Master. You found a mistake. I
    accidentally removed it when removing the rest of my code, as that's a part of a bigger plugin. I am sorry, my queen.
    The only problem is, that you gave him wrong code, too. There's no $event->getCause(). It has to be
    PHP:
    $cause $event->getEntity()->getLastDamageCause();
  12. zombie_Power
    Offline

    zombie_Power Active Member

    Joined:
    Sep 7, 2015
    Posts:
    239
    Minecraft User:
    Zombie_Power
    Thanks, I understand everything you have done, however one thing, which is still troubling me, I am unsure of how you got "getEntity" and "getCause".

    Thanks for your help

    EDIT: I am only asking, because I don't want to copy your codes and learn nothing. I have looked through the docs and it only says
    PHP:
    public function getEntity(){
    return 
    $this->entity;
    Last edited: Oct 3, 2015
  13. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Sorry, gramps. I was rushing it.
    I'll give you some links that will help you, but you have to do the thinking on your own. https://github.com/PocketMine/Pocke.../pocketmine/event/player/PlayerDeathEvent.php https://github.com/PocketMine/Pocke...pocketmine/event/entity/EntityDamageEvent.php
    HotFireyDeath and FlamingGenius like this.
  14. zombie_Power
    Offline

    zombie_Power Active Member

    Joined:
    Sep 7, 2015
    Posts:
    239
    Minecraft User:
    Zombie_Power
    PHP:
    public function onEnable(){
        
    $this->getServer()->getPluginManager()->registerEvents($this$this);
       }

    public function 
    onPlayerdeath(PlayerDeathEvent $event) {
            
    $p $event->getEntity();
            if (
    $p instanceof Player) {
               
    $cause $event->getEntity()->getLastDamageCause();
                if (
    $cause instanceof EntityDamageByEntityEvent) {
                    
    $killer $cause->getEntity()->getLastDamageCause();
                    if (
    $killer instanceof Player) {
                        
    $name $killer->getName();
                        
    $p->sendMessage("You've been killed by " $name);
                    }
                    elseif(
    $causeId $p->getLastDamageCause()->getCause());
                        switch(
    $causeId){
         case 
    EntityDamageEvent::CAUSE_DROWNING:
           
    $p->sendPopup("The pirahnas ate you!");
           break;
         case 
    EntityDamageEvent::CAUSE_FALL:
           
    $p->sendPopup("Watch out where you are going!");
           break;
         case 
    EntityDamageEvent::CAUSE_LAVA:
           
    $p->sendPopup("You tried to swim in lava!");
           break;
         case 
    EntityDamageEvent::CAUSE_FIRE:
           
    $p->sendPopup("You burned to death!");
           break;
         case 
    EntityDamageEvent::CAUSE_SUFFOCATION:
           
    $p->sendPopup("Don't try Carbon Dioxide              
           break;
         case EntityDamageEvent::CAUSE_SUICIDE:
          
    $p->sendPopup("You died!");
           break;
         case EntityDamageEvent::CAUSE_CONTACT:
       if(
    $cause instanceof EntityDamageByBlockEvent){
                 if(
    $cause->getDamager()->getId() === Block::DIAMOND_SWORD){
                    
    $killer->sendPopup("killed" . $p->getName());

            }
                }
                break;
            }
    here is the updated code. Can some please check it and the second trouble I am having is with PHP, I am unsure if I can use "&&" after "DIAMOND_SWORD" TO ADD "GOLD_SWORD" or do I need to create another case to put that it and I believe I messed up the part where it states "elseif($causeId = $p.....

    Thanks for your help in Advance
    Last edited: Oct 3, 2015
  15. jojoe77777
    Offline

    jojoe77777 Notable Member Plugin Developer

    Joined:
    May 28, 2015
    Posts:
    653
    Plugins:
    1
    Minecraft User:
    jojoe77777
    • DIAMOND_SWORD is an item, not a block, use Item:DIAMOND_SWORD or 276
    • EntityDamageByBlockEvent is only called when the damage is something like lava or cactus, I think you are looking for EntityDamageByEntityEvent
    Last edited: Oct 3, 2015
  16. zombie_Power
    Offline

    zombie_Power Active Member

    Joined:
    Sep 7, 2015
    Posts:
    239
    Minecraft User:
    Zombie_Power
    Thanks, I couldn't find them, so I thought that I should use "EntityDamageByBlockEvent"
  17. jojoe77777
    Offline

    jojoe77777 Notable Member Plugin Developer

    Joined:
    May 28, 2015
    Posts:
    653
    Plugins:
    1
    Minecraft User:
    jojoe77777
    Oh, and use
    PHP:
    if($cause->getDamager()->getId() === Item::DIAMOND_SWORD || $cause->getDamager()->getId() === Item::GOLD_SWORD || $cause->getDamager()->getId() === Item:IRON_SWORD)
    etc...
  18. zombie_Power
    Offline

    zombie_Power Active Member

    Joined:
    Sep 7, 2015
    Posts:
    239
    Minecraft User:
    Zombie_Power
    Thanks! I was confused if I could use && or || in conditional statements, btw I believe there is something wrong here
    PHP:
           
                        $name 
    $killer->getName();
                        
    $p->sendMessage("You've been killed by " $name);
                    }
                    elseif(
    $causeId $p->getLastDamageCause()->getCause());
                        switch(
    $causeId){
         
  19. jojoe77777
    Offline

    jojoe77777 Notable Member Plugin Developer

    Joined:
    May 28, 2015
    Posts:
    653
    Plugins:
    1
    Minecraft User:
    jojoe77777
    Yup, that "else if" isn't doing anything, replace the ; with {, and at the end of that code, put a }
  20. zombie_Power
    Offline

    zombie_Power Active Member

    Joined:
    Sep 7, 2015
    Posts:
    239
    Minecraft User:
    Zombie_Power
    so then I need to change elseif with if to make it work?

Share This Page

Advertisement