首页 > 解决方案 > 使用 config.yml 文件中的整数作为 mt_rand() 函数中的变量的问题(pocketmine 插件)

问题描述

我正在尝试使用配置文件来存储用户可以更改的最小值和最大值,以便更轻松地更改随机代码。这用于 PocketMine-MP 插件,该插件将在随机位置生成玩家并在随机位置生成玩家。

我的配置文件如下所示:

##Change These Listed Numbers To Change Your Spawn Randomizers min and Maxes
-Coords:
Xvalues:
Xmin: -10000
Xmax: 10000
Yvalues:
Ymin: -10000
Ymax: 10000
Zvalues:
Zmin: -10000
Zmax: 10000
...

我知道这可行,但是当我使用这些值并将它们设为变量并在mt_rand()函数中使用该变量时,我收到一条错误消息:

[21:26:18] [Server thread/CRITICAL]: TypeError: "mt_rand() expects parameter 1 to be int, bool given" (EXCEPTION) in "plugins/TPRandomOnFirstJoinAndDeath/src/JviguyGamesYT/TPRandomOnFirstJoinAndDeath/Main" at line 27

我真的不知道该怎么做才能解决这个问题。如果有人可以帮助我的插件代码,这里是代码:

$player = $e->getPlayer();
$Xmin = $this->getConfig()->get("Xmin");
$Xmax = $this->getConfig()->get("Xmax");
$Ymin = $this->getConfig()->get("Ymin");
$Ymax = $this->getConfig()->get("Ymax");
$Zmin = $this->getConfig()->get("Zmin");
$Zmax = $this->getConfig()->get("Zmax");
$x = mt_rand($Xmin , $Xmax);
$y = mt_rand($Ymin , $Ymax);
$z = mt_rand($Zmin , $Zmax);
$player->teleport(new vector3($x, $y, $z));

标签: phppluginspocketmine

解决方案


您需要其转换为 int。

例如$x = mt_rand((int) $Xmin, (int) $Xmax);


推荐阅读