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

Solved Umm... I have no idea how to explain this...

Comments in 'Plugin Development' started by minebuilder0110, Feb 18, 2016.

  1. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    When you are using some basic functions, you can do $player->kill(). However, in the function kill() itself, how do they know which player to kill? I mean, if you wrote:
    $player->kill()
    $p->kill()
    $thisguy->kill()
    $someone->kill()
    (Where $player, $p, $thisguy and $someone is a valid player, silly.)
    the plugin will still recognise these variables, and how do I make a functions so that it can be used through:
    $player->doSomething()
    Instead of writing:
    $this->doSonething($player)
    ?
    Sorry for being vague, I only have extremely basic knowledge of PHP and programming in general. I can explain to you what I want to know if you need more information on what I am trying to say.
    #TheseKindOfNoobs
  2. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    There is no way, you just need to edit Pocketmine's source on Player.php, you can't create functions on a class while you're on another class.
    applqpak, PEMapModder and Vaivez66 like this.
  3. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    $this->xxx() calls to function xxx() in your own class. This is what "$this" means - your own class, the current running instance.
    This is not JavaScript. You cannot add methods to a class not defined by yourself. Well, it is actually possible by PlayerCreationEvent, but unless it is very necessary, avoid using it in public plugins that have the chance to be used with other plugins.
    However, if you use a structure like player sessions, it will be possible to call, like, $session->xxx(), where $session is an instance of a class defined by your plugin that has an instance for each player. However, you need to be familiar with object-oriented programming to do this. Remember, object-oriented programming wasn't designed to let you type $object->fx() rather than $this->fx($object).
  4. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    Again... Long sentences :p
  5. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    The only way you could do $player->yourFunction() is if yourFunction() exists in the pocketmine\Player class itself. Meaning you would have to edit pocketmine's source code and add your function to the Player class.
    You should learn OOP (Object oriented programming) then you would understand what @PEMapModder is saying, if you don't already.
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Nope, it can be done by extending Player + handling PlayerCreationEvent. But this is just a little bit better than modifying PocketMine source. Still bad for public plugins.
    Hotshot_9930 and Legoboy0215 like this.
  7. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    That was very helpful. Thank you.

Share This Page

Advertisement