Is it Server Problem or Config?

Discussion in 'Development' started by iBa4x, Jun 17, 2020.

  1. iBa4x

    iBa4x Spider Jockey

    Messages:
    32
    GitHub:
    iBa4x
    I have this code..
    PHP:
    public function JoinTeamEvent(){
            
    $mRed TextFormat::BLUE."Team> ".TextFormat::GRAY."You joined".TextFormat::RED." RED ".TextFormat::GRAY."Team".TextFormat::BLUE.".";
            
    $mBlue TextFormat::BLUE."Team> ".TextFormat::GRAY."You joined".TextFormat::BLUE." BLUE ".TextFormat::GRAY."Team".TextFormat::BLUE.".";
            foreach(
    $this->plugin->getServer()->getOnlinePlayers() as $player){
                
    $username $player->getName();
                if(
    $this->plugin->getPlayerDataByName($username)->isInGame()){
                    if(
    $this->GameData->countPlayers("blue") == $this->GameData->countPlayers("red")){
                        if(
    mt_rand(0,1) == 0){
                            
    $this->plugin->getPlayerDataByName($username)->setInTeam("RED");
                            
    $this->plugin->getGameData()->setTeamPlayer($username "RED");
                            
    $player->sendMessage($mRed);
                            
    $player->setNameTag(TextFormat::BOLD.TextFormat::RED.$player->getName());
                        }else{
                            
    $this->plugin->getPlayerDataByName($username)->setInTeam("BLUE");
                            
    $this->plugin->getGameData()->setTeamPlayer($username "BLUE");
                            
    $player->sendMessage(TextFormat::BLUE "Team> " TextFormat::GRAY "You joined" TextFormat::BLUE " BLUE " TextFormat::GRAY "Team".TextFormat::BLUE.".");
                            
    $player->setNameTag(TextFormat::BOLD.TextFormat::BLUE.$player->getName());
                        }
                    }elseif(
    $this->GameData->countPlayers("blue") > $this->GameData->countPlayers("red")){
                        
    $this->plugin->getPlayerDataByName($username)->setInTeam("RED");
                        
    $this->plugin->getGameData()->setTeamPlayer($username "RED");
                        
    $player->sendMessage($mRed);
                        
    $player->setNameTag(TextFormat::BOLD.TextFormat::RED.$player->getName());
                    }else{
                        
    $this->plugin->getPlayerDataByName($username)->setInTeam("BLUE");
                        
    $this->plugin->getGameData()->setTeamPlayer($username "BLUE");
                        
    $player->sendMessage($mBlue);
                        
    $player->setNameTag(TextFormat::BOLD.TextFormat::BLUE.$player->getName());
                    }
                }
            }
        }
    PHP:
    public function setTeamPlayer($username$team){
            
    $this->file->setNested("PLAYERS.".$username$team);
            
    $this->file->save();
        }
    sometime setTeamPlayer got skip and sometime not and this make me angry because no error code at all!
    when it's not get skip every things go right but if it got skip may be every player will be in the same team and I don't want to change count system or what ever

    if anyone know why it work sometime and sometime not tell me may be it would be helpful!
     
    Last edited: Jun 17, 2020
  2. Doxestic

    Doxestic Silverfish

    Messages:
    22
    I have this problem too but I think it because of low TPS
     
  3. iBa4x

    iBa4x Spider Jockey

    Messages:
    32
    GitHub:
    iBa4x
    So in order to fix the issue I should change it is it right ?
     
  4. Doxestic

    Doxestic Silverfish

    Messages:
    22
    I think no but if you want to reduce this problem you can use a checking function for get team of player
     
    iBa4x likes this.
  5. iBa4x

    iBa4x Spider Jockey

    Messages:
    32
    GitHub:
    iBa4x
    That's really cool idea ! I liked it :)
    I'll test it out
     
  6. Doxestic

    Doxestic Silverfish

    Messages:
    22
    your welcome;)
     

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.