OK. Here goes.
The code that I have is for a battle script. Each player has X ammount of 'puppets' which in my game are what you would call monsters. Each monster can have up to 4 skills and go into a slot that the user chooses. Each skill has it's own piece of PHP that effects the way that the battle would go (eg; take health, change stats). The values for the puppets are constantly changing throughout the battle, so HP is constantly being taken each loop, that is relayed back to the user in a list. The problem is, the SQL doesn't seem to be sticking, or I'm missing something out. The HP doesn't always fall. My code is a complete mess which is why I might have become slightly lost with my code, but I will post it in chunks.
First, we find out if the player got to this page without choosing an opponent, or trying to attack themselves.
if(!isset($_GET['pid']))
{
oops();
}
elseif($_GET['pid']==$GETVAR['PL_DIWOR'])
{
oops();
}
else
{
then we get all the info about opponent.
$OPPID = $_GET['pid'];
$temp1 = "SELECT * FROM users where PL_DIWOR='$OPPID'";
$temp2 = mysql_query($temp1);
$OPP = mysql_fetch_array($temp2);
$temp3 = "SELECT * FROM bpuppet where PL_DIWOR='$OPPID' and PU_CURHP > '0'";
$temp4 = mysql_query($temp3);
$temp5 = "SELECT * FROM bpuppet where PL_DIWOR='$GETVAR[PL_DIWOR]' and PU_CURHP > '0'";
$temp6 = mysql_query($temp5);
$op=0;
while($OPPPUP = mysql_fetch_array($temp4))
{
$op++;
$OPOPUP[$op] = array("POD" => $PLAPUP['PO_DIWOR'], "PID" => $OPPPUP['PU_DIWOR'],"NAM" => $OPPPUP['PU_NICK'], "CHP" => $OPPPUP['PU_CURHP'], "MHP" => $OPPPUP['PU_MAXHP'], "S1" => $OPPPUP['PU_SKIL1'], "S2" => $OPPPUP['PU_SKIL2'], "S3" => $OPPPUP['PU_SKIL3'], "S4" => $OPPPUP['PU_SKIL4'], "NI" => $OPPPUP['PU_NICK'], "STR" => $OPPPUP['PU_STR'],"DEX" => $OPPPUP['PU_DEX'], "SPE" => $OPPPUP['PU_SPE'], "DEF" => $OPPPUP['PU_DEF']);
}
If the opponent has no puppets available to battle
if($op=='0')
{
oops();
}
else
{
now we check the player and show what puppets are abouts to battle.
echo "<center>";
$pl=0;
while($PLAPUP = mysql_fetch_array($temp6))
{
$pl++;
$PLOPUP[$pl] = array("POD" => $PLAPUP['PO_DIWOR'], "PID" => $PLAPUP['PU_DIWOR'], "NAM" => $PLAPUP['PU_NICK'], "CHP" => $PLAPUP['PU_CURHP'], "MHP" => $PLAPUP['PU_MAXHP'], "S1" => $PLAPUP['PU_SKIL1'], "S2" => $PLAPUP['PU_SKIL2'], "S3" => $PLAPUP['PU_SKIL3'], "S4" => $PLAPUP['PU_SKIL4'], "NI" => $PLAPUP['PU_NICK'], "STR" => $PLAPUP['PU_STR'], "DEX" => $PLAPUP['PU_DEX'], "SPE" => $PLAPUP['PU_SPE'], "DEF" => $PLAPUP['PU_DEF']);
}
if($pl == '1')
{
echo "You have ".$pl." Puppet. ";
}
else
{
echo "You have ".$pl." Puppets. ";
}
if($op == '1')
{
echo "Enemy ".name($OPP[PL_NAME])." has ".$op." Puppet.<br><br>";
}
else
{
echo "Enemy ".name($OPP[PL_NAME])." has ".$op." Puppets.<br><br>";
}
echo "<table width=80%><tr><td style='background: #ccc;vertical-align:middle;' width=45%><center>";
for ($i=1; $i<$pl+1; $i++)
{
$GETIMG = mysql_fetch_array(mysql_query("SELECT PU_IMG from puppet WHERE PU_DIWOR = '".$PLOPUP[$i]["PID"]."'"));
echo "<img src='monster/$GETIMG[PU_IMG]'><font color='black'> - ".$PLOPUP[$i]["NAM"]."</font><br>";
}
echo "<td width=10% style='vertical-align:middle;'><center><h1>VS</h1></center></td><td style='background: #ccc;vertical-align:middle;' width=45%><center>";
for ($j=1; $j<$op+1; $j++)
{
$GETIMG = mysql_fetch_array(mysql_query("SELECT PU_IMG from puppet WHERE PU_DIWOR = '".$OPOPUP[$j]["PID"]."'"));
echo "<img src='monster/$GETIMG[PU_IMG]'><FONT color='black'> - ".$OPOPUP[$j]["NAM"]."</font><br>";
}
echo "</tr></table><table width=80%><tr><td><center><b>Battle Commence</b><br><br>";
$winner = '0';
I also set $winner to 0 as there is no winner yet.
Now there is the main loop.
while ($winner == '0')
{
$turn = rand(1,2);
$temp3 = "SELECT * FROM bpuppet where PL_DIWOR='$OPPID' and PU_CURHP > '0'";
$temp4 = mysql_query($temp3);
$temp5 = "SELECT * FROM bpuppet where PL_DIWOR='$GETVAR[PL_DIWOR]' and PU_CURHP > '0'";
$temp6 = mysql_query($temp5);
if($turn == '1')
{
$pturn = rand(1,$pl);
echo $PLOPUP[$pturn]["NAM"]." attacks ";
$oppon = rand(1,$op);
echo $OPOPUP[$oppon]["NAM"]." with ";
$sk = 0;
if($PLOPUP[$pturn]["S1"] != '0')
{
++$sk;
$PLOSKI[$sk] = $PLOPUP[$pturn]["S1"];
}
if($PLOPUP[$pturn]["S2"] != '0')
{
++$sk;
$PLOSKI[$sk] = $PLOPUP[$pturn]["S2"];
}
if($PLOPUP[$pturn]["S3"] != '0')
{
++$sk;
$PLOSKI[$sk] = $PLOPUP[$pturn]["S3"];
}
if($PLOPUP[$pturn]["S4"] != '0')
{
++$sk;
$PLOSKI[$sk] = $PLOPUP[$pturn]["S4"];
}
$skill = rand(1,$sk);
$GETSKILLNAME = mysql_fetch_array(mysql_query("SELECT * FROM askills WHERE SK_DIWOR = '$PLOSKI[$skill]'"));
echo "$GETSKILLNAME[sK_NAME]<br>";
eval($GETSKILLNAME[sK_EFFECT]);
$op=0;
while($OPPPUP = mysql_fetch_array($temp4))
{
$op++;
$OPOPUP[$op] = array("PID" => $OPPPUP['PU_DIWOR'],"NAM" => $OPPPUP['PU_NICK'], "CHP" => $OPPPUP['PU_CURHP'], "MHP" => $OPPPUP['PU_MAXHP'], "S1" => $OPPPUP['PU_SKIL1'], "S2" => $OPPPUP['PU_SKIL2'], "S3" => $OPPPUP['PU_SKIL3'], "S4" => $OPPPUP['PU_SKIL4'], "NI" => $OPPPUP['PU_NICK'], "STR" => $OPPPUP['PU_STR'],"DEX" => $OPPPUP['PU_DEX'], "SPE" => $OPPPUP['PU_SPE'], "DEF" => $OPPPUP['PU_DEF']);
}
if($op=='0')
{
$winner='1';
}
echo "(".$OPOPUP[$oppon]["CHP"]." HP Remaining)<br>";
}
elseif($turn == '2')
{
$oppon = rand(1,$op);
echo $OPOPUP[$oppon]["NAM"]." attacks ";
$pturn = rand(1,$pl);
echo $PLOPUP[$pturn]["NAM"]." with ";
$sk = 0;
if($OPOPUP[$oppon]["S1"] != '0')
{
++$sk;
$OPOSKI[$sk] = $OPOPUP[$oppon]["S1"];
}
if($OPOPUP[$oppon]["S2"] != '0')
{
++$sk;
$OPOSKI[$sk] = $OPOPUP[$oppon]["S2"];
}
if($OPOPUP[$oppon]["S3"] != '0')
{
++$sk;
$OPOSKI[$sk] = $OPOPUP[$oppon]["S3"];
}
if($OPOPUP[$oppon]["S4"] != '0')
{
++$sk;
$OPOSKI[$sk] = $OPOPUP[$oppon]["S4"];
}
$skill = rand(1,$sk);
$GETSKILLNAME = mysql_fetch_array(mysql_query("SELECT * FROM askills WHERE SK_DIWOR = '$OPOSKI[$oppon]'"));
echo "$GETSKILLNAME[sK_NAME]<br>";
eval($GETSKILLNAME[sK_EFFECT]);
while($PLAPUP = mysql_fetch_array($temp6))
{
$pl++;
$PLOPUP[$pl] = array("PID" => $PLAPUP['PU_DIWOR'], "NAM" => $PLAPUP['PU_NICK'], "CHP" => $PLAPUP['PU_CURHP'], "MHP" => $PLAPUP['PU_MAXHP'], "S1" => $PLAPUP['PU_SKIL1'], "S2" => $PLAPUP['PU_SKIL2'], "S3" => $PLAPUP['PU_SKIL3'], "S4" => $PLAPUP['PU_SKIL4'], "NI" => $PLAPUP['PU_NICK'], "STR" => $PLAPUP['PU_STR'], "DEX" => $PLAPUP['PU_DEX'], "SPE" => $PLAPUP['PU_SPE'], "DEF" => $PLAPUP['PU_DEF']);
}
if($pl=='0')
{
$winner='2';
}
echo "(".$PLOPUP[$pturn]["CHP"]." HP Remaining)<br>";
}
$r++;
if($r=='40')
{
$winner=1;
}
}
echo "</td></tr></table></center>";
I have the $r in there so that if it is broken, it doesn't go on forever.
in my DB, the value of $GETSKILLNAME[sK_EFFECT] is
if($turn=='1')
{
takedamage($OPOPUP[$oppon]["POD"],"-2");
}
elseif($turn=='2')
{
takedamage($PLOPUP[$pturn]["POD"],"-2");
}
and the function that is being used is
function takedamage($POD,$AMMNT)
{
$sql = "SELECT PU_CURHP FROM bpuppet WHERE PO_DIWOR = '$POD'";
$sql2 = mysql_fetch_array(mysql_query($sql));
$newval = $sql2['PU_CURHP'] + $AMMNT;
if($newval <= 0)
{
$newval = 0;
}
$sql3 = "UPDATE bpuppet SET PU_CURHP = ".$newval." WHERE PO_DIWOR = '$POD'";
mysql_query($sql3);
}
What should happen is, everytime one of the puppets uses the skill "spark" which is what $GETSKILLNAME[sK_NAME] is, it should decrease the value of the opponents HP by 2
Kirby is the one and only Opponent Puppets
Ark, Elle and Fyda, are my Puppets.
None of the other skills apart from Spark do anything at the moment.
but my outcome is:
Kirby attacks Ark with Spark
(100 HP Remaining)
Elle attacks Kirby with Bite
(100 HP Remaining)
Fyda attacks Kirby with Punch
(100 HP Remaining)
Kirby attacks Elle with Spark
(100 HP Remaining)
Ark attacks Kirby with Shadows
(100 HP Remaining)
Elle attacks Kirby with Bite
(100 HP Remaining)
Ark attacks Kirby with Bite
(100 HP Remaining)
Fyda attacks Kirby with Punch
(100 HP Remaining)
Kirby attacks Fyda with Spark
(100 HP Remaining)
Ark attacks Kirby with Spark
(100 HP Remaining)
Kirby attacks Elle with Spark
(100 HP Remaining)
Kirby attacks Elle with Spark
(100 HP Remaining)
Ark attacks Kirby with Spark
(100 HP Remaining)
Kirby attacks Fyda with Spark
(100 HP Remaining)
Elle attacks Kirby with Spark
(100 HP Remaining)
Fyda attacks Kirby with Punch
(100 HP Remaining)
Kirby attacks Fyda with Spark
(100 HP Remaining)
Kirby attacks Elle with Spark
(94 HP Remaining)
Fyda attacks Kirby with Shadows
(100 HP Remaining)
Kirby attacks Elle with Spark
(94 HP Remaining)
Kirby attacks Ark with Spark
(98 HP Remaining)
Kirby attacks Elle with Spark
(94 HP Remaining)
Ark attacks Kirby with Spark
(100 HP Remaining)
Elle attacks Kirby with Bite
(100 HP Remaining)
Ark attacks Kirby with Shadows
(100 HP Remaining)
Kirby attacks Ark with Spark
(98 HP Remaining)
Kirby attacks Ark with Spark
(98 HP Remaining)
Kirby attacks Ark with Spark
(98 HP Remaining)
Fyda attacks Kirby with Punch
(100 HP Remaining)
Elle attacks Kirby with Bite
(100 HP Remaining)
Kirby attacks Fyda with Spark
(100 HP Remaining)
Kirby attacks Elle with Spark
(98 HP Remaining)
Kirby attacks Ark with Spark
(100 HP Remaining)
Kirby attacks Elle with Spark
(94 HP Remaining)
Ark attacks Kirby with Bite
(100 HP Remaining)
Fyda attacks Kirby with Shadows
(100 HP Remaining)
Elle attacks Kirby with Bite
(100 HP Remaining)
Kirby attacks Fyda with Spark
(100 HP Remaining)
Kirby attacks Ark with Spark
(98 HP Remaining)
Ark attacks Kirby with Bite
(100 HP Remaining)