Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Help me!

Comments in 'Plugin Development' started by alexwolf_dev, Oct 21, 2016.

  1. alexwolf_dev
    Offline

    alexwolf_dev New Member

    Joined:
    Apr 6, 2016
    Posts:
    10
    Minecraft User:
    skillhearts
    On join to mini game 1 player all done, but on join two players server stopped.

    Sorry for bad english, I'm from Russia. We have a completely different structure the sentences.

    PHP:

    public function GameJoin(PlayerInteractEvent $e){
            
    $p $e->getPlayer();
            
    $b $e->getBlock();
            
    $item $p->getInventory()->getItemInHand();
            if(
    $item !== null && $this->players 8){
                if(
    $b->getId() == 133){
                    if(
    $item->getId() == 263){
                        
    $p->getInventory()->clearAll();
                        
    $this->give($p1);
                    }
                    if(
    $item->getId() == 265){
                        
    $p->getInventory()->clearAll();
                        
    $this->give($p2);
                    }
                    if(
    $item->getId() == 266){
                        
    $p->getInventory()->clearAll();
                        
    $this->give($p3);
                    }
                    if(
    $item->getId() == 341){
                        
    $p->getInventory()->clearAll();
                        
    $this->give($p4);
                    }
                    if(
    $item->getId() == 348){
                        
    $p->getInventory()->clearAll();
                        
    $this->give($p5);
                    }
                    if(!(
    $item->getId() == 263 or $item->getId() == 265 or $item->getId() == 266 or $item->getId() == 341 or $item->getId() == 348)){
                        
    $p->sendTip("§b Вы не выбрали класс!");
                    }else{
                        
    $this->setGame($p);
    $this->getLogger()->info("set game $p");
                    }
                }
            } else {
                
    $p->sendTip("§6 Арена полная!");
            }
        }

    public function 
    setGame($p){
            if(
    $this->gameStatus==&& $this->players >= 1){
                
    $this->gameStatus=1;
            }
            if(
    $this->gameStatus !== 2){
                
    //if($this->players !== 8){
                    
    $this->setPos($p);
    $this->getLogger()->info("set pos $p");
                
    //}
            
    }
        }


        public function 
    setPos($player){
            
    $name $player->getName();
        
            
    $pos = array("1","2","3","4","5","6","7","8");
            
    $rand array_rand($pos);
            
    $r $pos[$rand];
        
            
    $n $this->info["pos$r"]["name"];
            
    $p $this->info["pos$r"]["pos"];
            
    $a $this->info["pos$r"]["a"];
        
            if(
    $a == "0"){
                
    $this->info["pos$r"] = array("name"=>"$name""pos"=>"$r""a"=>"1");
                
    $playername $this->info["pos$r"]["name"];
                
    $a_pos $this->info["pos$r"]["a"];
            
                
    $this->spawn($player$r);
    $this->getLogger()->info("spawn $p");
            }else{
                
    $this->setPos($player);
    $this->getLogger()->info("set pos 2 $p");
            }
        }

        public function 
    spawn($p$pos){
            if(
    $pos == !null){
    $this->getLogger()->info("spawned $p succeed");
                
    $p->teleport(Server::getInstance()->getLevelByName("SuperSmashMobs")->getSafeSpawn());
                if(
    $pos == 1){
                    
    $p->teleport(new Vector3(13532103));
                }
                if(
    $pos == 2){
                    
    $p->teleport(new Vector3(13533139));
                }
                if(
    $pos == 3){
                    
    $p->teleport(new Vector3(14433161));
                }
                if(
    $pos == 4){
                    
    $p->teleport(new Vector3(11133159));
                }
                if(
    $pos == 5){
                    
    $p->teleport(new Vector3(8933120));
                }
                if(
    $pos == 6){
                    
    $p->teleport(new Vector3(1143285));
                }
                if(
    $pos == 7){
                    
    $p->teleport(new Vector3(1573075));
                }
                if(
    $pos == 8){
                    
    $p->teleport(new Vector3(17235120));
                }
            }
        }

    Last edited: Oct 21, 2016
  2. Nawaf_Craft1b
    Offline

    Nawaf_Craft1b Active Member Plugin Developer

    Joined:
    May 8, 2015
    Posts:
    232
    Plugins:
    1
    Minecraft User:
    Nawaf_Craft1b
    Use this is more better
    PHP:
    if(count($this->array) == 1){
    # teleport to pos1
    }
    if(
    count($this->array) == 2){
    # teleport to pos2
    }
  3. alexwolf_dev
    Offline

    alexwolf_dev New Member

    Joined:
    Apr 6, 2016
    Posts:
    10
    Minecraft User:
    skillhearts
    It's not really change the situation.
  4. ImagicalGamer
    Offline

    ImagicalGamer Active Member

    Joined:
    Feb 25, 2016
    Posts:
    141
    Minecraft User:
    ImagicalGamer
    This isn't going to solve your problem but on PlayerInteractEvent use elseif instead of if multiple times it's faster.
  5. xBeastMode
    Offline

    xBeastMode Active Member

    Joined:
    Nov 27, 2015
    Posts:
    292
    Your code is very bad, it wastes more memory and runs slower. Why are you choosing a position with mt_rand(), there is a big chance that the players will join the same position, did you know that?

    What I really suggest is make an array of the positions, make a variable with the amount of positions, make an array to save players in-game (players in-game array is optional).

    I'll show an example here, it is much easier to code it than to explain it:

    PHP:
    public $pn 12;//amount of positions
    public $positions = [new Vector3(99,99,99)];//vector 3 positions

    public function setPlayer(Player $p){
    //Check if player already joined logic here and return

    //Else if hasn't joined

    if($this->pn 0){
    return;
    //if full don't join
    }

    //Else join
    $pos $this->positions[$this->pn];
    --
    $this->pn;
    $p->teleport($pos);
    }

    //Reset function
    public function reset(){
    $this->pn 24;
    //Other stuff
    }

    Blabla likes this.
  6. alexwolf_dev
    Offline

    alexwolf_dev New Member

    Joined:
    Apr 6, 2016
    Posts:
    10
    Minecraft User:
    skillhearts
    Thanks, but this code work:
    PHP:
    $p->teleport(new Vector3(13533139));
    and this code don't work:
    PHP:
    $players count($this->getServer()->getLevelByName("SuperSmashMobs")->getPlayers())+1;
    $pos $this->pos[$players];
    $r $p->teleport(new Vector3($pos));
    $this->getLogger()->info("teleport(new Vector3($pos));");

Share This Page

Advertisement