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

I want some codes

Comments in 'Plugin Development' started by KHAV, Aug 7, 2016.

  1. KHAV
    Offline

    KHAV New Member

    Joined:
    Aug 7, 2016
    Posts:
    35
    Minecraft User:
    KHAV
    Hello Guys

    I want code change the death message

    With use i want to change but i don't the code

    And i want code sound for event with use

    :)
  2. andre_the_gamer
    Offline

    andre_the_gamer Active Member

    Joined:
    Feb 5, 2015
    Posts:
    112
    Minecraft User:
    Andre_The_Gamer
    Take a look here!
  3. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    Change death message:
    PHP:
    use pocketmine\event\player\PlayerDeathEvent;

    public function 
    onDeath(PlayerDeathEvent $event){
    $event->setDeathMessage();
    // now you can set the message

    // to add sound
    // $player is the player who should hear it
    $level->addSound(new FizzSound($player->getLocation()));

    }
    Survingo likes this.
  4. MCPEPIG
    Offline

    MCPEPIG Notable Member

    Joined:
    Jun 22, 2014
    Posts:
    349
    Minecraft User:
    MCPEPIG
    The code you given makes all players near the player hear the sound, $player & $level are undefined, & you didnt import FizzSound. Also, the Player class is instanceof Vector3. :p Correct code:
    PHP:
    use pocketmine\event\player\PlayerDeathEvent;
    use 
    pocketmine\level\sound\FizzSound;

    public function 
    onDeath(PlayerDeathEvent $event){
       
    $player $event->getEntity();
       
    $level $player->getLevel();
       
    $event->setDeathMessage($player->getName() . " died");
       
    $level->addSound(new FizzSound($player), [$player]);
    }
    Last edited: Aug 10, 2016
  5. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    It's 06:04 at the moment, it's bad time outside and this was the only thing that made me smile today :D
    Survingo likes this.
  6. EntirelyQuartz
    Offline

    EntirelyQuartz New Member

    Joined:
    Aug 9, 2016
    Posts:
    15
    Minecraft User:
    EntirelyQuartz
    This post isn't complying the new posting requeriments written by @iamadpond.

    https://forums.pocketmine.net/threads/new-posting-requirement-read.17843/

    1. Argument 2 given to addSound must be an array, Player instance was given.
    PHP:
    public function addSound(Sound $sound, array $players null)
    2. Why did you store $player->getLevel() into a variable? If you're going to use it only one time it's totally unnecessary.

    Also, instead
    PHP:
    $player->getName() . "died"
    you can use
    PHP:
    "{$player->getName()} died"
    to increase the readablity.

    NOTE: Actually, your code is going to return Usernamedied instead Username died (assuming $player->getName() returns Username).
    Last edited: Aug 10, 2016
  7. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    PHP:
    $event->setDeathMessage($player->getName() . " died");
    You forgot the space :p
  8. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Player::getName() returns a string.
  9. EntirelyQuartz
    Offline

    EntirelyQuartz New Member

    Joined:
    Aug 9, 2016
    Posts:
    15
    Minecraft User:
    EntirelyQuartz
    When I said "Player" I was speaking about a string, not the Player class.
  10. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    You should have mentioned that, it's confusing otherwise
  11. MCPEPIG
    Offline

    MCPEPIG Notable Member

    Joined:
    Jun 22, 2014
    Posts:
    349
    Minecraft User:
    MCPEPIG
    I actually didn't break any :p Ive changed $player to [$player] in addSound function. I used $level cause MyNameIsTrix used it and I was adding on to his code. Also added a space so it says Username died.
    Primus likes this.
  12. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    The last string example with {} is a matter of person preference. For example, I find it easier to read the first example with the dots (Sorry, I forgot how you spell it)
  13. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Concatenation
  14. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    Side note: Using the string concatenation operator rather than the in-string variable substitutions is slightly faster, but it is premature optimization at the cost of code readability.
  15. TheDeibo
    Offline

    TheDeibo Notable Member

    Joined:
    Sep 8, 2014
    Posts:
    693
    Minecraft User:
    TheDeibo

Share This Page

Advertisement