0
$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

4

1 回答 1

1

看起来$UserInfo->LastGivenWood默认为零。

当您第一次点击此条件时,它会触发,因为time() >= 10

if((time() - $UserInfo->LastGivenWood) >= 10) {

然后根据自零时间戳以来的时间(0 是 Unix 纪元,1970 年初——这就是为什么它最终会变得相当复杂),你可以根据时间来记录玩家的资源存储:

  $last_given = $UserInfo->LastGivenWood;
  $added_wood = ceil(($time_current-$last_given )/$time) * $wood_to_give;
于 2013-09-12T09:32:15.267 回答