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

Solved just 2 players

Discussion in 'Development' started by KHAV, Aug 9, 2017.

  1. KHAV

    KHAV Baby Zombie

    Messages:
    152
    GitHub:
    xkhhv
    i am working on a minigame but i want to know how i can work when the first two write command to enter the game no one can enter after them :)
     
  2. XdmingXD

    XdmingXD Baby Zombie

    Messages:
    158
    GitHub:
    xdmingxd
    Isn't that is all your plugin about...
    Why don't you put this thread to request?
     
    Last edited: Aug 9, 2017
    SOFe likes this.
  3. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    This is very unreliable and unsustainable. What if it doesn't have a unique world?? And what if you want to add extra players into the world, such as moderators, spectators, etc.?
     
    jasonwynn10, XdmingXD and Sandertv like this.
  4. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    PHP:
    // $players_on - number of players on the minigame

    // if player enters minigame
    if($players_on 2) {
        if(
    $player->hasPermission("minigame-watcher") {
            
    // enter as watcher
        
    } else {
            
    // enter as player
           
    $players_on++;
         }
    } else {
        if(
    $player->hasPermission("minigame-watcher") {
            
    // enter as watcher
        
    } else {
            
    // 2 players entered already
        
    }
    }
     
  5. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    You can just create player array and then count number of players in it
    PHP:
    /** @var Player[] */
    public $players= []; 

    $this->players[strtolower($p->getName())]= $player//Add player to the array
    Now you get number of players, and check if there is more than 2 players, like this:
    PHP:
    $players intval(count($this->players));
    if(
    $players 2){
        
    //Player can not enter
    }else{
      
    //Player can enter
    }
     
  6. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    count() returns an int. Why intval...
    And your code will allow three players to join because $player is the current count not the new count.
    And without defining $players_on your post didn't explain anything at all.
     
  7. XdmingXD

    XdmingXD Baby Zombie

    Messages:
    158
    GitHub:
    xdmingxd
    Ok...since some member were trying to help...
    Take a look at this HERE
    Something maybe outdated but still usefull
     
  8. KHAV

    KHAV Baby Zombie

    Messages:
    152
    GitHub:
    xkhhv
    thank you for everyone i will try the codes and i will tell you what happened:)
     
  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.