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

How can I put Players in config except before I putted randomly Player.

Discussion in 'Development' started by Hoyee, Jun 11, 2020.

  1. Hoyee

    Hoyee Baby Zombie

    Messages:
    126
    I put one of player in config that is selected before by randomly. So now I want to put all of players to Config except one of player that is selected before randomly. How can I?

    Code:
    $all = $this->getServer()->getOnlinePlayers();
    
            $o = $all[array_rand($all)];
    
    
    $p = $this->List->getAll();
          $p["RandomOfPlayer"][] = "{$o->getName()}";
    
          $this->List->setAll($p);
          $this->List->save();
     
  2. mmm545

    mmm545 Baby Zombie

    Messages:
    152
    GitHub:
    mmm545
    use array_splice to remove the random player from the array
    PHP:
    array_splice($allarray_search($o$all));
    Edit: fixed a mistake
     
  3. Hoyee

    Hoyee Baby Zombie

    Messages:
    126
    Then, How can I remove one of player in config? and all clear too
     
  4. Hoyee

    Hoyee Baby Zombie

    Messages:
    126
    ErrorException: "array_splice() expects parameter 2 to be int, string given" (EXCEPTION)

    error happened

    Code:
    $all = $this->getServer()->getOnlinePlayers();
    
            $o = $all[array_rand($all)];
    
    
    $this->P["Hum"] = array_splice($all, array_search($o, $all));
    
    
    
    
    $Hum = $this->P["Hum"];
            $Hum->getInventory()->addItem(Item::get(1, 0, 1));
    
          }
     
  5. mmm545

    mmm545 Baby Zombie

    Messages:
    152
    GitHub:
    mmm545
    ok apparently i'm an idot, i didn't realize array_rand returns an int, so u can do it like this:
    PHP:
    array_splice($all$o);
    and like that it shouldn't give an error
     
  6. Hoyee

    Hoyee Baby Zombie

    Messages:
    126
    but now it says ErrorException: "array_splice() expects parameter 2 to be int, object given"
     
  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.