gpt4 book ai didi

php mysql 游戏升级脚本问题

转载 作者:行者123 更新时间:2023-11-29 06:23:59 25 4
gpt4 key购买 nike

这是我的问题。在我的游戏中,我试图实现这个升级系统,一旦你达到一定的经验,你就可以晋级到更高的级别。我正在使用 php 5.0 和最新的 MYSQL。我的问题是我无法让我的脚本正确执行。

这里有一些虚拟统计数据,后面是我的代码任何可以帮助我解决问题的信息将不胜感激

     $playerNAME = "Bozo";
$playerClASS = "Warrior";
$playerLEVEL = 13;
$playerSTR = 5;
$playerDEF = 2;
$playerDEX = 3;
$playerMAG = 2;
$playerEXPERIENCE = 99999;

当我从 13 升级到 14 时,没有任何统计数据会更新为新值,并且级别不会更新...是的,我从 connect.php 到数据库服务器的所有连接都正常工作,是的,我是在我的代码中使用正确的表名称

 function levelUPSTATS () {
global $playerNAME;
global $playerClASS;
global $playerLEVEL;
global $playerSTR;
global $playerDEF;
global $playerDEX;
global $playerMAG;

if ($playerCLASS === "Warrior") {
$playerSTR = $playerSTR + 3;
$playerDEF = $playerDEF + 2;
$playerDEX = $playerDEX + 3;
$playerMAG = $playerMAG + 2;
$playerBASE_DAMAGE = ceil($playerSTR*$playerDEX);
$playerSPELL_BASE_DAMAGE = ceil($playerMAG * $playerDEX);
$playerMAX_HEALTH_POINTS = ceil($playerSTR * $playerDEF * $playerDEX);
$playerMAX_MANA_POINTS = ceil($playerMAG * $playerDEF * $playerDEX / $playerSTR);
$statusplayerSTR = "update players set strength=strength+'$playerSTR' where username='$playerNAME'";
mysql_query($statusplayerSTR) or die("Could not update player");

$statusplayerDEF = "update players set defence=defence+'$playerDEF' where username='$playerNAME'";
mysql_query($statusplayerDEF) or die("Could not update player");

$statusplayerDEX = "update players set dexterity=dexterity+'$playerDEX' where username='$playerNAME'";
mysql_query($statusplayerDEX) or die("Could not update player");

$statusplayerMAG = "update players set magic=magic+'$playerMAG' where username='$playerNAME'";
mysql_query($statusplayerMAG) or die("Could not update player");

$statusplayerBASE_DAMAGE = "update players set basedamage=basedamage+'$playerBASE_DAMAGE' where username='$playerNAME'";
mysql_query($statusplayerBASE_DAMAGE) or die("Could not update player");

$statusplayerSPELL_BASE_DAMAGE = "update players set spellbasedamage=spellbasedamage+'$playerSPELL_BASE_DAMAGE' where username='$playerNAME'";
mysql_query($statusplayerSPELL_BASE_DAMAGE) or die("Could not update player");

$statusplayerHealthPOINTS = "update players set healthpoints='$playerMAX_HEALTH_POINTS' where username='$playerNAME'";
mysql_query($statusplayerHealthPOINTS) or die("Could not update player");

$statusplayerMaxHealthPOINTS = "update players set maxhealthpoints='$playerMAX_HEALTH_POINTS' where username='$playerNAME'";
mysql_query($statusplayerMaxHealthPOINTS) or die("Could not update player");

$statusplayerManaPOINTS = "update players set manapoints='$playerMAX_MANA_POINTS' where username='$playerNAME'";
mysql_query($statusplayerManaPOINTS) or die("Could not update player");

$statusplayerMaxManaPOINTS = "update players set maxmanapoints='$playerMAX_MANA_POINTS' where username='$playerNAME'";
mysql_query($statusplayerMaxManaPOINTS) or die("Could not update player");
} elseif ($playerCLASS === "Mage") {
$playerSTR = $playerSTR + 2;
$playerDEF = $playerDEF + 2;
$playerDEX = $playerDEX + 3;
$playerMAG = $playerMAG + 3;
$playerBASE_DAMAGE = ceil($playerSTR * $playerDEF);
$playerSPELL_BASE_DAMAGE = ceil($playerMAG * $playerDEX);
$playerMAX_HEALTH_POINTS = ceil($playerDEF * $playerDEX * $playerMAG);
$playerMAX_MANA_POINTS = ceil($playerMAG * $playerDEF * $playerDEX / $playerSTR);
} else {
}
}

if ($playerEXPERIENCE < 100) {
if (!$playerLEVEL ==1) {
$playerLEVEL = 1;
$statusplayerLEVELUPDATE = "update players set level='$playerLEVEL' where username='$playerNAME'";
mysql_query($statusplayerLEVELUPDATE ) or die("Could not update player");

} else {
$playerNEXT_LEVEL = 100;
}
} elseif ($playerEXPERIENCE >= 100 && $playerEXPERIENCE <= 200) {
if (!$playerLEVEL ==2) {
levelUPSTATS ();
$playerLEVEL = 2;
$statusplayerLEVELUPDATE = "update players set level='$playerLEVEL' where username='$playerNAME'";
mysql_query($statusplayerLEVELUPDATE ) or die("Could not update player");
} else {
$playerNEXT_LEVEL = 200;
}
} elseif ($playerEXPERIENCE >= 200 && $playerEXPERIENCE <= 400) {
if (!$playerLEVEL ==3) {
levelUPSTATS ();
$playerLEVEL = 3;
$statusplayerLEVELUPDATE = "update players set level='$playerLEVEL' where username='$playerNAME'";
mysql_query($statusplayerLEVELUPDATE ) or die("Could not update player");
} else {
$playerNEXT_LEVEL = 400;
}
} elseif ($playerEXPERIENCE >= 400 && $playerEXPERIENCE <= 800) {
if (!$playerLEVEL ==4) {
levelUPSTATS ();
$playerLEVEL = 4;
$statusplayerLEVELUPDATE = "update players set level='$playerLEVEL' where username='$playerNAME'";
mysql_query($statusplayerLEVELUPDATE ) or die("Could not update player");
} else {
$playerNEXT_LEVEL = 800;
}
} elseif ($playerEXPERIENCE >= 800 && $playerEXPERIENCE <= 1600) {
if (!$playerLEVEL ==5) {
levelUPSTATS ();
$playerLEVEL = 5;
$statusplayerLEVELUPDATE = "update players set level='$playerLEVEL' where username='$playerNAME'";
mysql_query($statusplayerLEVELUPDATE ) or die("Could not update player");
} else {
$playerNEXT_LEVEL = 1600;
}
} elseif ($playerEXPERIENCE >= 1600 && $playerEXPERIENCE <= 3200) {
if (!$playerLEVEL ==6) {

levelUPSTATS ();
$playerLEVEL = 6;
$statusplayerLEVELUPDATE = "update players set level='$playerLEVEL' where username='$playerNAME'";
mysql_query($statusplayerLEVELUPDATE ) or die("Could not update player");
} else {
$playerNEXT_LEVEL = 3200;
}
} elseif ($playerEXPERIENCE >= 3200 && $playerEXPERIENCE <= 6400) {
if (!$playerLEVEL ==7) {
levelUPSTATS ();
$playerLEVEL = 7;
$statusplayerLEVELUPDATE = "update players set level='$playerLEVEL' where username='$playerNAME'";
mysql_query($statusplayerLEVELUPDATE ) or die("Could not update player");
} else {
$playerNEXT_LEVEL = 6400;
}
} elseif ($playerEXPERIENCE >= 6400 && $playerEXPERIENCE <= 12800) {
if (!$playerLEVEL ==8) {
levelUPSTATS ();
$playerLEVEL = 8;
$statusplayerLEVELUPDATE = "update players set level='$playerLEVEL' where username='$playerNAME'";
mysql_query($statusplayerLEVELUPDATE ) or die("Could not update player");
} else {
$playerNEXT_LEVEL = 12800;
}
} elseif ($playerEXPERIENCE >= 12800 && $playerEXPERIENCE <= 25000) {
if (!$playerLEVEL ==9) {
levelUPSTATS ();
$playerLEVEL = 9;
$statusplayerLEVELUPDATE = "update players set level='$playerLEVEL' where username='$playerNAME'";
mysql_query($statusplayerLEVELUPDATE ) or die("Could not update player");
} else {
$playerNEXT_LEVEL = 25000;
}
} elseif ($playerEXPERIENCE >= 25000 && $playerEXPERIENCE <= 35000) {
if (!$playerLEVEL ==10) {
levelUPSTATS ();
$playerLEVEL = 10;
$statusplayerLEVELUPDATE = "update players set level='$playerLEVEL' where username='$playerNAME'";
mysql_query($statusplayerLEVELUPDATE ) or die("Could not update player");

} else {
$playerNEXT_LEVEL = 35000;
}
} elseif ($playerEXPERIENCE >= 35000 && $playerEXPERIENCE <= 50000) {
if (!$playerLEVEL ==11) {
levelUPSTATS ();
$playerLEVEL = 11;
$statusplayerLEVELUPDATE = "update players set level='$playerLEVEL' where username='$playerNAME'";
mysql_query($statusplayerLEVELUPDATE ) or die("Could not update player");
} else {
$playerNEXT_LEVEL = 50000;
}
} elseif ($playerEXPERIENCE >= 50000 && $playerEXPERIENCE <= 75000) {
if (!$playerLEVEL ==12) {
levelUPSTATS ();
$playerLEVEL = 12;
$statusplayerLEVELUPDATE = "update players set level='$playerLEVEL' where username='$playerNAME'";
mysql_query($statusplayerLEVELUPDATE ) or die("Could not update player");
} else {
$playerNEXT_LEVEL = 75000;
}
} elseif ($playerEXPERIENCE >= 75000 && $playerEXPERIENCE <= 100000) {
if (!$playerLEVEL ==13) {
levelUPSTATS ();
$playerLEVEL = 13;
$statusplayerLEVELUPDATE = "update players set level='$playerLEVEL' where username='$playerNAME'";
mysql_query($statusplayerLEVELUPDATE ) or die("Could not update player");
} else {
$playerNEXT_LEVEL = 100000;
}
} elseif ($playerEXPERIENCE >= 100000 && $playerEXPERIENCE <= 135000) {
if (!$playerLEVEL == 14) {
levelUPSTATS ();
$playerLEVEL = 14;
$statusplayerLEVELUPDATE = "update players set level='$playerLEVEL' where username='$playerNAME'";
mysql_query($statusplayerLEVELUPDATE ) or die("Could not update player");
} else {
$playerNEXT_LEVEL = 135000;
}
} elseif ($playerEXPERIENCE >= 135000 && $playerEXPERIENCE <= 200000) {
if (!$playerLEVEL ==15) {
levelUPSTATS ();
$playerLEVEL = 15;
$statusplayerLEVELUPDATE = "update players set level='$playerLEVEL' where username='$playerNAME'";
mysql_query($statusplayerLEVELUPDATE ) or die("Could not update player");
} else {
$playerNEXT_LEVEL = 200000;
}
} elseif ($playerEXPERIENCE >= 200000 && $playerEXPERIENCE <= 300000) {
if (!$playerLEVEL ==16) {

levelUPSTATS ();
$playerLEVEL = 16;
$statusplayerLEVELUPDATE = "update players set level='$playerLEVEL' where username='$playerNAME'";
mysql_query($statusplayerLEVELUPDATE ) or die("Could not update player");
} else {
$playerNEXT_LEVEL = 300000;
}
} elseif ($playerEXPERIENCE >= 300000 && $playerEXPERIENCE <= 420000) {
if (!$playerLEVEL ==17) {
levelUPSTATS ();
$playerLEVEL = 17;
$statusplayerLEVELUPDATE = "update players set level='$playerLEVEL' where username='$playerNAME'";
mysql_query($statusplayerLEVELUPDATE ) or die("Could not update player");
} else {
$playerNEXT_LEVEL = 420000;
}
} elseif ($playerEXPERIENCE >= 420000 && $playerEXPERIENCE <= 600000) {
if (!$playerLEVEL ==18) {
levelUPSTATS ();
$playerLEVEL = 18;
$statusplayerLEVELUPDATE = "update players set level='$playerLEVEL' where username='$playerNAME'";
mysql_query($statusplayerLEVELUPDATE ) or die("Could not update player");
} else {
$playerNEXT_LEVEL = 600000;
}
} elseif ($playerEXPERIENCE >= 600000 && $playerEXPERIENCE <= 800000) {
if (!$playerLEVEL ==19) {
levelUPSTATS ();
$playerLEVEL = 19;
$statusplayerLEVELUPDATE = "update players set level='$playerLEVEL' where username='$playerNAME'";
mysql_query($statusplayerLEVELUPDATE ) or die("Could not update player");
} else {
$playerNEXT_LEVEL = 800000;
}
} elseif ($playerEXPERIENCE >= 800000 && $playerEXPERIENCE <= 1000000) {
if (!$playerLEVEL ==20) {
levelUPSTATS ();
$playerLEVEL = 20;
$statusplayerLEVELUPDATE = "update players set level='$playerLEVEL' where username='$playerNAME'";
mysql_query($statusplayerLEVELUPDATE ) or die("Could not update player");
} else {
$playerNEXT_LEVEL = 1000000;
}
} elseif ($playerEXPERIENCE >= 1000000) {
if (!$playerLEVEL ==21) {
levelUPSTATS ();
$playerLEVEL = 21;
$statusplayerLEVELUPDATE = "update players set level='$playerLEVEL' where username='$playerNAME'";
mysql_query($statusplayerLEVELUPDATE ) or die("Could not update player");
}
} else {
print "N/A";
}

问题是它没有显示任何错误消息。

它不会正确更新统计数据,级别不会更新。

最佳答案

您是否测试过查询是否能够与您提供的值实际配合使用?即,使用 phpMyAdmin 或类似的并尝试手动查询?

我曾经遇到过这样的情况:我认为我的 PHP 不正确,但我的 SQL 中的一个小错误才是问题所在。

您可能还想将 PHP 的错误模式设置为 E_ALL。您可以在 php.ini 中或通过代码来做到这一点

ini_set("display_errors","2"); ERROR_REPORTING(E_ALL);

在脚本的开头。它应该[希望]给出一个错误来识别您的问题。


编辑

我刚刚注意到您的情况可能是问题所在......

你有:

if (!$playerLEVEL ==13) 
{
levelUPSTATS ();
$playerLEVEL = 13;
//etc
}

我相当怀疑 if block 永远不会运行,并且不会调用 levelUPSTATS()。

当您真正想要if $playerLEVEL is NOT EQUAL to 13时,您会问if NOT $playerLEVEL is NOT EQUAL to 13,这将满足以下条件:

if($playerLEVEL != 13)

注意!(NOT)所在的位置。

顺便说一句,您会遇到不平等的情况,某些边缘情况意味着玩家有两个级别。

例如,对于 2 级,您需要 100 到 200 EXP(含)。但是3级需要200和400 EXP(含)。如果你的玩家有 200EXP,他在技术上是 2 级和 3 级。当代码运行时,它将匹配代码 2 级部分中的 200,而不是 3 级部分...

您的代码:

if($playerEXPERIENCE >= 100 && $playerEXPERIENCE <= 200)
//code to make them 2
if($playerEXPERIENCE >= 200 $$ $playerEXPERIENCE <= 400)
//code to make them 3

这对我来说似乎是错误的 - 虽然这可能是你想要的,但我不知道。如果不是有意的,您应该将其更改为:

if($playerEXPERIENCE >= 100 && $playerEXPERIENCE < 200)

请注意使用 < [小于],而不是 <= [小于或等于]。

我希望这能解决您的问题:)

关于php mysql 游戏升级脚本问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1248418/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com