wrong and error with array and setRespawnPosition()

Discussion in 'Development' started by Hoyee, Mar 14, 2020.

  1. Hoyee

    Hoyee Slime

    Messages:
    90
    If I use this code

    Code:
    $this->db["BlueHome"] = array('x'=>(int)$player->getX(),'y'=>(int)$player->getY(),'z'=>(int) $player->getZ());
    it saves in yml like
    Code:
    BlueHome:
      x: 333
      "y": 69
      z: 241
    this. how can I remove " in between y ?

    and if I use
    Code:
    $this->db["blue"]->setRespawnPosition(new Position($this->db["BlueHome"]),$player->getLevel());
    this code, server crash and says "Call to a member function setRespawnPosition() on string" (EXCEPTION)
     
  2. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,362
    GitHub:
    HimbeersaftLP
    You can't, "y" means true in yaml, that's why it needs to be quoted to interpret it as the letter y.
    If you absolutely can't stand quotes around the y, you could name your coordinates differently.
    The Position constructor takes four arguments, not an array, also "$this->db["blue"]->setRespawnPosition" makes no sense at all, what are you trying to do?
     
  3. Hoyee

    Hoyee Slime

    Messages:
    90
    I want to change worldspawn of players that is inside ["blue"] where I located.
     
    Last edited: Mar 14, 2020
  4. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,362
    GitHub:
    HimbeersaftLP
    You can use a function like this:
    PHP:
    private function setupSpawnsForTeam($teamName) {
         
    $playerNames $this->db[$teamName];
         foreach (
    $playerNames as $playerName) {
              
    $player $this->getServer()->getPlayer($playerName);
              if (
    $player !== null) {
                   
    $positions $this->db[$teamName "Home"];
                   
    $player->setSpawn(new Vector3((int) $positions["x"], (int) $positions["y"], (int) $positions["z"]));
              }
         }
    }
    Assuming your config looks like this:
    Code:
    blue:
      - Alex
      - Steve
      - ChuckNorris
    
    blueHome:
      x: 333
      "y": 69
      z: 241
    
    P.S. don't forget use pocketmine\math\Vector3;
     
    Invy55 likes this.
  5. Hoyee

    Hoyee Slime

    Messages:
    90
    How can I make

    Code:
    blue:
    - Alex
    - Steve
    - notch
    like this??? It works like
    Code:
    blue: Alex
    blue: Honey
    blue: steve
    this.
     
  6. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,362
    GitHub:
    HimbeersaftLP
    You can't have it like the second, at least not with standard-compliant yaml, because you'd just override blue every time.
     
    Invy55 likes this.
  7. Hoyee

    Hoyee Slime

    Messages:
    90
    Now I think I understanded what's your saying, but now There is crash of player names. I think it's because of

    blue : player
    blue : player
    blue : player

    this. So what config should I use about?

    "Undefined index: player name"
     
    Last edited: Mar 15, 2020
  8. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,362
    GitHub:
    HimbeersaftLP
    Just look at the one I provided in my reply :|
     
  9. Hoyee

    Hoyee Slime

    Messages:
    90
    ah.. Now I know how to make
    -a
    -b
    -c
    like this. but Now it says

    "Illegal offset type" ~~~ on line 31

    here is the line 31
    Code:
     $playerNames = $this->db[$teamName];
    and this code is came from
    Code:
    private function setupSpawnsForTeam($teamName) {
         $playerNames = $this->db[$teamName];
         foreach ($playerNames as $playerName) {
              $player = $this->getServer()->getPlayer($playerName);
              if ($player !== null) {
                   $positions = $this->db[$teamName . "Home"];
                   $player->setSpawn(new Vector3((int) $positions["x"], (int) $positions["y"], (int) $positions["z"]));
              }
         }
    }

    and here is the code
    Code:
    if( !isset($blueplayers) or !isset($redplayers) ){
                  $player->sendMessage("ntp");
                }//if
                  if( isset($blueplayers) or isset($redplayers) ){
    
                                    $blueplayers = $this->db["blue"];
    
                                    $this->setupSpawnsForTeam($blueplayers);
    
                                    $redplayers = $this->db["red"];
    
                                    $this->setupSpawnsForTeam($redplayers);
    
                                    $this->getServer()->broadCastMessage("w");
     
    Last edited: Mar 16, 2020
  10. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,362
    GitHub:
    HimbeersaftLP
    You need to $this->setupSpawnsForTeam("blue"); and $this->setupSpawnsForTeam("red"); my function expects a string.
     
  11. Hoyee

    Hoyee Slime

    Messages:
    90
    wow I didn't know that I can put "red" inside () it works well, Until I succeeded, I did many strange things to do.
     
  12. Hoyee

    Hoyee Slime

    Messages:
    90
    But how can I remove "blue" or "red" or "blueHome" or "redHome" ? by the command, not remove folder inside plugindata
     
  13. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    495
    GitHub:
    GamakCZ
    unset($array["blue"]);
     
    HimbeersaftLP likes this.

Share This Page

  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.