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); }
Make a function to get the kitnumber, then use giveKit with that number. Example: PHP: public function randomKit(){return mt_rand(1, 3);} Then just remove the random number from giveKit and do it like this: PHP: public function giveKit($id, Player $player){//...}
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.
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
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.