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

PayCheck plugin, almost got it..i think

Comments in 'Plugin Development' started by dxm_hippie, Apr 15, 2015.

  1. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    So i thought for sure i would have got this one right my first try..but once again like my first plugin it does nothing lol i think im close tho. Basically this plugin will give selected people (staff) money at set intervals for time spent on the server only, i believe the problem is in here..I dont think i have it finding the player right.

    PHP:
    public function onSchedule(){
            if(
    $this->economy == true && $this->config->get("enable") == "true"){
                                    if(
    $this->config->get("player")){
                    if(
    $this->config->get("economy-plugin") == "EconomyAPI") {
                        
    $msg str_replace ($this->config->get("message"));
                        
    $player->sendMessage("$msg");
                        
    $this->getServer()->getPluginManager()->getPlugin("EconomyAPI")->addMoney($player->getName(), $this->config->get("money"));
                        return 
    true;
                    }
                                  }
                    if(
    $this->config->get("economy-plugin") == "PocketMoney") {
                        
    $msg str_replace($this->config->get("message"));
                        
    $player->sendMessage("$msg");
                        
    $this->getServer()->getPluginManager()->getPlugin("PocketMoney")->grantMoney($player->getName(), $this->config->get("money"));
                        return 
    true;
                    }
                    if(
    $this->config->get("economy-plugin") == "MassiveEconomyAPI") {
                        
    $msg str_replace($this->config->get("message"));
                        
    $player->sendMessage("$msg");
                        
    $this->getServer()->getPluginManager()->getPlugin("MassiveEconomyAPI")->payPlayer($player->getName(), $this->config->get("money"));
                        return 
    true;
                                         
                                            }else{
                                             
                    return 
    true;
                }
            }
           }
          }
  2. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    Do you want to do this in a separated task?
  3. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    No..maybe..lol i just found the tutorial for making plugins on a scheduled so i got some reading to do there. But this is what i got so far..
    main php
    PHP:
    namespace CrazyHippie\PayCheck;

    use 
    pocketmine\utils\TextFormat;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\Player;
    use 
    pocketmine\Server;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\scheduler\PluginTask;
    use 
    pocketmine\scheduler\CallbackTask;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\player\PlayerJoinEvent;

    class 
    main extends PluginBase implements listener
       
        public 
    $economy false;
        private 
    $player null;
        public 
    $time 10;
        public 
    $tasks = array();
        private 
    $config;

        public function 
    onEnable(){ 
                    
    $this->getLogger()->info("┬žaEnabling ".$this->getDescription()->getFullName()."...");
            @
    mkdir($this->getDataFolder());

            
    $this->config = new Config($this->getDataFolder()."config.yml"Config::YAML, array(
                
    # ---------------------------
                            # PayCheck
                            # CONFIGURATION FILE
                            # Version 0.1
                            # ---------------------------

                            #Set to false to disable.
                            
    "enable" => "true",
                            
    #Economy plugin you wish to use.
                            
    "economy-plugin" => "EconomyAPI",
                            
    #List of players you wish to pay.
                            
    "player" => "",
                            
    #Time in minutes at witch you wish to pay them.
                            
    "time" => 10,
                            
    #Amount of money to pay.
                            
    "money" => 50,
                            
    #message to send on payment use {name} to get the players name.
                            
    "message" => "Heres your paycheck {PLAYER}",
            ));
           
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
                    if(
    $this->config->get("economy-plugin") == "EconomyAPI"){
                if(
    is_dir($this->getServer()->getPluginPath()."EconomyAPI")){
                    
    $this->getLogger()->info(TextFormat::GREEN."PayCheck successfully loaded with Economy!API");
                    
    $this->economy true;
                }else{
                    
    $this->getLogger()->info(TextFormat::RED."PayCheck not loaded, I can't find EconomyAPI");
                    
    $this->economy false;
                 }
               }
             }
                    public function 
    onDisable(){
            
    $this->getLogger()->info(TextFormat::RED."PayCheck unloaded!");
        }
                    public function 
    onPlayerJoinEvent(PlayerJoinEvent $event$player){  
                    
    $player = ($this->config->get("player"));
                         
    $player->sendMessage("You are now on the clockn\pay check in ".$this->time." time.");
                         return 
    true;
                     }
                     public function 
    onSchedule(){ 
            if(
    $this->economy == true && $this->config->get("enable") == "true"){
                    if(
    $this->config->get("economy-plugin") == "EconomyAPI"){ 
                                            
    $msg $this->getConfig()->get("message");
                                            
    $players $this->getServer()->getOnlinePlayers();
                       foreach(
    $players as $player){
                    if(!(
    $player $this->config->get("player")) !== ""){
                        continue;
                                    }
                        
    $this->getServer()->getPluginManager()->getPlugin("EconomyAPI")->addMoney($player->getName(), $this->config->get("money"));
                                            
    $player->sendMessage("$msg");
                        return 
    true;
            }
          }
        }
      }
    }
                     
    paytime php

    PHP:
    namespace CrazyHippie\PayCheck;

    use 
    pocketmine\Player;
    use 
    pocketmine\scheduler\PluginTask;

    class 
    paytime extends PluginTask{

        private 
    $minutes 0;
        private 
    $time 10;
        private 
    $player null;

        public function 
    __construct($plugin$player){
            
    $this->plugin $plugin;
            
    parent::__construct($plugin);
            
    $this->time $plugin->time;
            
    $this->player $plugin->player;
        }

        public function 
    onRun($currentTick){
            
    $this->minutes++;
            if(
    $this->time === $this->time){
                if(
    $this->player->isOnline()){
                    
    $this->plugin->getServer()->getScheduler()->setTask($this->getTaskId());
                    
    set($this->plugin->tasks[$this->player->getName()]);
                }
            }
        }
    }
  4. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    I do want it to only pay for time on the server..witch is what is confusing me so much i think.
  5. Gamecrafter
    Offline

    Gamecrafter Notable Member Plugin Developer

    Joined:
    Nov 20, 2014
    Posts:
    981
    Plugins:
    9
    Go learn a little PHP first, then come back.
    dxm_hippie likes this.
  6. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    lol ok :p i saw the main tutorial for learning php but it said it would take 4 hours..havnt had that kind of time to kill since i started messing with it.
  7. Gamecrafter
    Offline

    Gamecrafter Notable Member Plugin Developer

    Joined:
    Nov 20, 2014
    Posts:
    981
    Plugins:
    9
    It took me weeks, months maybe, to learn. But look at me now. ;)
    dxm_hippie likes this.
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Do not use $this->config. Either make another name for it or use the PocketMine plugin config API.
    dxm_hippie likes this.
  9. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    I think I got the basics of php..like the very basics lol just understanding where and when to put some things I need to work on I guess..pluss everything else lol All I did really was started modding and studying others code and looked at a few tutorials on here. I got some reading to do huh? :p
  10. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    I don't really understand what you mean by this, a lot of the code I've studied used that to "get" somthing from the config
  11. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    Also..off topic but how far off from making pocketmine plugins is a possibility of making a career out of developing software..if that makes sense, im planning on going to college here soon for developing..got welder as a backup plan :D lol
  12. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Idk in your society. But in Hong Kong, if you have the choice, developing wouldn't be something you prefer unless you are really expert at it, which I believe nobody here including like @shoghicp is one.
  13. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Those code you saw were wrong. There should not be $this->config anywhere in your main class.
  14. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    Ah so pretty far off lol im still thinking of going to school for it. love this stuff XD maybe ill be back in 4 years with some sweet plugins :p
  15. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    And I mean this stuff as in developing lol dont get me wrong mc is a sweet game but I really started tinkering to try and teach myself a bit of the trade.
  16. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Things here are too simple. Knowing these basic things can help you a lot in the future would where very likely everything is about computers, but if you want to be professional at it, you're still too far away.
  17. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    Obviously XD I have trouble with the most basic plugins :p but feel I am learning fast. Just need to do some reading up I think, I hate book work lol more of a hands on learner.

Share This Page

Advertisement