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

Need Help With Code

Comments in 'Plugin Development' started by Adrian, Jun 28, 2014.

  1. PluginMastered
    Offline

    PluginMastered Active Member

    Joined:
    Mar 1, 2014
    Posts:
    161
    Minecraft User:
    Flexa33
    I actually tried doing this but I had no success do too it never ranked up the player and took money away from their bank :(
  2. Adrian
    Offline

    Adrian Active Member

    Joined:
    Jun 26, 2014
    Posts:
    64
    Minecraft User:
    Adrian
    Did you use a rank plugin, and actually set it to rank them up?
  3. Adrian
    Offline

    Adrian Active Member

    Joined:
    Jun 26, 2014
    Posts:
    64
    Minecraft User:
    Adrian
    Going to test mine :D
  4. Adrian
    Offline

    Adrian Active Member

    Joined:
    Jun 26, 2014
    Posts:
    64
    Minecraft User:
    Adrian
    Ok almost finished testing!
  5. iFootball
    Offline

    iFootball Active Member

    Joined:
    Jun 9, 2014
    Posts:
    84
    Minecraft User:
    iFootball
    We'll I thought you were using PocketMoney, but this isn't complete still fixing out some errors and it won't work yet, but this is how it will work. I completly re-did it, and told you what I'd did. And yes I see the $money announcemnt isn't correct.
    PHP:
    <?php

    /*
    __PocketMine Plugin__
    name=MoneyRankUp
    version=1.0
    description=When you do "/rankup" you get rank "A" if you have 10000 PM's.
    author=iFootball, made for Adrian.
    class=MoneyRankUp
    apiversion=12
    */

    class MoneyRankUp implements Plugin{

    private 
    $api;

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

    public function 
    init(){
    //Thie receives data from the PocketMoney plugin, this will be used to figure out the players money, and retract it from their account.
    if (file_exists(DATA_PATH."plugins/PocketMoney.php")) {
                
    $this->config['moneyplugin'] = self::CONFIG_POCKETMONEY;
            }
    $this->api->console->register("rankup","ranks you up",array($this"rankup"));
    $this->api->ban->cmdWhitelist("rankup");
    }

    public function 
    rankup($cmd$issuer){
    $username $issuer->username;
    $money PocketMoney::getMoney($issuer);
    //This retrieves the players money from the config
        
    if ($money >= 10000) {
        
    //This says if the players money is larger then 10000
        
    $this->api->console->run("rmgr sr " $username,"A");
        
    //Before you were having the console run "pay bank 10000" instead of the player, this runs it as the player.
        
    $this->api->console->run("sudo " $username "pay bank 10000");
        
    //Tells the player this messege
        
    $username->sendChat("You have payed 10000 to rank up! You are now rank A!");
        
    //Tells the hole server this messege.
        
    $this->api->chat->broadcast("[RankUp] $username has ranked-up to rank A!");
        }
        else {
        
    //If they don't have enough money it will say:
        
    $username->sendChat("You do not have enough money to buy this rank. You need $money to rank up.");
      
    }
    }
    public function 
    __destruct(){
    }
    }
    ?>
    Last edited: Jun 29, 2014
    Adrian likes this.
  6. Adrian
    Offline

    Adrian Active Member

    Joined:
    Jun 26, 2014
    Posts:
    64
    Minecraft User:
    Adrian
    Wow, thanks for this plugin. I'll download PocketMoney :D
  7. iFootball
    Offline

    iFootball Active Member

    Joined:
    Jun 9, 2014
    Posts:
    84
    Minecraft User:
    iFootball
    Remember it still doesn't work yet, right now I need to fix a couple errors
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    self::CONFIG_POCKETMONEY?
  9. Adrian
    Offline

    Adrian Active Member

    Joined:
    Jun 26, 2014
    Posts:
    64
    Minecraft User:
    Adrian
    I Know!

    Thank You very much!!!!!!!!!! :D :D
  10. iFootball
    Offline

    iFootball Active Member

    Joined:
    Jun 9, 2014
    Posts:
    84
    Minecraft User:
    iFootball
    Is is a update still doesn't work yet, I have worked out the main errors, but the server still crashes when you run the command. Their is no dump file, or error message created. Here's the updated code.
    PHP:
    <?php

    /*
    __PocketMine Plugin__
    name=MoneyRankUp
    version=1.0
    description=When you do "/rankup" you get rank "A" if you have 10000 PM's.
    author=iFootball, made for Adrian.
    class=MoneyRankUp
    apiversion=12
    */

    class MoneyRankUp implements Plugin{

    const 
    CONFIG_POCKETMONEY 0b01;

    private 
    $api;

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

    public function 
    init(){
    //Thie receives data from the PocketMoney plugin, this will be used to figure out the players money, and retract it from their account.
    if (file_exists(DATA_PATH."plugins/PocketMoney.php")) {
    $this->api->console->register("rankup","ranks you up",array($this"rankup"));
    $this->api->ban->cmdWhitelist("rankup");
    }
    }
    public function 
    rankup($cmd$issuer){
    $username $issuer->username;
    10000-$money=$amount;
    $money PocketMoney::getMoney($issuer);
    //This retrieves the players money from the config
        
    if ($money >= 10000) {
        
    //This says if the players money is larger then 10000
        
    $this->api->console->run("rmgr sr " $username,"A");
        
    //Before you were having the console run "pay bank 10000" instead of the player, this runs it as the player.
        
    $this->api->console->run("sudo " $username "pay bank 10000");
        
    //Tells the player this messege
        
    $issuer->sendChat("You have payed 10000 to rank up! You are now rank A!");
        
    //Tells the hole server this messege.
        
    $this->api->chat->broadcast("[RankUp] $username has ranked-up to rank A!");
        }
        else {
        
    //If they don't have enough money it will say:
        
    $issuer->sendChat("You do not have enough money to buy this rank. You need $amount to rank up.");
       
    }
    }
    public function 
    __destruct(){
    }
    }
    ?>
    Adrian likes this.
  11. Adrian
    Offline

    Adrian Active Member

    Joined:
    Jun 26, 2014
    Posts:
    64
    Minecraft User:
    Adrian
    Ok, I'll try to figure out error :D

    What is

    Const CONFIG_POCKETMONEY = 0b01;
    PEMapModder likes this.
  12. Adrian
    Offline

    Adrian Active Member

    Joined:
    Jun 26, 2014
    Posts:
    64
    Minecraft User:
    Adrian
    What is a "for" loop? Thanks :D :D
  13. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Learn PHP.
    Darunia18 likes this.
  14. Adrian
    Offline

    Adrian Active Member

    Joined:
    Jun 26, 2014
    Posts:
    64
    Minecraft User:
    Adrian
    I went to code academy and can't find where it teaches that. I learned rest of php.
  15. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    for loop is so basic. Read everything if you can't guess; or read tutorials of for loops in other languages.
  16. PluginMastered
    Offline

    PluginMastered Active Member

    Joined:
    Mar 1, 2014
    Posts:
    161
    Minecraft User:
    Flexa33
    here:
    Code:
    <?php
    for ($x=0; $x<=10; $x++) {
       echo "The number is: $x <br>";
    }
    ?>
    
    <--- is and example and here is how to :
    PHP:
    for (init countertest counterincrement counter) {
       
    code to be executed;
    http://www.w3schools.com/php/php_looping_for.asp
  17. Adrian
    Offline

    Adrian Active Member

    Joined:
    Jun 26, 2014
    Posts:
    64
    Minecraft User:
    Adrian
    Thank You! :D :D
  18. PluginMastered
    Offline

    PluginMastered Active Member

    Joined:
    Mar 1, 2014
    Posts:
    161
    Minecraft User:
    Flexa33
    np :D !
  19. iFootball
    Offline

    iFootball Active Member

    Joined:
    Jun 9, 2014
    Posts:
    84
    Minecraft User:
    iFootball
    Its Constructing the PocketMoney config and telling this plugin what to look for in the PocketMoney code.
  20. PluginMastered
    Offline

    PluginMastered Active Member

    Joined:
    Mar 1, 2014
    Posts:
    161
    Minecraft User:
    Flexa33
    the plugin isn't working because idk why but you cant run multiple commands in one command for some reason :( I tried this for my youtuber so they could do /youtuber but it didn't give them their items :(

Share This Page

Advertisement