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

making join queue

Discussion in 'Plugin Help' started by zenqibruh, Sep 20, 2021.

  1. zenqibruh

    zenqibruh Spider Jockey

    Messages:
    36
    GitHub:
    ohitszenqi
    Hi, How do i make a system when player click the button and it queues him example:
    say that i clicked a button then if other player click the button then we two gonna go to a world then we gonna pvp like queuing system.

    I don't gonna go to the world unless someone click it to join the game since we two need to pvp. Just like practice pvp game

    and when i clicked the button the it will show like this
    Queued: 1/2
    When someone clicked the button (not me)
    Then it will show
    Queued: 2/2 or Ongoing, then we gonna go to a specific world and fight
     
  2. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    You could use arrays.
    I'm starting to forget PHP, so I might be incorrect.

    Example:
    PHP:
    public array $queued = [];

    /**
    * Queues a player
    *
    * @param string $playername
    **/
    public function queuePlayer(string $playername) : void {
          if(empty(
    $this->queued[])) { # If no one's in the queue
                
    $this->queued[] = $playername# Set the player to the queue
                
    return;
          } 
    # If someone is already in the queue
          
    $codeToStartTheGame# Start the game
          
    unset($this->queued[]); # Clears the queue
          
    return;
    }

    // On Button Click
    # $player instance of Player object
    $this->queuePlayer($player->getName()); # Queues the player with the above function
     
    Last edited: Sep 20, 2021
    Agent likes this.
  3. Axon

    Axon Zombie

    Messages:
    276
    it’s happening, minijaham is forgetting php. The day has come
     
  4. Axon

    Axon Zombie

    Messages:
    276
    He’s becoming old. :p
     
    Agent likes this.
  5. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    Now that you said that....
    I'm worried if my answer is wrong! :(
     
    Agent and Axon like this.
  6. Axon

    Axon Zombie

    Messages:
    276
    You mis-spelt param as parem, and I think the rest is just fine


    The student becomes the master :p, jk I’m a newbie
     
    Agent likes this.
  7. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    Oh jeez...that's an embarrassing mistake!
     
    Agent and Axon like this.
  8. zenqibruh

    zenqibruh Spider Jockey

    Messages:
    36
    GitHub:
    ohitszenqi
    How do i got the player name?
     
  9. Axon

    Axon Zombie

    Messages:
    276
    PHP:
    $player->getName();
     
    Agent likes this.
  10. zenqibruh

    zenqibruh Spider Jockey

    Messages:
    36
    GitHub:
    ohitszenqi
    Its seems like its T_Public so i removed public now its T_Variable btw how do i got the counts of in queue
     
  11. Axon

    Axon Zombie

    Messages:
    276
    You can use a basic php function called count.
    Usage:
    PHP:
    count($array)
    This is to get the number of names in an array.
    PHP:
    count($this->queued[])
     
    Agent likes this.
  12. zenqibruh

    zenqibruh Spider Jockey

    Messages:
    36
    GitHub:
    ohitszenqi

    So when i do that, i gonna teleport those two and how do i do that? And btw
     

    Attached Files:

  13. Axon

    Axon Zombie

    Messages:
    276
    On line 50, remove array.
    You don’t need to redefine the variable inside a function.
     
    Agent likes this.
  14. NTT

    NTT Zombie

    Messages:
    311
    GitHub:
    NTT1906
    How can you be a newbie :'v
     
    Axon likes this.
  15. Axon

    Axon Zombie

    Messages:
    276
    What do you mean :>?
     
    Agent likes this.
  16. zenqibruh

    zenqibruh Spider Jockey

    Messages:
    36
    GitHub:
    ohitszenqi
    BRUUUUUUUUUH
     

    Attached Files:

  17. zenqibruh

    zenqibruh Spider Jockey

    Messages:
    36
    GitHub:
    ohitszenqi
    So how do those two teleport to a specific world?
     
  18. Axon

    Axon Zombie

    Messages:
    276
    You don’t put a function inside a function.
    You don’t define a class variable inside a function.
    If you would like I can link you a website to learn php. :)
     
    Agent and minijaham like this.
  19. Axon

    Axon Zombie

    Messages:
    276
    Agent likes this.
  20. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    bruh moment numero 27
     
    Agent likes this.
  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.