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

Solved Target the name of player from an other function

Discussion in 'Development' started by armagadon159753, Dec 9, 2017.

  1. Miste

    Miste Baby Zombie

    Messages:
    109
    GitHub:
    Misteboss
    PHP:
    public $cache = [];
    public function 
    mainForm(Player $player){
            
    $form $this->createSimpleForm(function (Player $event, array $data){
            
    $player $event->getPlayer();
            
    $result $data[0];
            if(
    $result !== null){
            }

            switch(
    $result){
                case 
    0:
                break;
                default:
                    
    $player->sendMessage("You clicked on " $this->cache[$player->getName()][($result 1)] . " !"); /* get the name of the player from the array */
                    
    unset($this->cache[$player->getName()]); /* unset the player from the array to save memory */
                
    break;
            }
            });
            
    $form->setTitle(TextFormat::GREEN "--= " TextFormat::BLACK "AdminUI" TextFormat::GREEN " =--");
            
    $form->setContent(TextFormat::RED "Choose a player from the below list");
            
    $form->addButton("=none=");
            foreach(
    $this->getServer()->getOnlinePlayers() as $online){
                
    $name $online->getName();
                
    $this->cache[$player->getName()][] = $name/* save each name in the array corresponding to the player in the order they appear on the form */
                
    $form->addButton(TextFormat::BLACK "--=" TextFormat::RED $name TextFormat::BLACK "=--");
            }
            
    $form->sendToPlayer($player);
        }
    Not tested but it should work.
     
    armagadon159753 likes this.
  2. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
    That work :) tank you master
     
  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.