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

Multi Commands ,

Comments in 'Plugin Development' started by BukkitPE, May 11, 2014.

  1. BukkitPE
    Offline

    BukkitPE Banned

    Joined:
    May 11, 2014
    Posts:
    15
    Minecraft User:
    MINEMASTER_28
    I want to make a plugin witht he following commands...

    /talk
    /talk hi
    /talk bye
    /talk why

    and they all send a message to the user , can somebody make that code for me with comments on how i can add more /talks ,

    BTW: talk isnt gonna be the command im gonna change it !
  2. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,130
    Plugins:
    4
    Minecraft User:
    iksaku
    $args
    Darunia18 likes this.
  3. BukkitPE
    Offline

    BukkitPE Banned

    Joined:
    May 11, 2014
    Posts:
    15
    Minecraft User:
    MINEMASTER_28
    Can u make an example , Just starting ! sorry : )
  4. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,429
    Plugins:
    14
    Don't claim it as your own. People who do that get banned.

    PHP:
    <?php

    /*
    __PocketMine Plugin__
    name=Talk
    version=1.0
    author=LDX
    class=Talk
    apiversion=12
    */

    class Talk implements Plugin {

    private 
    $api;
    public function 
    __construct(ServerAPI $api$server false) {
    $this->api $api;
    }

    public function 
    init() {
    $this->api->console->register("talk","Description",array($this,"talk"));
    }

    public function 
    __destruct() {}

    public function 
    talk($cmd,$args,$issuer) {
      if(isset(
    $args[0])) {
        switch(
    $args[0]) {
          case 
    "hi":
            
    $msg "Hi!";
          break;
          case 
    "bye":
            
    $msg "Bye!";
          break;
          case 
    "why":
            
    $msg "Why?";
          break;
          default:
            
    $msg "[Unknown]";
          break;
        }
        
    $this->api->chat->broadcast("<" $issuer->username "> " $msg);
      } else {
        return 
    "[Talk] Please specify something to say.";
      }
    }

    }
    ?>
    Last edited: May 12, 2014
    MegaSamNinja likes this.
  5. BukkitPE
    Offline

    BukkitPE Banned

    Joined:
    May 11, 2014
    Posts:
    15
    Minecraft User:
    MINEMASTER_28
    Ik , when dealing with arrays , it must have default

    but what will this do ?
    default:
    $msg = "[Unknown]";
    break;
  6. iJoshuaHD
    Offline

    iJoshuaHD Notable Member Plugin Developer

    Joined:
    Nov 7, 2013
    Posts:
    1,196
    Plugins:
    4
    Minecraft User:
    iJoshuaHD
    those cases that cant be find in the code above will return the unknown message.
  7. BukkitPE
    Offline

    BukkitPE Banned

    Joined:
    May 11, 2014
    Posts:
    15
    Minecraft User:
    MINEMASTER_28
    Question , how would i make it a line that will run a command for the issuser ?> like $this->api->console(setprefix,"NewBie",$issuser) ? is it like thth
  8. BukkitPE
    Offline

    BukkitPE Banned

    Joined:
    May 11, 2014
    Posts:
    15
    Minecraft User:
    MINEMASTER_28
    How do u display kills and deaths ?
  9. Anton Magsino
    Offline

    Anton Magsino Active Member

    Joined:
    Jan 17, 2014
    Posts:
    58
    Minecraft User:
    MinecrafterPH
    PHP:
            $username $issuer->username;
    PHP:
            $this->api->console->run("setprefix NewBie $username");
    BukkitPE likes this.
  10. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,429
    Plugins:
    14
    No, he had it right before... Sort of.
  11. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,429
    Plugins:
    14
    PHP:
    $this->api->console->run("setprefix NewBie",$issuer);
  12. BukkitPE
    Offline

    BukkitPE Banned

    Joined:
    May 11, 2014
    Posts:
    15
    Minecraft User:
    MINEMASTER_28
    So , i was almost there , thank you ! Your plugin above helped me undertsand plugin making even more ! You guys are the best ! I love you LDX <3 :*
    LDX likes this.
  13. BukkitPE
    Offline

    BukkitPE Banned

    Joined:
    May 11, 2014
    Posts:
    15
    Minecraft User:
    MINEMASTER_28
    So i can do this , BTW , i changed your code a bit because it brodcasted it to the server , and i wanted it to go to the player only so will this work ?
    Code:
      case "V.I.P":
            $this->api->chat->sendTo(false, "[V.I.P] Prefix \n 1 kit \n 5 diamonds ! \n Price: 3$", $player);
        $this->api->console->run("setprefix NewBie",$issuer);
          break;
    
    I just added it there as an EX:
  14. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,429
    Plugins:
    14
    Return is better.

    PHP:
    case "V.I.P":
    return 
    "[V.I.P]Prefix \n 1 kit\n 5 diamonds ! \n Price: 3$";
    $this->api->console->run("setprefix NewBie",$issuer);
    break;
  15. BukkitPE
    Offline

    BukkitPE Banned

    Joined:
    May 11, 2014
    Posts:
    15
    Minecraft User:
    MINEMASTER_28
    PHP:
    case "Farmer":
    return 
    "[Prefixer] Your prefix is now "Farmer";
    $this->api->console->run("setprefix Farmer",$issuer);
    break;
    So that is what it will do , is it ok if i finish the code for this plugin and upload it , but give u credit ! if so thank you ! , also thanks for the help agn your a pro , where did u learn the PocketMine API , because i cant learn by reading the API files , im looking at http://docs.pocketmine.net/ but i think that that is for the new API !
    LDX likes this.
  16. BukkitPE
    Offline

    BukkitPE Banned

    Joined:
    May 11, 2014
    Posts:
    15
    Minecraft User:
    MINEMASTER_28
    The only thing i need to add is a KD counter ! for /stats
    PHP:
    //Cant i do this ?
    private $kills;
    //blah blah
    return " You have " $kills " Kills "
  17. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,429
    Plugins:
    14
    You must escape quotes.

    PHP:
    case "Farmer":
    return 
    "[Prefixer] Your prefix is now \"Farmer\"";
    $this->api->console->run("setprefix Farmer",$issuer);
    break;
  18. BukkitPE
    Offline

    BukkitPE Banned

    Joined:
    May 11, 2014
    Posts:
    15
    Minecraft User:
    MINEMASTER_28
    Opps , that was my fault ! lol , mini but big prob ! Thanks may i upload it when im finished ?
  19. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,429
    Plugins:
    14
    It might be better to use a class-wide variable, like this. And when putting variables between quotes, put periods between them.

    PHP:
    $this->kills[$issuer->username] = "";
    return 
    "You have " $this->kills[$issuer->username] . " kills";
  20. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,429
    Plugins:
    14
    Sure. :)

Share This Page

Advertisement