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

Solved Check Player Gamemode

Discussion in 'Development' started by KittyDev, Sep 16, 2017.

  1. KittyDev

    KittyDev Slime

    Messages:
    96
    GitHub:
    FreakingDev
    is there a way to check player gamemode??
     
  2. Rysieku

    Rysieku Spider Jockey

    Messages:
    34
    GitHub:
    rysieku
    PHP:
    $player $event->getPlayer();
    if(
    $player->getGamemode() == 1) {
    // code
    }
     
  3. AshBull

    AshBull Spider Jockey

    Messages:
    31
    PHP:
    if($player->getGamemode() === Player::CREATIVE){
        
    //???
    }
     
  4. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
  5. KittyDev

    KittyDev Slime

    Messages:
    96
    GitHub:
    FreakingDev
  6. KittyDev

    KittyDev Slime

    Messages:
    96
    GitHub:
    FreakingDev
    thanks guys :) it helps!
     
  7. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    Yes, it is still working.
    Add the [Solved] tag.
     
    Last edited: Sep 17, 2017
  8. sup

    sup Spider

    Messages:
    12
    can we do something like that?

    $player = $event->getPlayer();
    if($player->getGamemode() == 1,3) {
    // code
    }
    so the code work when the player is in gamemode 1 and when he is in gamemode 3?
     
  9. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    If you want to check for multiple conditions in php, you need to write them out out and combine them with a logical or, also it's recommended to use the constants from PocketMine instead of hardcoding the IDs of the gamemodes, as that is more furture-proof and makes the code more readable.
    PHP:
    $player $event->getPlayer();
    if(
    $player->getGamemode() === Player::CREATIVE || $player->getGamemode() === Player::SPECTATOR) {
    // code
    }
     
    Diduhless and sup like this.
  10. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    $player = $event->getPlayer();
    if($player->getGamemode() == 1 or $player->getGamemode() == 3) {
    // code
    }
     
  11. sup

    sup Spider

    Messages:
    12
    thank you
     
  12. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    sure dog
     
  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.