php - 使用 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));
解决方案
您需要将其转换为 int。
例如$x = mt_rand((int) $Xmin, (int) $Xmax);
推荐阅读
- excel - 按最近日期过滤数据 - (重复数据)
- python - s3中没有上传文件时如何触发lambda?
- gem5 - 如何定期驱逐特定的缓存行?
- javascript - 如何在 Chrome/Edge 浏览器中单击按钮时打印 SSRS 报告
- node.js - 如何通过指定我要创建的项目数在 Mongodb 中自动创建具有不同 ID 的项目表?
- python - 根据缺失数据添加行
- php - 用ftp制作php文件夹
- javascript - 如何在 django-leaflet 传单地图中表示 Geodjango 模型?
- docker - 在 Heroku 上部署 Net core 5.0 API 失败并出现 Docker 错误:无法启动 Kestrel
- smartcontracts - 带有 OpenZeppelin 合约的 Tron 网络