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

Need Help

Comments in 'Plugin Development' started by xiaoq, Jun 7, 2015.

  1. xiaoq
    Offline

    xiaoq Active Member

    Joined:
    Dec 23, 2014
    Posts:
    232
    Minecraft User:
    xiaoq
    I work on a mini game but I have a problem, can some one help me?
    When player tap the sign, this player will teleport to (pos1)
    when another player tap the sign, this player will teleport to (pos2)
    them pos3, pos4
    if the first player leave, the next player tap the sign will teleport to pos1
  2. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Got a Basic code?
  3. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    make variable
    PHP:
     public $pos = [12345678]; 
    public 
    $players = [];
    when player touch sign:
    PHP:
    $player->teleport(min($this->pos));
    $this->players[strtolower($player->getName())] = min($this->pos);
    unset(
    min($this->pos));
    when player leave
    PHP:
    $pos[0]= $this->players[strtolower($player->getName())];
    unset(
    $this->players[strtolower($player->getName())];
    i think it should work.
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    When player joins, push the position into another array and shift it out of the old array.
    When player quits, pull out the relevant position and unshift it back into the old array.
  5. xiaoq
    Offline

    xiaoq Active Member

    Joined:
    Dec 23, 2014
    Posts:
    232
    Minecraft User:
    xiaoq
    No Really Understand:
    I use another example please help me:

    ===========================
    PHP:
    public function playerJoinEvent(PlayerJoinEvent $event){
                 if(!isset(
    $this->players[$event->getPlayer()->getName()])){
                
    $this->players[$event->getPlayer()->getName()]=array("id"=>$event->getPlayer()->getName());
                }else{
             
    $event->getPlayer()->sendMessage("Error during this match");
             
    $event->getPlayer()->kick("Error"false);
           }
    }
        public function 
    PlayerQuit(PlayerQuitEvent $event){
            if(isset(
    $this->players[$event->getPlayer()->getName()]))
            unset(
    $this->players[$event->getPlayer()->getName()]);
            }  
    For Example:
    pos1 = 1,1,1,skywars;
    pos2 = 2,2,2,skywars;
    pos3 = 3,3,3,skywars;
    pos4 = 4,4,4,skywars
    So how to write?
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    PHP:
    private $availableSpawns$usedSpawns = []; // populate $availableSpawns yourself
    private function join(Player $player){
      
    $pos array_shift($this->availableSpawns); // extract one from available list
      
    $this->usedSpawns[$player->getId()] = $pos// add it into used list
      
    $player->teleport($pos);
    }
    private function 
    quit(Player $player){
      if(isset(
    $this->usedSpawns[$player->getId()])){
        
    $pos $this->usedSpawns[$player->getId()];
        unset(
    $this->usedSpawns[$player->getId()]); // remove it from used list
        
    array_unshift($this->availableSpawns$pos); // put it back into available list
      
    }
    }
    xiaoq likes this.
  7. xiaoq
    Offline

    xiaoq Active Member

    Joined:
    Dec 23, 2014
    Posts:
    232
    Minecraft User:
    xiaoq
    So when player join :
    $this->join($player);
    Quit:
    $this->quit($player);

    And what should I write in $usedSpawns = [ HERE ] :)
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Learn PHP... This is the syntax for an array.
  9. xiaoq
    Offline

    xiaoq Active Member

    Joined:
    Dec 23, 2014
    Posts:
    232
    Minecraft User:
    xiaoq
    I mean should I put the pos & level or v3 in side...
    Last edited: Jun 10, 2015
  10. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    You can't populate objects at that context. Populate the array in somewhere like onEnable or when your arena starts.

Share This Page

Advertisement