Jump to content

Battle Script... Huge Problem!


grlayouts

Recommended Posts

Ok i have my own online game, when people battle im trying to make it fair.

 

they get 100HP or more depending on level however with the way the stats are set up wepons and armor when the script runs you get

 

admin attacks (guest) for 30hp
guest attacks admin for -10hp <--- causing the players hp to go above 100..

so with the code below how do i get it to stop displaying minus stats.

[code]
<?php $title = "Battle"; include("header.php"); ?>

<?
global $stat;
global $enemy;
global $myarm;
global $mywep;
global $earm;
global $ewep;
?>
<?php
if (($stat[attacksdone]  >4 )) {
print "<center>Your tired and need a rest, try again soon.";
include("footer.php");
exit;
}
?>
<?php
function attack() {
global $stat;
global $enemy;
global $myarm;
global $mywep;
global $earm;
global $ewep;

$repeat = ($stat[agility] / $enemy[agility] / 2);
$attackstr = ceil($repeat);
if ($attackstr <= 0) {
	$attackstr = 1;
}
$mypower = ($mywep[power]  + $stat[strength] - ($earm[power] / 2));
$epower = ($enemy[strength]  +  $ewep[power] - $myarm[power]);

$attackdmg = ($mypower);
$round = 1;
while ($round <= $attackstr && $enemy[hp] >= 0) {
	$enemy[hp] = ($enemy[hp] - $attackdmg);
	print "<b>$stat[user]</b> attacks <b>$enemy[user]</b> for <b><font color=green>$attackdmg</font></b> damage! ($enemy[hp] left)<br>";
	$round = ($round + 1);
}

if ($enemy[hp] <= 0) {
	$enemy[hp] = 0;
	print "<br><b>$stat[user]</b> is the winner!<br>";
	$expgain = $enemy[level] * rand(3,4);
	$creditgain = ($enemy[credits] / 2 );
	print "<b>$stat[user]</b> have gained <b>$expgain</b> EXP and <b>$creditgain</b> cash.
	<br><b>$enemy[user]</b> has lost <b>0.1</b> strength.
	<br><b>$stat[user]</b> you have lost <b>0.3</b> agility.

	";
	mysql_query("update players set hp=$stat[hp] where id=$stat[id]");
	mysql_query("update players set hp=0 where id=$enemy[id]");
	mysql_query("update players set exp=exp+$expgain where id=$stat[id]");
	mysql_query("update players set line='Dead' where id=$enemy[id]");
	mysql_query("update players set alive='red' where id=$enemy[id]");
	mysql_query("update players set line='Alive' where id=$stat[id]");
	mysql_query("update players set alive='green' where id=$stat[id]");
	mysql_query("update players set credits=credits+$creditgain where id=$stat[id]");
	mysql_query("update players set cashlost=cashlost+$creditgain where id=$enemy[id]");
	mysql_query("update players set strength=strength-0.1 where id=$enemy[id]");
	mysql_query("update players set agility=agility-0.3 where id=$stat[id]");
	mysql_query("update players set cashwon=cashwon+$creditgain where id=$stat[id]");
	mysql_query("update players set credits=0 where id=$enemy[id]");
	mysql_query("update players set wins=wins+1 where id=$stat[id]");
	mysql_query("update players set hp=0 where id=$enemy[id]");
	mysql_query("update players set hp=max_hp where id=$stat[id]");
	mysql_query("update players set attacksdone=attacksdone+1 where id=$stat[id]");
	mysql_query("update players set losses=losses+1 where id=$enemy[id]");
	mysql_query("update players set lastkilled='$enemy[user]' where id=$stat[id]");
	mysql_query("update players set lastkilledby='$stat[user]' where id=$enemy[id]");
	$texp = ($stat[exp] + $expgain);
	$expn = (($stat[level] * 50) + ($stat[level] * 15));
	if ($texp >= $expn) {
		print "<b>$stat[user]</b> gained a level!  and +1 Level.";
		mysql_query("update players set level=level+1 where id=$stat[id]");
		mysql_query("update players set max_hp=max_hp+10 where id=$stat[id]");
		mysql_query("update players set exp=0 where id=$stat[id]");
		mysql_query("insert into log (owner, log) values($stat[id],'During a fight with <b>$enemy[user]</b>, you gained a level.')");
}
	mysql_query("insert into log (owner, log) values($stat[id],'You have defeated <b>$enemy[user]</b>. Gained <b>$expgain</b> EXP and <b>$creditgain</b> credits.')");
	mysql_query("insert into log (owner, log) values($enemy[id],'You were defeated by <b>$stat[user]</b>. And lost 0.1 Strength')");			

	include("footer.php");
	exit;
} else {
	attackback();
}
}

function attackback() {
global $stat;
global $enemy;
global $myarm;
global $mywep;
global $earm;
global $ewep;

$repeat = ($enemy[agility] / $stat[agility] / 2);
$attackstr = ceil($repeat);
if ($attackstr <= 0) {
	$attackstr = 1;
}
$mypower = ($mywep[power] + $stat[strength] - ($earm[power] / 2));
$epower = ($enemy[strength] + $ewep[power] - ($myarm[power] / 2));

$attackdmg = ($epower);
$round = 1;
while ($round <= $attackstr && $stat[hp] >= 0) {
	$stat[hp] = ($stat[hp] - $attackdmg);
	print "<b>$enemy[user]</b> attacks <b>$stat[user]</b> for <b><font color=red>$attackdmg</font></b> damage! ($stat[hp] left)<br>";
	$round = ($round + 1);
}

if ($stat[hp] <= 0) {
	print "<br>To bad...You lost! <br>";
	$expgain = $enemy[level] * rand(3,4);
	$credittgain = ($stat[credits] / 2);
	print "<b>$enemy[user]</b> just gained <b>$expgain</b> EXP and <b>$credittgain</b> cash.<br>
		<br> $stat[user] You have also lost 0.3 agility.";
	mysql_query("update players set hp=$enemy[hp] where id=$enemy[id]");
	mysql_query("update players set line='Dead' where id=$stat[id]");
	mysql_query("update players set alive='red' where id=$stat[id]");

		mysql_query("update players set line='Alive' where id=$enemy[id]");
	mysql_query("update players set alive='green' where id=$enemy[id]");
mysql_query("update players set hp=0 where id=$stat[id]");
	mysql_query("update players set exp=exp+$expgain where id=$enemy[id]");
	mysql_query("update players set credits=credits+$credittgain where id=$enemy[id]");
	mysql_query("update players set cashwon=cashwon+$credittgain where id=$enemy[id]");
	mysql_query("update players set cashlost=cashlost+$credittgain where id=$stat[id]");
	mysql_query("update players set credits=0 where id=$stat[id]");
	mysql_query("update players set wins=wins+1 where id=$enemy[id]");
	mysql_query("update players set agility=agility-0.3 where id=$stat[id]");
	mysql_query("update players set strength=strength-0.1 where id=$enemy[id]");
	mysql_query("update players set losses=losses+1 where id=$stat[id]");
	mysql_query("update players set lastkilled='$stat[user]' where id=$enemy[id]");
	mysql_query("update players set lastkilledby='$enemy[user]' where id=$stat[id]");
	$texp = ($enemy[exp] + $expgain);
	$expn = (($enemy[level] * 50) + ($enemy[level] * 15));
	if ($texp >= $expn) {
		print "<b>$enemy[user]</b> gained a level! .";
		mysql_query("update players set level=level+1 where id=$enemy[id]");
		mysql_query("update players set exp=0 where id=$enemy[id]");
		mysql_query("update players set max_hp=max_hp+10 where id=$enemy[id]");				
		mysql_query("insert into log (owner, log) values($enemy[id],'During a fight with <b>$stat[user]</b>, you gained a level.')");	
	}
	mysql_query("insert into log (owner, log) values($enemy[id],'You have defeated <b>$stat[user]</b>. Gained <b>$expgain</b> EXP and <b>$creditgain</b> credits.')");
	mysql_query("insert into log (owner, log) values($stat[id],'You were defeated by <b>$enemy[user]</b>.')");	

	include("footer.php");
	exit;
} else {
	attack();
}
}
?>

<?php
if (!$action && !$battle) {
print "Welcome to the battle arena.<br><br>
 <a href=battle.php?action=levellist>List by level...</a><br>Here you can battle people at the level you choose.<br>
 <a href=battle.php?action=showalive>Show alive players at my level</a><br>All the alive player at your level.<br>
<a href=battle.php?action=advanced&min=0>Advanced Search</a><br>Here you can choose people with certain stats.

<br>
 <a href=arena.php>Pvp Arena </a><br>where you can fight as a group<br>


";
print "<form method=post action=view.php?view=$view&step=find>";
print "<b>Search for hobo  </b><br><hr color=black width=35% align=left></hr><br>   Name/ID           <input type=text name='view' size=15> <input type=submit value=Search>";

print "</form>";
}

if ($action == showalive) {
print "Showing all alive at level $stat[level]...<br><br>";
	print "<table cellspacing=0 cellpadding=1 width=100%>
<tr bgcolor=#240000>
<td width=25% align=left><b>Name (ID)</u></b>
<td width=10%  align=center ><b>Level</u></b>
<td width=10%  align=center ><b>Health</u></b>
<TD width=10% align=center ><b>War</u></b>
<TD width=10% align=center ><b>Staff</u></b>
<TD width=35% align=center ><b>Option</u></b>
<tr>";
$esel = mysql_query("select * from players where level=$stat[level] and hp>0 limit 5000");
	while ($elist = mysql_fetch_array($esel)) {
echo"
<TD align=center><A HREF=view.php?view=$elist[id]>$elist[user]</A> ($elist[id])
<TD align=center>$elist[level]";

echo "<TD align=center>";	
if ($elist[hp] < "1")
{ 
echo "<img src=images/dead.gif> ";
} 
else 
{																																																																										{
echo "<img src=images/alive.gif> ";
}
}


echo "<TD align=center>";


echo "$elist[side] ";

echo "<TD align=center>";
if ($elist[rank] != Member) 
{
echo "<img alt='$elist[rank]' src=images/admin.gif> ";
}

if ($elist[rank] == Member) 
{
echo "- ";
}


echo " 
<TD align=center><A HREF=battle.php?battle=$elist[id]>Battle</A>
<tr>";



}

echo "</table><p>";
print "Or you can always... <a href=battle.php>go back</a>.";
}
if ($action == levellist) {
print "<form method=post action=battle.php?action=levellist&step=go>";
print "Show me all alive at... <select name=slevel>";
for ($i = 1; $i < 100; ++$i) {
	print "<option value=$i>Level $i</option>";
}
print "</select> <input type=submit value=Go></form>";

if ($step == go) {
	print "<table cellspacing=0 cellpadding=1 width=100%>
<tr bgcolor=#240000>
<td width=25% align=left><b>Name (ID)</u></b>
<td width=10%  align=center ><b>Level</u></b>
<td width=10%  align=center ><b>Health</u></b>
<TD width=10% align=center ><b>Gang</u></b>
<TD width=35% align=center ><b>Option</u></b>
<tr>";
$esel = mysql_query("select * from players where level=$slevel and hp>0 limit 5000");
	while ($elist = mysql_fetch_array($esel)) {
echo"
<TD align=center><A HREF=view.php?view=$elist[id]>$elist[user]</A> ($elist[id])
<TD align=center>$elist[level]";

echo "<TD align=center>";	
if ($elist[hp] < "1")
{ 
echo "<img src=images/dead.gif> ";
} 
else 
{																																																																										{
echo "<img src=images/alive.gif> ";
}
}


echo "<TD align=center>";


echo "$elist[zone1] ";




echo " 
<TD align=center><A HREF=battle.php?battle=$elist[id]>Battle</A>
<tr>";



}

echo "</table><p>";
	print "Or you can always... <a href=battle.php>go back</a>.";
}
}	
if($action == "advanced"){
if(!$_GET['step']){
echo "<B>Advanced Search</B><BR><BR>";
echo "<FORM METHOD=POST ACTION=battle.php?action=advanced&step=search&min=0>";
if($stat['level'] == 1 || $stat['level'] == 2){
$low = 1;
}
else
{
$low = $stat[level]-2;
}
$hi = ceil($stat[level]*2);
echo "Level: <INPUT name=minlvl VALUE=\"$low\" SIZE=3> to <INPUT name=maxlvl VALUE=\"$hi\" SIZE=3><BR>";
echo "Level Attack Range: $low - $hi,<br>";
echo "Credits in hand</B>: <INPUT name=mincr size=8> to <INPUT name=maxcr size=8><BR>";
echo "</SELECT><BR><BR>";
echo "Order By:
<SELECT NAME=order>
<OPTION VALUE=none>None</OPTION>
<OPTION VALUE=id>ID</OPTION>
<OPTION VALUE=user>Name</OPTION>
<OPTION VALUE=level>Level</OPTION>
<OPTION VALUE=credits>Cash</OPTION>
</SELECT> 
<SELECT NAME=direction>
<OPTION VALUE=asc>Ascending</OPTION>
<OPTION VALUE=desc>Descending</OPTION>
</SELECT>

<BR><BR>";
echo "<INPUT TYPE=SUBMIT VALUE='Find Players'></FORM>";
echo "<p><center>[<a href=battle.php>Back</a>]</center>";
}















if($_GET['step'] === "search"){
$query = "SELECT * FROM `players` WHERE ";
$query .= "level >= $minlvl AND ";
$query .= "level <= $maxlvl AND ";
if (!empty($minfeel)) {
$query .= "align>=" . $_POST['minfeel'] . " AND ";
}
if (!empty($maxfeel)) {
$query .= "align>=" . $_POST['maxfeel'] . " AND ";
}
if (!empty($mincr)) {
$query .= "credits>=" . $_POST['mincr'] . " AND ";
}
if (!empty($maxcr)) {
$query .= "credits<=" . $_POST['maxcr'] . " AND ";
}

if ($clansetup == "not") 
{

}

if ($clansetup == "notmine") 
{
$query .=  "tribe!=" . $stat['tribe'] . " AND ";
}
if ($clansetup == "in")	 
{
$query .= "tribe=" . $_POST['clan'] . " AND ";
}

$query .= "hp >= 1 ";
if ($order != "none") {
$query .= " ORDER BY $order $direction";
}

$query .= " LIMIT $min,25";

$get_results = mysql_query("$query") or die (mysql_error());



echo "Advanced Search Results:<p>
<table cellspacing=0 cellpadding=1 width=100%>
<tr bgcolor=#240000>
<td width=25% align=left><b>Name (ID)</u></b>
<td width=10%  align=center ><b>Level</u></b>
<td width=10%  align=center ><b>Health</u></b>
<TD width=10% align=center ><b>Gang</u></b>
<TD width=35% align=center ><b>Option</u></b>
<tr>";


while($test = mysql_fetch_array($get_results))
{
echo"
<TD align=center><A HREF=view.php?view=$test[id]>$test[user]</A> ($test[id])
<TD align=center>$test[level]";

echo "<TD align=center>";	
if ($test[hp] < "1")
{ 
echo "<img src=images/dead.gif> ";
} 
else 
{																																																																										{
echo "<img src=images/alive.gif> ";
}
}


echo "<TD align=center>";


echo "$test[zone1] ";


echo " 
<TD align=center><A HREF=battle.php?battle=$test[id]>Battle</A>
<tr>";



}

echo "</table><p>";



if($min == "0")
{
$texter = $min + 25;
echo "<p><form method=post action=battle.php?action=advanced&step=search&min=$texter> 
<input type=hidden name=minlvl value=$minlvl>
<input type=hidden name=maxlvl value=$maxlvl>
<input type=hidden name=minfeel value=$minfeel>
<input type=hidden name=maxfeel value=$maxfeel>
<input type=hidden name=mincr value=$mincr>
<input type=hidden name=maxcr value=$maxcr>
<input type=hidden name=clansetup value=$clansetup>
<input type=hidden name=order value=$order>
<input type=hidden name=direction value=$direction>
<input type=submit name=go value=\"Next 25\"></form>";
}
else
{
$texterb = $min - 25;
$texter = $min + 25;
echo "<p><table><td><form method=post action=battle.php?action=advanced&step=search&min=$texterb> 
<input type=hidden name=minlvl value=$minlvl>
<input type=hidden name=maxlvl value=$maxlvl>
<input type=hidden name=minfeel value=$minfeel>
<input type=hidden name=maxfeel value=$maxfeel>
<input type=hidden name=mincr value=$mincr>
<input type=hidden name=maxcr value=$maxcr>
<input type=hidden name=clansetup value=$clansetup>
<input type=hidden name=order value=$order>
<input type=hidden name=direction value=$direction>
<input type=submit name=go value=\"Previous 25\"></form></td>

<td><form method=post action=battle.php?action=advanced&step=search&min=$texter> 
<input type=hidden name=minlvl value=$minlvl>
<input type=hidden name=maxlvl value=$maxlvl>
<input type=hidden name=minfeel value=$minfeel>
<input type=hidden name=maxfeel value=$maxfeel>
<input type=hidden name=mincr value=$mincr>
<input type=hidden name=maxcr value=$maxcr>
<input type=hidden name=clansetup value=$clansetup>
<input type=hidden name=order value=$order>
<input type=hidden name=direction value=$direction>
<input type=submit name=go value=\"Next 25\"></form></td>
</table>


";	}





echo "<p><center>[<a href=battle.php?action=advanced>Back</a>]</center>";
}
}
if ($battle) {
global $stat;
global $enemy;
global $myarm;
global $mywep;
global $earm;
global $ewep;

$enemy = mysql_fetch_array(mysql_query("select * from players where id=$battle"));
$mywep = mysql_fetch_array(mysql_query("select * from equipment where owner=$stat[id] and type='W' and status='E'"));
$myarm = mysql_fetch_array(mysql_query("select * from equipment where owner=$stat[id] and type='A' and status='E'"));
$ewep = mysql_fetch_array(mysql_query("select * from equipment where owner=$enemy[id] and type='W' and status='E'"));
$earm = mysql_fetch_array(mysql_query("select * from equipment where owner=$enemy[id] and type='A' and status='E'"));

if (!$enemy[id]) {
	print "No such player.";
	include("footer.php");
	exit;
}
if ($enemy[id] == $stat[id]) {
	print "You cannot attack yourself.";
	include("footer.php");	
	exit;
}
if ($enemy[hp] <= 0) {
	print "$enemy[user] is already dead.";
	include("footer.php");
	exit;
		}
if ($stat[prison] > 0) {
	print "Your are in prison idiot, what the hell do you think you can do from there.";
	include("footer.php");
	exit;
}
	if ($enemy[prison] > 0) {
	print "$enemy[user] is in prison.";
	include("footer.php");
	exit;
}
	if ($enemy[protection] >0) {
	print "$enemy[user] is being protected by the mob";
	include("footer.php");
	exit;
}
if ($stat[energy] < 10) {
	print "You do not have enough energy, you need 10 energy.";
	include("footer.php");
	exit;
}

if ($enemy[level] < $stat[level] / 2) {
	print "That player is less than half your level pick on someone higher.";
	include("footer.php");
	exit;
}
if ($enemy[level] > $stat[level] * 2) {
	print "You can only attack people up to 2x your level .";
	include("footer.php");
	exit;
}
if ($stat[hp] <= 0) {
	print "You're dead.";
	include("footer.php");
	exit;
}
	if ($stat[attacksdone] >3) {
	mysql_query("update players set hp=0 where id=$stat[id]");
	mysql_query("update players set lastkilled='LocalGang' where id=$stat[id]");
	print "A Local Gang seen you walking the streets attacking everyone. 'Enjoy your trip to hospital'";
	include("footer.php");
	exit;
}
if ($enemy[tribe] == $stat[tribe] && $enemy[tribe] ) {
	print "Dont attack your own gang you fool!";
	include("footer.php");	
	exit;
}
	if ($enemy[city] !== $stat[city] && $enemy[city] ) {
	print "Sorry $enemy[user] is in another city & cannot be attacked here.!";
	include("footer.php");	
	exit;
}
	print "<b><u>$stat[user] vs. $enemy[user]</b></u><br>";
mysql_query("update players set energy=energy-10 where id=$stat[id]");
if ($stat[agility] >= $enemy[agility]) {
	attack();
} else {
	attackback();
}
}
?>

[/code]

Link to comment
https://forums.phpfreaks.com/topic/38149-battle-script-huge-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.