Jump to content
MakeWebGames

Recommended Posts

Posted

How would I be able to do this? It's pretty important for my game, which Humans have to fight Aliens. Basically, instead of Male and Female, there are just Human and Alien.

I need to make sure Humans don't fight other Humans and Aliens don't fight other Aliens.

Posted

Re: Males only attack females and vice versa?

well lets say in the database humans are 1 aliens are 0 and the column is called race then do

if ($ir['race]==$r['race'])

die ("You can't attack your own species");

else

{

your attack script here

}

Posted

Re: Males only attack females and vice versa?

Still not working, no errors, but not working. This is the original file without the script added.

attack.php

<?php
$menuhide=0;
$atkpage=1;
include "globals.php";

$user_class=$ir;
$q=$db->query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid={$_GET['ID']}");
$attack_person=$db->fetch_row($q);
$qo=$db->query("SELECT i.* FROM items i   WHERE i.itmid={$user_class['equip_primary']}");
$user_class1=$db->fetch_row($qo);
$q1=$db->query("SELECT i.* FROM items i   WHERE i.itmid={$user_class['equip_armor']}");
$user_class2=$db->fetch_row($q1);
$weapon= "{$user_class1['itmname']}";
if(mysql_num_rows($qo) == 0) {
			$weapon="Fists";
			} 
$eq=$db->query("SELECT i.* FROM  items i  WHERE i.itmid IN({$attack_person['equip_primary']})");
		if(mysql_num_rows($eq) == 0) {
			$wep="Fists";
			} else {
			$cnt=0;
			while($r=$db->fetch_row($eq)) {
				$enweps[]=$r;
				$cnt++;
			}
			$weptouse=rand(0,$cnt-1);
			$wep=$enweps[$weptouse]['itmname'];
			}	
			$enperc=(int) ($ir['energy']/$ir['maxenergy']*100);
			$gq=$db->query("SELECT * FROM gangs WHERE gangID={$attack_person['gang']}");
$ga=$db->fetch_row($gq);
$error = ($enperc < 25) ? "You need to have at least 25% of your energy if you want to attack someone." : $error;
$error = ($user_class['jail'] > 0) ? "You can't attack someone if you are in jail." : $error;
$error = ($user_class['hospital'] > 0) ? "You can't attack someone if you are in the hospital." : $error;
$error = ($_GET['ID'] == "") ? "You didn't choose someone to attack." : $error;
$error = ($_GET['ID'] == $userid) ? "You can't attack yourself." : $error;
$error = ($attack_person['location'] != $user_class['location']) ? "You must be in the same city as the person you are attacking. Duh." : $error;
$error = ($attack_person['username'] == "") ? "That person doesn't exist." : $error;
$error = ($attack_person['hospital'] > 0) ? "You can't attack someone that is in the hospital." : $error;
$error = ($attack_person['jail'] > 0) ? "You can't attack someone that is in jail." : $error;
//$error = ($user_class['level'] > 5 && $attack_person['level'] < 6) ? "You can't attack someone that is level 5 or below because you are higher than level 5." : $error;
////////////// ^^ if you like to have it so noobs stay alive longer

?><div id="main " style="a"><center><?PHP
if (isset($error)){
echo ($error);

$h->endpage();
		exit;
}
if ($user_class['energy'] >= $user_class['maxenergy']/4) {
		$user_class['energy']-= floor($user_class['maxenergy']/4);
		$me=floor($user_class['maxenergy']/4);
		$db->query("UPDATE users SET energy=energy- {$me} WHERE userid=$userid");
		$_SESSION['attacklog']="";
		$_SESSION['attackdmg']=0;
	} 

$yourhp = $user_class['hp'];
$theirhp = $attack_person['hp'];
$damagestat = number_format($user_class['strength']) ;
$itstat = $user_class1['weapon'];
$damplu = $damagestat * ($itstat*100);
$ratio=($user_class['level']*100)/($attack_person['level']*100);
print "<center>Attack

<font color=yellow>The fight Ratio is ".$ratio."%</font>

You are in a Battle with  ".$attack_person['username']." </center>";
echo " You come in with your ".$weapon." With a Strenght of ".$damplu." (+".$itstat."%)
";

$wait = ($user_class['agility'] > $attack_person['agility']) ? 1 : 0;
$hospital = 600;
$qo=$db->query("SELECT i.* FROM  items i  WHERE i.itmid IN({$attack_person['equip_primary']})");
$r1=$db->fetch_row($qo);
$qo=$db->query("SELECT i.* FROM  items i  WHERE i.itmid IN({$attack_person['equip_primary']})");
$r2=$db->fetch_row($qo);
$damage = (int) (($user_class1['weapon']*$user_class['strength']/($attack_person['guard']/1.5)));
$theirdamage = (int) (($r1['weapon']*$attack_person['strength']/($user_class['guard']/1.5)));
while($yourhp > 0 && $theirhp > 0){
$damage = ($damage < 1) ? 1 : $damage;
$theirdamage = ($theirdamage < 1) ? 1 : $theirdamage;
if($wait == 0){
	$yourhp = $yourhp - $theirdamage;
	echo "<font color=red>".$attack_person['usename']."Takes their turn to swing at you!</font>
";
	echo $attack_person['username'].  " hit you for "  .number_format($theirdamage).  " damage using their ".$wep.". 
";
} else {
	$wait = 0;
}

if($yourhp > 0) {
$damage = (int) (($user_class1['weapon']*$user_class['strength']/($attack_person['guard']/1.5)));
	$damage = ($damage < 1) ? 1 : $damage;
	$theirhp = $theirhp - $damage;
	echo "<font color=green>You swing at them!</font>
";
	echo "You hit " .$attack_person['username'].  " for " . number_format($damage) . " damage using your ".$weapon.". 
";
}

if($theirhp <= 0){ // attacker won
	$winner = $user_class['ID'];
	$theirhp = 0;
	$moneywon = floor($attack_person['money'] /10);
	$expwon = 150 - (25 * ($user_class['level'] - $attack_person['level']));
	$expwon = ($expwon < 0) ? 0 : $expwon;
	$hosptime=20;

	$hospreason = "Attacked by ".$user_class['username']."" ;
	$newexp = $expwon + $user_class['exp'];
	$newmoney = $user_class['money'] + $moneywon;
	$result = $db->query("UPDATE `users` SET `exp` = '".$newexp."', money = '".$newmoney."' WHERE `userid`='".$user_class['userid']."'");	
	$newmoney = $attack_person['money'] - $moneywon;
	$result = $db->query("UPDATE `users` SET `hp`= 1,`hospital` ='".$hosptime."', `money` = '".$newmoney."', `hospreason` = '".$hospreason."' WHERE `userid`='".$attack_person['userid']."'");
	$atklog=mysql_escape_string($_SESSION['attacklog']);
$db->query("INSERT INTO attacklogs VALUES('',".$user_class['userid'].",".$attack_person['userid'].",'won',unix_timestamp(),".$moneywon.",'$atklog');");
	event_add($attack_person['userid'], "You were hospitalized by ".$user_class['username']." for 20 minutes.");
	$final ="<center>You hospitalized "  .$attack_person['username'].  ".
You gain $expwon exp and stole $".$moneywon." from "  .$attack_person['username'].  ".
</center>";
	$pwnd ="";
$warq=$db->query("SELECT * FROM gangwars WHERE (warDECLARER={$user_class['gang']} AND warDECLARED={$attack_person['gang']}) OR (warDECLARED={$user_class['gang']} AND warDECLARER={$attack_person['gang']})");
if ($db->num_rows($warq) > 0)
{
$war=$db->fetch_row($warq);
$db->query("UPDATE gangs SET gangRESPECT=gangRESPECT-2 WHERE gangID={$attack_person['gang']}");
$ga['gangRESPECT']-=2;
$db->query("UPDATE gangs SET gangRESPECT=gangRESPECT+2 WHERE gangID={$user_class['gang']}");
$pwnd  ="
You earnt 2 respect for your gang!";
	}
	if ($ga['gangRESPECT']<=0 && $attack_person['gang'])
{
$db->query("UPDATE users SET gang=0 WHERE gang={$attack_person['gang']}");

$db->query("DELETE FROM gangs WHERE gangRESPECT<='0'");
$db->query("DELETE FROM gangwars WHERE warDECLARER={$ga['gangID']} or warDECLARED={$ga['gangID']}");
}
$bots=array(96,94,5,97,98,99,142,138,138,140,141,146,143,144,145);//Your Battle Tent Bots
$moneys=array(96 =>5000,94 =>5000,5 => 500,97 => 5000, 98 => 500, 99 => 10000, 142 => 1500,138 =>10000,140 =>10000,141 =>10000,146 =>20000,143 =>15000,144 =>15000,145 =>15000);
if(in_array($attack_person['userid'],$bots))
{
$gain=$moneys[$attack_person['userid']];
$db->query("UPDATE users SET money=money+$gain WHERE userid=$userid",$c);
$finalbot ="";
$finalbot ="

Congrats, for beating the Challenge Bot {$attack_person['username']}, you have earnt \$$gain!";

}
}

if($yourhp <= 0){ // defender won
	$winner = $attack_person['ID'];
	$yourhp = 0;
	$moneywon = floor($user_class['money'] /10);
	$expwon = 100 - (25 * ($attack_person['level'] - $user_class['level']));
	$expwon = ($expwon < 0) ? 0 : $expwon;
	$hosplost = "Lost to ".$attack_person['username']."" ;
	$hosptime=20;
	$newexp = $expwon + $attack_person['exp'];
	$newmoney = $attack_person['money'] + $moneywon;
	$result = $db->query("UPDATE `users` SET `exp` = '".$newexp."', money = '".$newmoney."' WHERE `userid`='".$attack_person['userid']."'");
	$newmoney = $user_class['money'] - $moneywon;
	$result = $db->query("UPDATE `users` SET `hp`= 1,`hospital` ='".$hosptime."' ,`money` = '".$newmoney."', `hospreason` = '".$hosplost."' WHERE `userid`='".$user_class['userid']."'");
	  $atklog=mysql_escape_string($_SESSION['attacklog']);
$db->query("INSERT INTO attacklogs VALUES('',".$attack_person['userid'].",".$user_class['userid'].",'won',unix_timestamp(),".$moneywon.",'$atklog');");
	$final = $attack_person2 . " beat you and stole $".$moneywon." from you.";
$pwnd ="";
$warq=$db->query("SELECT * FROM gangwars WHERE (warDECLARER={$user_class['gang']} AND warDECLARED={$attack_person['gang']}) OR (warDECLARED={$user_class['gang']} AND warDECLARER={$attack_person['gang']})");
if ($db->num_rows($warq) > 0)
{
$war=$db->fetch_row($warq);
$db->query("UPDATE gangs SET gangRESPECT=gangRESPECT+1 WHERE gangID={$attack_person['gang']}");
$db->query("UPDATE gangs SET gangRESPECT=gangRESPECT-1 WHERE gangID={$user_class['gang']}");
$pwnd ="
You lost 1 respect for your gang!";
}
}
}
echo "$final";
echo "$pwnd ";
echo "$finalbot";
$h->endpage();
?></div></center>

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.   Paste as plain text instead

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