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

Has to work?!

Discussion in 'Plugin Help' started by M4nt0s, Mar 15, 2017.

  1. M4nt0s

    M4nt0s Spider Jockey

    Messages:
    31
    GitHub:
    M4nt0s
    public function onPlayerRespawn(PlayerRespawnEvent $event) {
    $player = $event->getPlayer() {
    $sender->getInventory()->addItem(Item::get(364,0,4));
    $sender->sendMessage("You have just recieved 4 steak!");
     
  2. TheDiamondYT

    TheDiamondYT Zombie

    Messages:
    298
    GitHub:
    TheDiamondYT1
    This is completely wrong. Please learn the API by reading through the source and it also looks like you need to learn PHP.

    Here's the fixed code
    PHP:
    public function onPlayerRespawn(PlayerRespawnEvent $event) {
            
    $player $event->getPlayer();
                
    $player->getInventory()->addItem(Item::get(364,0,4));
        
    $player->sendMessage("You have just recieved 4 steak!");
    }
    Alright, lets see what you did wrong
    $sender is not defined. You obviously copied this from a command in another plugin.

    $event->getPlayer() shouldnt have a { after it.

    You need an } at the end.
     
    EdwardHamHam and HimbeersaftLP like this.
  3. M4nt0s

    M4nt0s Spider Jockey

    Messages:
    31
    GitHub:
    M4nt0s
    Ok, thanks. I'm learning it at the moment. Reading and testing all the time. I was confused when I wrote a { after the getPlayer()!!! But I don't unterstand how else I can do it.

    Sry if my English is not the best...
     
  4. xBeastMode

    xBeastMode Shog Chips

    Messages:
    0
    Just one thing: don't give 'fixed' code because they're just gonna copy-paste and they will never learn. Additionally, this is the wrong section and they didn't read the guidelines.
     
  5. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    Every five year old should know that you can't do stuff with something that doesn't exist (I'm talking about the undefined $sender), though...
     
    TheDiamondYT likes 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.