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

cycle through array in order

Discussion in 'Development' started by Atomization, Nov 14, 2018.

  1. Atomization

    Atomization Baby Zombie

    Messages:
    120
    GitHub:
    iAtomPlaza
    how can i create a function that chooses 2 objects from an array and picks each one back and forth?

    *(example) for use with minigame, send one player to team red and then send the next player to team blue, and the next player back to team red... etc*

    object 1 in my array holds the cords position for red team spawnpoint
    object 2 holds the blue team spawn point

    Code:
    ---
    world:
      blueSpawn:
      - 10.629100
      - 55.000000
      - 55.617400
      redSpawn:
      - 10.445700
      - 55.000000
      - 9.381400
    ...
    
     
  2. radondev

    radondev Silverfish

    Messages:
    21
    GitHub:
    radondev
    You need a constant count of teams.
    PHP:
    $teams 3;
    Everytime a player joins or quits the minigame you have to increase or decrease the number of players.
    PHP:
    $players $players 1;
    After that you can calculate it using modulo:
    PHP:
    $playerTeam $players $teams;
    switch (
    $playerTeam) {
      case 
    0:
        echo 
    "Team 1";
        break;
      case 
    1:
        echo 
    "Team 2";
        break;
      case 
    2:
        echo 
    "Team 3";
        break;
    }
     
    Last edited: Mar 7, 2019
  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.