PHP: $rand = mt_rand(1,100);if($rand<=50){ $player->getInventory()->addItem(Item::get(264,0,1));} else if($rand<=20){$player->getInventory()->addItem(Item::get(368,0,1));} else if($rand<=30){$player->getInventory()->addItem(Item::get(265,0,1));} When I use this code, It only works in ItemCode 264(diamond). why? I want to make if 50%, give diamond, if 20%, give ender, if 30%, give iron

You will need to put the smallest number first, because with your code, even if $rand is smaller than 20, the condition <=50 is still true and it will use that.

I changed what you said, but when I tested, it sometimes give nothing. why this problem happening? PHP: if($rand<=20){ $player->getInventory()->addItem(Item::get(265,0,1));} else if($rand<=30){$player->getInventory()->addItem(Item::get(368,0,1));} else if($rand<=50){$player->getInventory()->addItem(Item::get(264,0,1));}

PHP: $rand = mt_rand(1,100);if($rand<=20){ $player->getInventory()->addItem(Item::get(265,0,1));} else if($rand<=30){$player->getInventory()->addItem(Item::get(368,0,1));} else if($rand<=50){$player->getInventory()->addItem(Item::get(264,0,1));} NO

what mean?? It works well, everything is good but a little more frequently, they just take the stones and don't give the items. what problem is this? I need to solve this problem quickly

$rand is a random number between 0 and 100. Try reading your code again. Which lines of code would be executed if $rand is 90?

PHP: $rand = mt_rand(1,100);if($rand<=40){ $player->getInventory()->addItem(Item::get(264,0,1));} else if($rand<=80){$player->getInventory()->addItem(Item::get(368,0,1));} else if($rand<=100){$player->getInventory()->addItem(Item::get(265,0,1));} is this right? 264 's probability is 40%, 368's probability is 80%, and 265's probability is 100%

No, it is 40% 40% 20%, because $rand cannot be <= 40 if the first condition is wrong. If $rand is 0-40, you get first. If $rand is 41-80, you get second. If $rand is 81-99, you get third.

Actually there is an off by one issue. The real probability in your code is 41% 40% 19% because $rand can be 0 but cannot be 100 (at most 99).

than, is this right? PHP: $rand = mt_rand(1,15)if($rand<=5){sendMessage(probability is 5%);} else if($rand<=15){sendMessage(probability is 10%);}