Jump to content

Help with Arrays and a bit of Math.


TheMeq

Recommended Posts

Hi, I am TheMeq. I am currently developing a Text-Based MMORPG in PHP/MySQL. I have quite alot of the code laid down, its just this bit that is starting to throw me a bit. I've been working on it since 8am this morning.. it is now 4:30pm and i think it's nearly there. It's just not working the way I would like.

 

So if I was to ask for help, should I just post what code I have?

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

Ok, I've made some changes to my code, but now it just gets stuck and says

 

[22-Apr-2012 21:40:17 UTC] PHP Fatal error:  Maximum execution time of 30 seconds exceeded in /home/feeditme/public_html/ethereal/content.php(17) : eval()'d code on line 28

 

This is the eval'd code.

 

if(!isset($_GET['pid']))
{
	oops();
}
elseif($_GET['pid']==$GETVAR['PL_DIWOR'])
{
	oops();
}
else
{
	$OPPID = $_GET['pid'];
	$GETOPPONENT = mysql_fetch_array(mysql_query("SELECT * FROM users WHERE PL_DIWOR = '$OPPID'"));
	$GETOPPONENT_PUPPET = mysql_query("SELECT * FROM bpuppet WHERE PL_DIWOR = '$OPPID' and PU_CURHP > '0'");
	$GETPLAYER_PUPPET = mysql_query("SELECT * FROM bpuppet WHERE PL_DIWOR = '$GETVAR[PL_DIWOR]' and PU_CURHP > '0'");
	if(mysql_num_rows($GETOPPONENT_PUPPET)=='0')
		{
			oops();
		}
	elseif(mysql_num_rows($GETPLAYER_PUPPET)=='0')
		{
			oops();
		}
	else
		{
			$winner = '0';
			while($winner == '0')
				{		
					$GETOPPONENT_PUPPET = mysql_query("SELECT * FROM bpuppet WHERE PL_DIWOR = '$OPPID' and PU_CURHP > '0'");
					$GETPLAYER_PUPPET = mysql_query("SELECT * FROM bpuppet WHERE PL_DIWOR = '$GETVAR[PL_DIWOR]' and PU_CURHP > '0'");		
					if(mysql_num_rows($GETOPPONENT_PUPPET)=='0')
						{
							$winner = '1';
						}
					elseif(mysql_num_rows($GETPLAYER_PUPPET)=='0')
						{
							$winner = '2';
						}
					else
						{
							$OP_ARRAY = 0;
							$PL_ARRAY = 0;
							while($P_PUPPET = mysql_fetch_array($GETPLAYER_PUPPET))
								{
                                                                                $PL_ARRAY = $PL_ARRAY + 1;
									$PL_KEY_ARRAY[$PL_ARRAY] = array("PO_DIWOR" => $P_PUPPET['PO_DIWOR'], "PU_DIWOR" => $P_PUPPET['PU_DIWOR'], "PU_NICK" => $P_PUPPET['PU_NICK'], "PU_CURHP" => $P_PUPPET['PU_CURHP'], "PU_MAXHP" => $P_PUPPET['PU_MAXHP'], "PU_SKIL1" => $P_PUPPET['PU_SKIL1'],"PU_SKIL2" => $P_PUPPET['PU_SKIL2'],"PU_SKIL3" => $P_PUPPET['PU_SKIL3'],"PU_SKIL4" => $P_PUPPET['PU_SKIL4'],"PU_STR" => $P_PUPPET['PU_STR'],"PU_DEX" => $P_PUPPET['PU_DEX'],"PU_SPE" => $P_PUPPET['PU_SPE'],"PU_DEF" => $P_PUPPET['PU_DEF']);
								}
							while($O_PUPPET = mysql_fetch_array($GETOPPONENT_PUPPET))
								{
                                                                                $OP_ARRAY = $OP_ARRAY + 1;
									$OP_KEY_ARRAY[$OP_ARRAY] = array("PO_DIWOR" => $O_PUPPET['PO_DIWOR'], "PU_DIWOR" => $O_PUPPET['PU_DIWOR'], "PU_NICK" => $O_PUPPET['PU_NICK'], "PU_CURHP" => $O_PUPPET['PU_CURHP'], "PU_MAXHP" => $O_PUPPET['PU_MAXHP'], "PU_SKIL1" => $O_PUPPET['PU_SKIL1'],"PU_SKIL2" => $O_PUPPET['PU_SKIL2'],"PU_SKIL3" => $O_PUPPET['PU_SKIL3'],"PU_SKIL4" => $O_PUPPET['PU_SKIL4'],"PU_STR" => $O_PUPPET['PU_STR'],"PU_DEX" => $O_PUPPET['PU_DEX'],"PU_SPE" => $O_PUPPET['PU_SPE'],"PU_DEF" => $O_PUPPET['PU_DEF']);					
								}
							$ROUND = rand(1,2);

							if($ROUND == '1')
								{
									$PL_PUPPET = rand(1,mysql_num_rows($GETPLAYER_PUPPET));
									$OP_PUPPET = rand(1,mysql_num_rows($GETOPPONENT_PUPPET));
									$PL_SKILL = "";
									$PL_NUM_SKILL = 0;
									if($P_PUPPET[$PL_PUPPET]["PU_SKIL1"] != '0')
										{
											$PL_NUM_SKILL = $PL_NUM_SKILL + 1;
											$PL_SKILL[$PL_NUM_SKILL] = $PL_KEY_ARRAY[$PL_PUPPET]["PU_SKIL1"];												
										}
									if($P_PUPPET[$PL_PUPPET]["PU_SKIL2"] != '0')
										{
											$PL_NUM_SKILL = $PL_NUM_SKILL + 1;
											$PL_SKILL[$PL_NUM_SKILL] = $PL_KEY_ARRAY[$PL_PUPPET]["PU_SKIL2"];
										}
									if($P_PUPPET[$PL_PUPPET]["PU_SKIL3"] != '0')
										{
											$PL_NUM_SKILL = $PL_NUM_SKILL + 1;
											$PL_SKILL[$PL_NUM_SKILL] = $PL_KEY_ARRAY[$PL_PUPPET]["PU_SKIL3"];
										}
									if($P_PUPPET[$PL_PUPPET]["PU_SKIL4"] != '0')
										{
											$PL_NUM_SKILL = $PL_NUM_SKILL + 1;
											$PL_SKILL[$PL_NUM_SKILL] = $PL_KEY_ARRAY[$PL_PUPPET]["PU_SKIL4"];
										}
									$PL_USE_SKILL = rand(1,$PL_NUM_SKILL);
									$GET_PL_SKILL = mysql_fetch_array(mysql_query("SELECT * FROM askills WHERE SK_DIWOR = '$PL_SKILL[$PL_USE_SKILL]'"));
									eval($GET_PL_SKILL['SK_EFFECT']);
								}
							elseif($ROUND == '2')
								{
									$PL_PUPPET = rand(1,mysql_num_rows($GETPLAYER_PUPPET));
									$OP_PUPPET = rand(1,mysql_num_rows($GETOPPONENT_PUPPET));
									$OP_SKILL = "";
									$OP_NUM_SKILL = 0;
									if($O_PUPPET[$OP_PUPPET]["PU_SKIL1"] != '0')
										{
											$OP_NUM_SKILL = $OP_NUM_SKILL + 1;
											$OP_SKILL[$OP_NUM_SKILL] = $OP_KEY_ARRAY[$OP_PUPPET]["PU_SKIL1"];												
										}
									if($O_PUPPET[$OP_PUPPET]["PU_SKIL2"] != '0')
										{
											$OP_NUM_SKILL = $OP_NUM_SKILL + 1;
											$OP_SKILL[$OP_NUM_SKILL] = $OP_KEY_ARRAY[$OP_PUPPET]["PU_SKIL2"];
										}
									if($O_PUPPET[$OP_PUPPET]["PU_SKIL3"] != '0')
										{
											$OP_NUM_SKILL = $OP_NUM_SKILL + 1;
											$OP_SKILL[$OP_NUM_SKILL] = $OP_KEY_ARRAY[$OP_PUPPET]["PU_SKIL3"];
										}
									if($O_PUPPET[$OP_PUPPET]["PU_SKIL4"] != '0')
										{
											$OP_NUM_SKILL = $OP_NUM_SKILL + 1;
											$OP_SKILL[$OP_NUM_SKILL] = $OP_KEY_ARRAY[$OP_PUPPET]["PU_SKIL4"];
										}
									$OP_USE_SKILL = rand(1,$OP_NUM_SKILL);
									$GET_OP_SKILL = mysql_fetch_array(mysql_query("SELECT * FROM askills WHERE SK_DIWOR = '$OP_SKILL[$OP_USE_SKILL]'"));
									eval($GET_OP_SKILL['SK_EFFECT']);
								}
						}
				}
			if($winner == '1')
				{
					echo "You Won";
				}
			else
				{
					echo "Enemy Won";
				}
		}
}

 

Any help?!

 

Thanks

Link to comment
Share on other sites

Ok, the error is in your takedamage function, and nowhere else.  You need to debug just this function.  Your code has no error handling or even any concept that something could go wrong, so debugging is going to be difficult.

 

First, dump the SELECT and UPDATE statements to the screen before they're called.

 

Then, add output for mysql_error() after every mysql_query command.

 

You should be adding error-handling code to all of these queries, especially if you're a new developer.  It should be something like:

 

$rs = mysql_query($sql);
if ( !$rs ) {
  echo "ERROR IN QUERY: <br /><i>{$sql}</i><br />Mysql Returned: " . mysql_error() . "<P />";
}
$row = mysql_fetch_array($rs);//or whatever, proceed with your code.

Link to comment
Share on other sites

Thanks, I've added echo's to lots of my mysql functions. And found out where the issue possibly is.

 

	$ROUND = rand(1,2);

if($ROUND == '1')
	{
		$PL_PUPPET = rand(1,mysql_num_rows($GETPLAYER_PUPPET));
		$OP_PUPPET = rand(1,mysql_num_rows($GETOPPONENT_PUPPET));
		unset($PL_SKILL);
		$PL_NUM_SKILL = '0';
		if($P_PUPPET['$PL_PUPPET']["PU_SKIL1"] != '0')
			{
				$PL_NUM_SKILL = $PL_NUM_SKILL + '1';
				$PL_SKILL['$PL_NUM_SKILL'] = $PL_KEY_ARRAY['$PL_PUPPET']["PU_SKIL1"];												
			}
		if($P_PUPPET['$PL_PUPPET']["PU_SKIL2"] != '0')
			{
				$PL_NUM_SKILL = $PL_NUM_SKILL + '1';
				$PL_SKILL['$PL_NUM_SKILL'] = $PL_KEY_ARRAY['$PL_PUPPET']["PU_SKIL2"];
			}
		if($P_PUPPET['$PL_PUPPET']["PU_SKIL3"] != '0')
			{
				$PL_NUM_SKILL = $PL_NUM_SKILL + '1';
				$PL_SKILL['$PL_NUM_SKILL'] = $PL_KEY_ARRAY['$PL_PUPPET']["PU_SKIL3"];
			}
		if($P_PUPPET['$PL_PUPPET']["PU_SKIL4"] != '0')
			{
				$PL_NUM_SKILL = $PL_NUM_SKILL + '1';
				$PL_SKILL['$PL_NUM_SKILL'] = $PL_KEY_ARRAY['$PL_PUPPET']["PU_SKIL4"];
			}
		$PL_USE_SKILL = rand(1,$PL_NUM_SKILL);
		$rql = "SELECT * FROM askills WHERE SK_DIWOR = '".$PL_SKILL['$PL_USE_SKILL']."'";
echo $rql." -RQL<br>";
		$tql = mysql_query($rql) or die(mysql_error());
		$GET_PL_SKILL = mysql_fetch_array($tql);
		eval($GET_PL_SKILL['SK_EFFECT']);
	}
elseif($ROUND == '2')
	{
		$PL_PUPPET = rand(1,mysql_num_rows($GETPLAYER_PUPPET));
		$OP_PUPPET = rand(1,mysql_num_rows($GETOPPONENT_PUPPET));
		unset($OP_SKILL);
		$OP_NUM_SKILL = '0';
		if($O_PUPPET[$OP_PUPPET]["PU_SKIL1"] != '0')
			{
				$OP_NUM_SKILL = $OP_NUM_SKILL + '1';
				$OP_SKILL['$OP_NUM_SKILL'] = $OP_KEY_ARRAY['$OP_PUPPET']["PU_SKIL1"];												
			}
		if($O_PUPPET['$OP_PUPPET']["PU_SKIL2"] != '0')
			{
				$OP_NUM_SKILL = $OP_NUM_SKILL + '1';
				$OP_SKILL['$OP_NUM_SKILL'] = $OP_KEY_ARRAY['$OP_PUPPET']["PU_SKIL2"];
			}
		if($O_PUPPET['$OP_PUPPET']["PU_SKIL3"] != '0')
			{
				$OP_NUM_SKILL = $OP_NUM_SKILL + '1';
				$OP_SKILL['$OP_NUM_SKILL'] = $OP_KEY_ARRAY['$OP_PUPPET']["PU_SKIL3"];
			}
		if($O_PUPPET['$OP_PUPPET']["PU_SKIL4"] != '0')
			{
				$OP_NUM_SKILL = $OP_NUM_SKILL + '1';
				$OP_SKILL['$OP_NUM_SKILL'] = $OP_KEY_ARRAY['$OP_PUPPET']["PU_SKIL4"];
		}
		$OP_USE_SKILL = rand(1,$OP_NUM_SKILL);
		$vql = "SELECT * FROM askills WHERE SK_DIWOR = '".$OP_SKILL['$OP_USE_SKILL']."'";
echo $vql." -VQL<br>";
		$uql = mysql_query($vql) or die(mysql_error());
		$GET_OP_SKILL = mysql_fetch_array($uql);
		eval($GET_OP_SKILL['SK_EFFECT']);
	}

 

OK, the two blocks above are very similar. But when I echo out $vql and $rql, i get this:

 

SELECT * FROM askills WHERE SK_DIWOR = '' -VQL

 

SK_DIWOR should equal $OP_KEY_ARRAY['$OP_PUPPET']["PU_SKILX"] according to my code. But it comes back as blank. It all looks ok to me, but maybe i've missed something.

Link to comment
Share on other sites

$OP_KEY_ARRAY['$OP_PUPPET']["PU_SKILX"]

The first key is equal to the string $OP_PUPPET not the value of $OP_PUPPET. If you put a variable in single quotes it does not evaluate. You either want $OP_PUPPET or 'OP_PUPPET'

Link to comment
Share on other sites

Thats working so much better now, Thank you very much. Another issue now.

 

unset($OP_SKILL);
$OP_NUM_SKILL = "0";
echo " 1 - ".$OP_KEY_ARRAY["$OP_PUPPET"]["PU_SKIL1"];
echo " 2 - ".$OP_KEY_ARRAY["$OP_PUPPET"]["PU_SKIL2"];
echo " 3 - ".$OP_KEY_ARRAY["$OP_PUPPET"]["PU_SKIL3"];
echo " 4 - ".$OP_KEY_ARRAY["$OP_PUPPET"]["PU_SKIL4"];
if($O_PUPPET["$OP_PUPPET"]["PU_SKIL1"] != "0")
        {
        $OP_NUM_SKILL = $OP_NUM_SKILL + "1";
        	$OP_SKILL["$OP_NUM_SKILL"] = $OP_KEY_ARRAY["$OP_PUPPET"]["PU_SKIL1"];												
}
if($O_PUPPET["$OP_PUPPET"]["PU_SKIL2"] != "0")
{
	$OP_NUM_SKILL = $OP_NUM_SKILL + "1";
	$OP_SKILL["$OP_NUM_SKILL"] = $OP_KEY_ARRAY["$OP_PUPPET"]["PU_SKIL2"];
}
if($O_PUPPET["$OP_PUPPET"]["PU_SKIL3"] != "0")
{
	$OP_NUM_SKILL = $OP_NUM_SKILL + "1";
	$OP_SKILL["$OP_NUM_SKILL"] = $OP_KEY_ARRAY["$OP_PUPPET"]["PU_SKIL3"];
}
if($O_PUPPET["$OP_PUPPET"]["PU_SKIL4"] != "0")
{
	$OP_NUM_SKILL = $OP_NUM_SKILL + "1";
	$OP_SKILL["$OP_NUM_SKILL"] = $OP_KEY_ARRAY["$OP_PUPPET"]["PU_SKIL4"];
}
echo $OP_NUM_SKILL;

 

$OP_NUM_SKILL always = 4 even if SKIL3 and SKIL4 equal "0".

same for the $PL_NUM_SKILL as well.  :confused:

Link to comment
Share on other sites

You either want $OP_PUPPET or 'OP_PUPPET'

"$OP_PUPPET" takes longer to evaluate. See above.

You have so much in your code in strings that doesn't need to be. A number is not a string. Just because PHP will evaluate it usually ok doesn't make it right. Fix all your numbers and variables that don't need to be inside strings.

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.