我有这个问题有一段时间了,最后我把它缩小到它是什么(我认为)。我试图限制收入,限制是 $storagecap 每个 $warehouse = 到 500 $storagecap。在我向您展示代码之前,我会告诉您我的问题。它显示了当我拥有 2 个 $ 仓库时你的限制是什么,它说我的限制是 1000,但它使我的收入停止在 499,我设置为 0 个仓库,所以它显示 499/1000。Cron_turn 将您的收入添加到您的帐户中。
我不知道为什么当它知道 $storagecap 是 1000 时它会停在 499。
storagecap.php
<?php
$warehouse = $building['warehouse'];
if ($warehouse == 1) {
$storagecap = 500;
}elseif($warehouse == 2) {
$storagecap = 1000;
}elseif($warehouse == 3) {
$storagecap = 1500;
}elseif($warehouse == 4) {
$storagecap = 2000;
}elseif($warehouse == 5) {
$storagecap = 2500;
}elseif($warehouse == 6) {
$storagecap = 3000;
}elseif($warehouse == 7) {
$storagecap = 3500;
}elseif($warehouse == 8) {
$storagecap = 4000;
}elseif($warehouse == 9) {
$storagecap = 4500;
}elseif($warehouse == 10) {
$storagecap = 5000;
}elseif($warehouse == 11) {
$storagecap = 5500;
}elseif($warehouse == 12) {
$storagecap = 6000;
}elseif($warehouse == 13) {
$storagecap = 6500;
}elseif($warehouse == 14) {
$storagecap = 7000;
}elseif($warehouse == 15) {
$storagecap = 7500;
}elseif($warehouse == 16) {
$storagecap = 8000;
}elseif($warehouse == 17) {
$storagecap = 8500;
}elseif($warehouse == 18) {
$storagecap = 9000;
}elseif($warehouse == 19) {
$storagecap = 9500;
}elseif($warehouse == 20) {
$storagecap = 10000;
}elseif($warehouse == 0) {
$storagecap = 499;
}else{
$storagecap = 10;
}
?>
* cron_turn.php*
<?php
include("functions.php");
connect();
include("safe.php");
include("storagecap.php");
$get_users = mysql_query("SELECT * FROM `stats`") or die(mysql_error());
while($user = mysql_fetch_assoc($get_users)) {
//Get
$gold = $user["gold"];
$food = $user["food"];
$energy = $user["energy"];
//Increment
$gold += $user["income"];
$food += $user["farming"];
$energy += 5;
//Verify and correct
if ($energy > 100) {
$energy = 100;
};
if ($gold > $storagecap) {
$gold = $storagecap;
};
if ($food > $storagecap) {
$food = $storagecap;
};
//Submit
$update = mysql_query("UPDATE `stats` SET
`gold`= '".$gold."',
`food`= '".$food."',
`energy`= '".$energy."' WHERE `id`='".$user['id']."'") or die(mysql_error());
}
?>