1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

[HELP] No error but doesn't work

Discussion in 'Development' started by Hipster, Apr 30, 2017.

  1. Hipster

    Hipster Zombie

    Messages:
    214
    Snippet
    onEnable
    PHP:
    public $hud = [];
     
    $this->getServer()->getScheduler()->scheduleRepeatingTask(new Task($this), 20);
    onCommand
    PHP:
    case "hud":
            
    $name strtolower($sender->getName());
            if (isset(
    $this->hud[$name])){
                
    $sender->sendMessage("Disabling HUD");
                unset(
    $this->hud[$name]);
                return 
    false;
            }
            else{
                
    $sender->sendMessage("Enabling HUD");
                
    $this->hud[$name] = $name;
                return 
    false;
            }
            break;
    PluginTask onRun
    PHP:
    $pl $this->plugin->getServer()->getOnlinePlayers();
    foreach(
    $pl as $p){
         
    $name strtolower($p->getName());
    if(isset(
    $this->hud[$name])){
        
    $p->sendPopup("\n[Money: §f".$this->plugin->getServer()->getPluginManager()->getPlugin("EconomyAPI")->myMoney($p)."$"."§6]");
            }
    }
    No errors in console but when i turn on hud it doesn't come up!
     
    Last edited: Apr 30, 2017
  2. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    You're checking if the array hud from the task, has a value that's been put in the hud array from the main class. That won't work. In your task, you should have:
    PHP:
    if(isset($this->getOwner()->hud[$name])) {
      
    $p->sendPopup("PopupText");
    }
     
    Hipster likes this.
  3. Hipster

    Hipster Zombie

    Messages:
    214
    Sandertv likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.