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

Check if player in two different array

Discussion in 'Plugin Help' started by ZackyVN, Jan 23, 2019.

  1. ZackyVN

    ZackyVN Baby Zombie

    Messages:
    150
    The title said all :3

    Example: if a player in array $vanish and $nick. It will show a repeating popup
     
  2. Driesboy

    Driesboy Spider Jockey

    Messages:
    34
    GitHub:
    driesboy
    Search for the PHP function called in_array()
     
    corytortoise likes this.
  3. ZackyVN

    ZackyVN Baby Zombie

    Messages:
    150
    i know this but i want to check if player in both them
     
  4. Driesboy

    Driesboy Spider Jockey

    Messages:
    34
    GitHub:
    driesboy
    PHP:
    If(in_array($player$nick) && in_array($player$vanish)){}
     
    corytortoise likes this.
  5. ZackyVN

    ZackyVN Baby Zombie

    Messages:
    150
    it doesnt work
    PHP:
        }elseif(in_array($name$this->plugin->nickpopup) && in_array($name$this->plugin->vanishpopup) && $player->getLevel()->getName() === "world"){
            
    $player->sendPopup("You are currently§c VANISHED, NICKED");
     
  6. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    $name = $player->getName();
    Right?
     
  7. ZackyVN

    ZackyVN Baby Zombie

    Messages:
    150
    Yes
     
  8. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    Var_dump level name.
     
  9. ZackyVN

    ZackyVN Baby Zombie

    Messages:
    150
    what do u mean. Im new to php
     
  10. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    add var_dump($player->getLevel()->getName());

    Are you sure the plugin is loaded?
     
  11. ZackyVN

    ZackyVN Baby Zombie

    Messages:
    150
    yes
     
  12. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    ok, make the code run and send us what you see in the console.
     
  13. Marabou

    Marabou Baby Zombie

    Messages:
    137
    GitHub:
    wiligangster
    I think operator replace && to ||

    because the first in_array can return you true and the second one false and if (true && false) the problem here.
    it can not be checked because your condition can't check. Your array he need returned to true. It is necessary to put operator || to find out if one of your array contains the index he return you true.
     
    Last edited: Jan 25, 2019
  14. Diduhless

    Diduhless Baby Zombie

    Messages:
    199
    GitHub:
    Diduhless
    He's asking how to check if a player is in both arrays, so it wouldn't make sense using || statement.
    If the code returns false it's because the player is not in the two arrays.
    Also remember that elseif will only be executed if the past if returns false.
    PHP:
    $name "diduhless";
    if(
    $name === "diduhless") {
        
    // returns true
    } elseif($name === "zackyvn") {
        
    // this won't be executed as the first if doesn't return false
    }

    if(
    $name === "zackyvn") {
        
    // returns false
    } elseif($name === "diduhless") {
        
    // this will be executed
    }
     
    corytortoise likes this.
  15. Marabou

    Marabou Baby Zombie

    Messages:
    137
    GitHub:
    wiligangster
    Ohh i don't understand OP lol He want to check two array oh okay. I think he want check if one of two array content the index can be passed.
     
  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.