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

onplayerlogin help

Comments in 'Plugin Development' started by underfined_, Aug 27, 2015.

  1. underfined_
    Offline

    underfined_ New Member

    Joined:
    Aug 25, 2015
    Posts:
    14
    Minecraft User:
    underfined_
    Hello!
    I have a question: what i must put here instead $event?
    $this->onPlayerLogin($event/*←here←*/)->getPlayer();
  2. hoyinm14mc
    Offline

    hoyinm14mc Notable Member Plugin Developer

    Joined:
    Jun 4, 2014
    Posts:
    501
    Plugins:
    9
    Minecraft User:
    hoyinm14mc
    Learn PHP and PocketMine API.
  3. basprohop
    Offline

    basprohop Active Member Plugin Developer

    Joined:
    Aug 8, 2015
    Posts:
    128
    Plugins:
    3
    Minecraft User:
    basprohop
    To be honest these type of posts don't help anyone. Perhaps you could point him in the right direction

    "Hi, take a look at the PocketMine docs for Player Events: http://docs.pocketmine.net/de/d7b/namespacepocketmine_1_1event_1_1player.html "
    Something like that would be more useful for someone searching the forum for the same question and for the person who asked the question in the first place.
  4. xFlare
    Offline

    xFlare Active Member Plugin Developer

    Joined:
    Sep 28, 2014
    Posts:
    199
    Plugins:
    1
    Minecraft User:
    xFlare
    I'm not sure what you are asking, but if I do understand correctly, I think this is what you mean:
    Code:
    public function onJoin(PlayerJoinEvent $event){ //You can replace this with part with any event. Don't use PreLoginEvent.
        $player = $event->getPlayer();
    } 
  5. hoyinm14mc
    Offline

    hoyinm14mc Notable Member Plugin Developer

    Joined:
    Jun 4, 2014
    Posts:
    501
    Plugins:
    9
    Minecraft User:
    hoyinm14mc
    In the past when someone post questions, @PEMapModder told them to learn PocketMine API.. Same...
  6. hoyinm14mc
    Offline

    hoyinm14mc Notable Member Plugin Developer

    Joined:
    Jun 4, 2014
    Posts:
    501
    Plugins:
    9
    Minecraft User:
    hoyinm14mc
    addition: register the events in the onEnable() method of your main class
    xFlare likes this.
  7. underfined_
    Offline

    underfined_ New Member

    Joined:
    Aug 25, 2015
    Posts:
    14
    Minecraft User:
    underfined_
    I am already learning it
    hoyinm14mc likes this.
  8. hoyinm14mc
    Offline

    hoyinm14mc Notable Member Plugin Developer

    Joined:
    Jun 4, 2014
    Posts:
    501
    Plugins:
    9
    Minecraft User:
    hoyinm14mc
    And see more examples other than the ExamplePlugin, e.g. Have a look at @LegendsOfMCPE 's Github and their plugins can be good example
  9. underfined_
    Offline

    underfined_ New Member

    Joined:
    Aug 25, 2015
    Posts:
    14
    Minecraft User:
    underfined_
    I must use onPlayerLogin
    And i like to call this function from another, like that:
    function sampleFunction(){
    $p = $this->onPlayerLogin($event//dont know what put here//)->getPlayer));
    }
    function onPlayerLogin(PlayerLoginEvent $event){

    }
  10. hoyinm14mc
    Offline

    hoyinm14mc Notable Member Plugin Developer

    Joined:
    Jun 4, 2014
    Posts:
    501
    Plugins:
    9
    Minecraft User:
    hoyinm14mc
    To get the player object when they login, should be
    PHP:
    PlayerLoginEvent::getPlayer()
  11. underfined_
    Offline

    underfined_ New Member

    Joined:
    Aug 25, 2015
    Posts:
    14
    Minecraft User:
    underfined_
    I get an error by using that code:
    $p = PlayerLoginEvent::getPlayer();
  12. hoyinm14mc
    Offline

    hoyinm14mc Notable Member Plugin Developer

    Joined:
    Jun 4, 2014
    Posts:
    501
    Plugins:
    9
    Minecraft User:
    hoyinm14mc
    No, not just copying, you have to understand. That's the concept and not the code to use.
  13. underfined_
    Offline

    underfined_ New Member

    Joined:
    Aug 25, 2015
    Posts:
    14
    Minecraft User:
    underfined_
    Can you tell me what i must to do to make this code working?
    I dont understand.
    It says "Non-static method"
  14. hoyinm14mc
    Offline

    hoyinm14mc Notable Member Plugin Developer

    Joined:
    Jun 4, 2014
    Posts:
    501
    Plugins:
    9
    Minecraft User:
    hoyinm14mc
    1. register events in the onEnable() method
    2. e.g.PlayerLoginEvent
    PHP:
    public function onLogin(PlayerLoginEvent $event){
        
    $player $event->getPlayer();
        
    //code
    }
  15. underfined_
    Offline

    underfined_ New Member

    Joined:
    Aug 25, 2015
    Posts:
    14
    Minecraft User:
    underfined_
    Already heave this code, nothing changed.
    I cant use PlayerLoginEvent::getPlayer(), it says "Non-static method..."
  16. hoyinm14mc
    Offline

    hoyinm14mc Notable Member Plugin Developer

    Joined:
    Jun 4, 2014
    Posts:
    501
    Plugins:
    9
    Minecraft User:
    hoyinm14mc
    PHP:
    public function onLogin(PlayerLoginEvent $e){
        
    $p $e->getPlayer();
    }
  17. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    In the class PlayerLoginEvent, getPlayer() is not a static method. :p
  18. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Asking people to show you how to make the code work is completely useless, unless you actually understand the code. But it appears that you're too lazy to even bother trying to understand, and you are just blindly copying the code that people give you(without understanding how it works). So please, learn PHP and the PocketMine API.
  19. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    That only means that you are using that function. He didn't say it's static.
    hoyinm14mc likes this.
  20. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Read closely. The guy who was asking him asked for the code(the exact code), not how to use the function.

Share This Page

Advertisement