$time_current = time();
$User = $con->query("SELECT * FROM players WHERE Username='".$_SESSION['Username']."'");
$UserInfo = $User->fetch_object();
if($UserInfo->Wood == "") {
$con->query("UPDATE players SET Wood='100'");
} elseif($UserInfo->Stone == "") {
$con->query("UPDATE players SET Stone='100'");
} elseif($UserInfo->Gold == "") {
$con->query("UPDATE players SET Gold='100'");
}
if((time() - $UserInfo->LastGivenWood) >= 10) {
$wood_to_give = 20;
$time = 10;
$last_given = $UserInfo->LastGivenWood;
$added_wood = ceil(($time_current-$last_given )/$time) * $wood_to_give;
echo $added_wood."<br>";
echo $last_given."<br>";
echo $time."<br>";
echo $wood_to_give."<br>";
$con->query("UPDATE players SET Wood=Wood+$added_wood WHERE Username='". $_SESSION['Username']."'");
}
if((time() - $UserInfo->LastGivenStone) >= 10) {
$stone_to_give = 20;
$time = 10;
$last_given = $UserInfo->LastGivenStone;
$added_stone = ceil(($time_current-$last_given)/$time) * $stone_to_give;
$con->query("UPDATE players SET Stone=Stone+$added_stone WHERE Username='". $_SESSION['Username']."'");
}
if (isset($added_wood) && $added_wood>0) $con->query("UPDATE players SET LastGivenWood=$time_current WHERE Username='".$_SESSION['Username']."'");
if (isset($added_stone) && $added_stone>0) $con->query("UPDATE players SET LastGivenStone=$time_current WHERE Username='".$_SESSION['Username']."'");
出于一些非常奇怪的原因,$added_stone
是一个类似于2,757,953,800
的数字第一次给出资源(在用户第一次登录后直接)我试着再次回复它第一次接收资源。第二次它应该是(20)
所以我的所有资源都设置为类似2,757,953,800
的数字,有没有人知道如何解决这个问题
编辑:另外,$last_given
我的意思是$added_wood
和$added_stone
(他们的行为都相同)抱歉。
答案 0 :(得分:1)
看起来$UserInfo->LastGivenWood
默认为零。
当您第一次点击此条件时,它会触发,因为time() >= 10
:
if((time() - $UserInfo->LastGivenWood) >= 10) {
然后根据零时间戳(0是Unix Epoch,1970年初 - 这就是为什么它最终会成为相当多的木材)的时间,你可以根据玩家的资源存储量进行测量:
$last_given = $UserInfo->LastGivenWood;
$added_wood = ceil(($time_current-$last_given )/$time) * $wood_to_give;