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

Run a command as a player

Comments in 'Plugin Development' started by DopeteK, May 4, 2014.

  1. DopeteK
    Offline

    DopeteK Active Member

    Joined:
    Aug 24, 2013
    Posts:
    393
    Minecraft User:
    DTeK
    I have developed a plugin that allows a predefined command to be run when a player stands on a predefined block.
    The command currently runs as the console but I would like it to run as the player that activates it. How can I do this?

    Here is the line that runs the command as the console:

    $command = $this->api->console->run (COMMAND);


    The original code came from Darunia18s Claymores plugin with his permission. <3
    MegaSamNinja likes this.
  2. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,707
    Plugins:
    22
    Minecraft User:
    Falkirknh
    $p is a player object.
    PHP:
    $this->api->console->run("command",$p); 
    DopeteK likes this.
  3. DopeteK
    Offline

    DopeteK Active Member

    Joined:
    Aug 24, 2013
    Posts:
    393
    Minecraft User:
    DTeK
    [ERROR] A level 8 error happened: "Undefined variable: p" in "C:\Users\root\Desktop\PocketMine- MP PvP Maze - Copy\plugins\CMDBlock.php" at line 30

    The line you gave me is all that is on line 30
  4. DopeteK
    Offline

    DopeteK Active Member

    Joined:
    Aug 24, 2013
    Posts:
    393
    Minecraft User:
    DTeK
    And the command is already defined in a yml file. It still runs the command but as the console and also gives the undefined variable: p error.
  5. sekjun9878
    Offline

    sekjun9878 Staff Member PocketMine Team

    Joined:
    Aug 22, 2013
    Posts:
    108
    Plugins:
    1
    Minecraft User:
    sekjun9878
    Of course it gives the "$p is undefined" error. You never assigned anything to it.
    $p must be an instance of Player.

    You should probably ask an actual PHP developer to do this for you.
    DopeteK likes this.
  6. DopeteK
    Offline

    DopeteK Active Member

    Joined:
    Aug 24, 2013
    Posts:
    393
    Minecraft User:
    DTeK
    I am trying to learn :( I figured I needed to define %p as a player and am looking at other plugins to see how it is done. Any help would be appreciated. :D
  7. sekjun9878
    Offline

    sekjun9878 Staff Member PocketMine Team

    Joined:
    Aug 22, 2013
    Posts:
    108
    Plugins:
    1
    Minecraft User:
    sekjun9878
    PHP:
    $p $this->api->player->get("username");
    $this->api->console->run("command",$p);
    LDX, Falk and DopeteK like this.
  8. DopeteK
    Offline

    DopeteK Active Member

    Joined:
    Aug 24, 2013
    Posts:
    393
    Minecraft User:
    DTeK
    So I can define a variable directly above it?
  9. DopeteK
    Offline

    DopeteK Active Member

    Joined:
    Aug 24, 2013
    Posts:
    393
    Minecraft User:
    DTeK
    I had to change it a little as the command is already defined but I am still getting [DEBUG] * issued server command: tp 10 10 10

    PHP:
        public function entitymove($data){
            
    $activate $data->level->getBlock(new Vector3($data->x, ($data->-1), $data->z));
            if(
    $activate->getID() == ACTIVATE){
                
    $p $this->api->player->get("username");
                
    $this->api->console->run(COMMAND,$p); 
    I am very proud of myself to have got this far though. Am i allowed to post the whole plugin in order to get a real developer to help?

    And thanks for your help.
  10. Darunia18
    Offline

    Darunia18 Staff Member Sectional Moderator

    Joined:
    Aug 23, 2013
    Posts:
    755
    Plugins:
    2
    Minecraft User:
    Darunia18
    Yep! :D By the way, if you haven't already, try looking into PHP tutorials on codecademy.com and at @Glitchmaster_PE's plugin tutorials on here ;)
    DopeteK likes this.
  11. DopeteK
    Offline

    DopeteK Active Member

    Joined:
    Aug 24, 2013
    Posts:
    393
    Minecraft User:
    DTeK
    I will do that in the morning. Thanks

Share This Page

Advertisement