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

Solved Help

Comments in 'Plugin Development' started by TheBison_, Dec 26, 2015.

  1. TheBison_
    Offline

    TheBison_ New Member

    Joined:
    Mar 31, 2014
    Posts:
    46
    Minecraft User:
    TheBisonXD_
    Hello guys i hope you can solve this question:

    How can I make that both players get the same kit ? With this code , both players get a random kit .

    Code:
    public function startDuel(){
    foreach ($this->players as $player){
                $this->giveKit($player);
            } }
    
    
    Code:
    private function giveKit(Player $player){
            // Clear inventory
            $player->getInventory()->clearAll();
           
            //Kits
            //Kit 1
            $Kit = rand(1 ,3);
           
            if($Kit == 1)
            {
            $player->getInventory()->addItem(Item::get(ITEM::DIAMOND_SWORD));
            $player->getInventory()->setItemInHand(Item::get(ITEM::DIAMOND_SWORD), $player);   
           
            $player->getInventory()->setHelmet(Item::get(298, 0, 1));
            $player->getInventory()->setChestplate(Item::get(299, 0, 1));
            $player->getInventory()->setLeggings(Item::get(300, 0, 1));
            $player->getInventory()->setBoots(Item::get(301, 0, 1));
            $player->getInventory()->sendArmorContents($player);
            }
            if($Kit == 2)
            {
            $player->getInventory()->addItem(Item::get(ITEM::STONE_SWORD));
            $player->getInventory()->setItemInHand(Item::get(ITEM::STONE_SWORD), $player);   
           
            $player->getInventory()->setHelmet(Item::get(306, 0, 1));
            $player->getInventory()->setChestplate(Item::get(307, 0, 1));
            $player->getInventory()->setLeggings(Item::get(308, 0, 1));
            $player->getInventory()->setBoots(Item::get(309, 0, 1));
            $player->getInventory()->sendArmorContents($player);
            }
            if($Kit == 3)
            {
            $player->getInventory()->addItem(Item::get(ITEM::WOODEN_SWORD));
            $player->getInventory()->setItemInHand(Item::get(ITEM::WOODEN_SWORD), $player);   
           
            $player->getInventory()->setHelmet(Item::get(310, 0, 1));
            $player->getInventory()->setChestplate(Item::get(311, 0, 1));
            $player->getInventory()->setLeggings(Item::get(312, 0, 1));
            $player->getInventory()->setBoots(Item::get(313, 0, 1));
            $player->getInventory()->sendArmorContents($player);
            }
            $player->setHealth(20);
            $player->removeAllEffects();
                    $player->setGamemode(0);
    
       }
  2. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Make a function to get the kitnumber, then use giveKit with that number. Example:
    PHP:
    public function randomKit(){
    return 
    mt_rand(13);
    }
    Then just remove the random number from giveKit and do it like this:
    PHP:
    public function giveKit($idPlayer $player){
    //...
    }
    TheBison_ likes this.
  3. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Just saying, you should set the Player's Gamemode before adding the items to the inventory.
  4. TheBison_
    Offline

    TheBison_ New Member

    Joined:
    Mar 31, 2014
    Posts:
    46
    Minecraft User:
    TheBisonXD_
    Es haut trotzdem nicht hin, hast du Twitter? Ozecraft Dev ;)
  5. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Wrong. That has nothing to do with that.
    Just incase both of you know, this forum is english only.
    PEMapModder likes this.
  6. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    It has to do with this thread, just look his question! ._.
  7. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    First, $players is undefined. Second, how would it help to change a variable's name??
    PEMapModder and Vaivez66 like this.
  8. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    It is his question, I dont know why, and $player is an example
  9. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    His problem is that all players get a random kit, he wants them to get the same. I don't know how you thought that, but that doesn't affect the variable name in any case. Your code is the same as he showed us, just with another variable.
  10. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    His question was very bad, no details,...

    Anyways, you do foreach() at giveKit(), remove it and do it under if(.... == 1){

    Because you did for each person the givekit command
  11. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    I already helped him giving hin a correct way
    TheBison_ likes this.
  12. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    Nope you didnt, it didnt worked, he asked you for your twitter name, then you sayed this forum is english, that is what you did.
  13. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    It did, he just used it wrongly. :p I've talked to him on Twitter and corrected his code.
    TheBison_ likes this.
  14. TheBison_
    Offline

    TheBison_ New Member

    Joined:
    Mar 31, 2014
    Posts:
    46
    Minecraft User:
    TheBisonXD_
    Solved. Thanks to CraftYourBukkit.
    CraftYourBukkit likes this.

Share This Page

Advertisement