Jump to content

Basic Attack System


thechris

Recommended Posts

Hello all,

What I am trying to do is make a basic attack system i already have parts of it done I just need help figuring out how to do a few specific things.

 

Problem #1

I have three tables in my mysql databse. one keeps track of the users and thier stats, one keeps tracks of characters and thier stats, and the third is the battle table to store info for the battle and then for recall later.

What I want to do is as an admin pick out the two users from dropdown menus

then pick the two characters they are playing as from dropdown menus

then I want to combine the two stats together from the different tables and put them into the battle table

 

(like so)

player1_attack(battle table) = users_attack(picked from dropdown) + characters_attack(picked from dropdown)

 

Problem #2

May come in the future!

Link to comment
Share on other sites

as of right now I just have the table setup (no dropdown menus yet) for trying to pick the users and thier characters but if you want to see the battle code that I have here it is.

 

<?php require_once('../Connections/conn_users.php'); ?>
<?php
$colname_battles = "-1";
if (isset($_GET['battle_id'])) {
  $colname_battles = (get_magic_quotes_gpc()) ? $_GET['battle_id'] : addslashes($_GET['battle_id']);
}
mysql_select_db($database_conn_users, $conn_users);
$query_battles = sprintf("SELECT * FROM battles WHERE battle_id = %s", $colname_battles);
$battles = mysql_query($query_battles, $conn_users) or die(mysql_error());
$row_battles = mysql_fetch_assoc($battles);
$totalRows_battles = mysql_num_rows($battles);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<?php
global $player1,$player1_char,$player1_attack,$player1_defense,$player1_stamina,$player1_dexterity,$player1_special,$player1_health,$player1_counter;
global $player2,$player2_char,$player2_attack,$player2_defense,$player2_stamina,$player2_dexterity,$player2_special,$player2_health,$player2_counter;
global $attack,$defend;
global $turn,$special;
global $hits,$blocks,$damage;

$player1_health = $player1_health + player1_stamina;
$player2_health = $player2_health + player2_stamina;

function rolldamage(){
if ($player1_health>0 && $player2_health>0){
	if ($turn==1) {
		$attack = ($player1_attack);
		$defend = ($player2_defense + $player2_dexterity);
	}
	else {
		$attack = ($player2_attack);
		$defend = ($player1_defense + $player1_dexterity);
	} 
	while($attack>0){
		srand(time());
		$random = (rand()%9);
		$hits == $hits + $random;
	}
	while($defend>0) {
		srand(time());
		$random = (rand()%9);
		$blocks == $blocks + $random;
	}
	if ($hits == $blocks) {
		if(turn==1){
			output("$player1_char tries to attack but is blocked");	
		}
		else{
			output("$player2_char tries to attack but is blocked");
		}
	}
	elseif($hits > $blocks) {
		if(turn==1){
			$damage = $hits-$blocks;
			output("$player1_char hits $player2_char for $damage");
			$player2_health = $player2_health-$damage;
			output("player2 has $player2_health life left");
		}
		else{
			$damage = $hits-$blocks;
			output("$player2_char hits $player1_char for $damage");
			$player1_health = $player1_health-$damage;
			output("player1 has $player1_health life left");
		}
	}
	elseif($hits < $blocks) {
		if(turn==1){
			$damage = $blocks-$hits;
			output("$player1_char hits $player2_char for $damage");
			$player2_health = $player2_health-$damage;
			output("player1 has $player1_health life left");
		}
		else{
			$damage = $blocks-$hits;
			output("$player2_char hits $player1_char for $damage");
			$player1_health = $player1_health-$damage;
			output("player1 has $player1_health life left");
		}
	}
}
if($turn==1){
	$turn=0;
}
else{
	$turn=1;
}
else {
	if($player1_health == 0) {
		output("$player1_char was beaten by $player2");
			//increase player 2's wins by one
			//increase player 1's losses by one
	}
	else {
		output("$player2_char was beaten by $player1");
			//increase player 1's wins by one
			//increase player 1's losses by one
	}
}
}
?>
<head>
<title>Cosplay Combat</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1" />
<meta name="Robots" content="NOINDEX" />
<meta http-equiv="PRAGMA" content="NO-CACHE" /><!--
  Web Site: www.ssi-developer.net
  Comments: Copyright 2003 www.ssi-developer.net
  Licence:  Creative Commons - Non-commercial Share-Alike
-->
<link rel="stylesheet" type="text/css"
href="../2c-hd-lc-static-layout.css" />
<link rel="stylesheet" type="text/css"
href="../2c-hd-lc-static-presentation.css" />
</head>
<body>
<!-- Header -->
<div id="hdr">Cosplay Combat </div>
<!-- left column -->
<div id="lh-col">
<ul>
  <li><a href="../index.php">Index</a></li>
  <li><a href="../gallery.php">Gallery</a></li><a href="fight.php">Cosplay Combat</a>
  <li><a href="../rankings.php">Rankings</a></li>
  <li><a href="../rules.php">Rules</a></li>
  <li><a href="../request.php">Request Event</a></li>
</ul> 
</div>
<div id="rh-col">
<div id="info"><a href="../login.php">Log In</a> | <a href="<?php echo $logoutAction ?>">Log Out</a> | <a href="../registration.php">Register </a></div>


</div>
</body>
</html>
<?php
mysql_free_result($battles);
?>

Link to comment
Share on other sites

Ok here is my code so far for the choosing screen

 

<?php require_once('../Connections/conn_users.php'); ?>
<?php
mysql_select_db($database_conn_users, $conn_users);
$query_player1 = "SELECT username FROM system_users";
$player1 = mysql_query($query_player1, $conn_users) or die(mysql_error());
$row_player1 = mysql_fetch_assoc($player1);
$totalRows_player1 = mysql_num_rows($player1);

mysql_select_db($database_conn_users, $conn_users);
$query_player2 = "SELECT username FROM system_users";
$player2 = mysql_query($query_player2, $conn_users) or die(mysql_error());
$row_player2 = mysql_fetch_assoc($player2);
$totalRows_player2 = mysql_num_rows($player2);

mysql_select_db($database_conn_users, $conn_users);
$query_character1 = "SELECT char_id, char_name, series FROM characters";
$character1 = mysql_query($query_character1, $conn_users) or die(mysql_error());
$row_character1 = mysql_fetch_assoc($character1);
$totalRows_character1 = mysql_num_rows($character1);

mysql_select_db($database_conn_users, $conn_users);
$query_character2 = "SELECT char_id, char_name, series FROM characters";
$character2 = mysql_query($query_character2, $conn_users) or die(mysql_error());
$row_character2 = mysql_fetch_assoc($character2);
$totalRows_character2 = mysql_num_rows($character2);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Cosplay Combat</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1" />
<meta name="Robots" content="NOINDEX" />
<meta http-equiv="PRAGMA" content="NO-CACHE" /><!--
  Web Site: www.ssi-developer.net
  Comments: Copyright 2003 www.ssi-developer.net
  Licence:  Creative Commons - Non-commercial Share-Alike
-->
<link rel="stylesheet" type="text/css"
href="../2c-hd-lc-static-layout.css" />
<link rel="stylesheet" type="text/css"
href="../2c-hd-lc-static-presentation.css" />
<script type="text/JavaScript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//-->
</script>
</head>
<body>
<!-- Header -->
<div id="hdr">Cosplay Combat </div>
<!-- left column -->
<div id="lh-col">
<ul>
  <li><a href="../index.php">Index</a></li>
  <li><a href="../gallery.php">Gallery</a></li>
  <li><a href="../rankings.php">Rankings</a></li>
  <li><a href="../rules.php">Rules</a></li>
  <li><a href="../request.php">Request Event</a></li>
</ul> 
</div>
<!-- end of left column -->
<!-- right column -->
<div id="rh-col">
<div id="info"><a href="../login.php">Log In</a> | <a>Log Out</a> | <a href="../registration.php">Register </a></div>
<form id="form1" name="form1" method="post" action="">
  <table width="600" border="1">
    <tr>
      <td><div align="center">Player 1 </div></td>
      <td><div align="center">Player 2 </div></td>
    </tr>
    <tr>
      <td><div align="center">
        
          <select name="menu1">
	  <?php do { ?>
              <option><?php echo $row_player1['username']; ?></option>
	  <?php } while ($row_player1 = mysql_fetch_assoc($player1)); ?>
          </select>
          
</div></td>
      <td><div align="center">
    <select name="menu1">
	  <?php do { ?>
              <option><?php echo $row_player2['username']; ?></option>
	  <?php } while ($row_player2 = mysql_fetch_assoc($player2)); ?>
          </select>
	</div></td>
    </tr>
    <tr>
      <td><div align="center">
    <select name="menu2">
        <?php do { ?>
          <option><?php echo $row_character1['char_name']; ?> - <?php echo $row_character1['series']; ?></option>
	<?php } while ($row_character1 = mysql_fetch_assoc($character1)); ?>
        </select>
          
</div></td>
      <td><div align="center">
        
          <select name="menu3" onchange="MM_jumpMenu('parent',this,0)">
	  <?php do { ?>
            <option><?php echo $row_character2['char_name']; ?> - <?php echo $row_character2['series']; ?></option>
	  <?php } while ($row_character2 = mysql_fetch_assoc($character2)); ?>
          </select>
          
</div></td>
    </tr>
    <tr>
      <td colspan="2"><div align="center">
          <input type="submit" name="Submit" value="Fight" />
      </div></td>
    </tr>
  </table>
</form>
<p></p>
</div>
<!-- end of right column -->

</body>
</html>
<?php
mysql_free_result($player1);

mysql_free_result($player2);

mysql_free_result($character1);

mysql_free_result($character2);
?>

Link to comment
Share on other sites

Ok I wanted to put in a confirm page first but I don't know how to pass the variables correctly. because I don't know how to pass the info from the menus. nor do I know how to pick out the char_id from picking the character and series from the drop down

 

Here is the code I have now for the page

<?php require_once('../Connections/conn_users.php'); ?>
<?php
mysql_select_db($database_conn_users, $conn_users);
$query_player1 = "SELECT username FROM system_users";
$player1 = mysql_query($query_player1, $conn_users) or die(mysql_error());
$row_player1 = mysql_fetch_assoc($player1);
$totalRows_player1 = mysql_num_rows($player1);

mysql_select_db($database_conn_users, $conn_users);
$query_player2 = "SELECT username FROM system_users";
$player2 = mysql_query($query_player2, $conn_users) or die(mysql_error());
$row_player2 = mysql_fetch_assoc($player2);
$totalRows_player2 = mysql_num_rows($player2);

mysql_select_db($database_conn_users, $conn_users);
$query_character1 = "SELECT char_id, char_name, series FROM characters";
$character1 = mysql_query($query_character1, $conn_users) or die(mysql_error());
$row_character1 = mysql_fetch_assoc($character1);
$totalRows_character1 = mysql_num_rows($character1);

mysql_select_db($database_conn_users, $conn_users);
$query_character2 = "SELECT char_id, char_name, series FROM characters";
$character2 = mysql_query($query_character2, $conn_users) or die(mysql_error());
$row_character2 = mysql_fetch_assoc($character2);
$totalRows_character2 = mysql_num_rows($character2);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Cosplay Combat</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1" />
<meta name="Robots" content="NOINDEX" />
<meta http-equiv="PRAGMA" content="NO-CACHE" /><!--
  Web Site: www.ssi-developer.net
  Comments: Copyright 2003 www.ssi-developer.net
  Licence:  Creative Commons - Non-commercial Share-Alike
-->
<link rel="stylesheet" type="text/css"
href="../2c-hd-lc-static-layout.css" />
<link rel="stylesheet" type="text/css"
href="../2c-hd-lc-static-presentation.css" />
<script type="text/JavaScript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//-->
</script>
</head>
<body>
<!-- Header -->
<div id="hdr">Cosplay Combat </div>
<!-- left column -->
<div id="lh-col">
<ul>
  <li><a href="../index.php">Index</a></li>
  <li><a href="../gallery.php">Gallery</a></li>
  <li><a href="../rankings.php">Rankings</a></li>
  <li><a href="../rules.php">Rules</a></li>
  <li><a href="../request.php">Request Event</a></li>
</ul> 
</div>
<!-- end of left column -->
<!-- right column -->
<div id="rh-col">
<div id="info"><a href="../login.php">Log In</a> | <a>Log Out</a> | <a href="../registration.php">Register </a></div>
<form id="form1" name="form1" method="post" action="">
  <table width="600" border="1">
    <tr>
      <td><div align="center">Player 1 </div></td>
      <td><div align="center">Player 2 </div></td>
    </tr>
    <tr>
      <td><div align="center">
        
          <select name="menu1">
	  <?php do { ?>
              <option><?php echo $row_player1['username']; ?></option>
	  <?php } while ($row_player1 = mysql_fetch_assoc($player1)); ?>
          </select>
          
</div></td>
      <td><div align="center">
    <select name="menu1">
	  <?php do { ?>
              <option><?php echo $row_player2['username']; ?></option>
	  <?php } while ($row_player2 = mysql_fetch_assoc($player2)); ?>
          </select>
	</div></td>
    </tr>
    <tr>
      <td><div align="center">
    <select name="menu2">
        <?php do { ?>
          <option><?php echo $row_character1['char_name']; ?> - <?php echo $row_character1['series']; ?></option>
	<?php } while ($row_character1 = mysql_fetch_assoc($character1)); ?>
        </select>
          
</div></td>
      <td><div align="center">
        
          <select name="menu3" onchange="MM_jumpMenu('parent',this,0)">
	  <?php do { ?>
            <option><?php echo $row_character2['char_name']; ?> - <?php echo $row_character2['series']; ?></option>
	  <?php } while ($row_character2 = mysql_fetch_assoc($character2)); ?>
          </select>
          
</div></td>
    </tr>
    <tr>
      <td colspan="2"><div align="center"><a href="confirm.php?username=<?php echo $row_player1['username']; ?>&username2=<?php echo $row_player2['username']; ?>&char1=<?php echo $row_character1['char_id']; ?>&char2=<?php echo $row_character2['char_id']; ?>">Confirm</a></div></td>
    </tr>
  </table>
</form>
<p></p>
</div>
<!-- end of right column -->

</body>
</html>
<?php
mysql_free_result($player1);

mysql_free_result($player2);

mysql_free_result($character1);

mysql_free_result($character2);
?>

Link to comment
Share on other sites

Alright let me tell you how this page should work and then hopefully someone can help me.

 

When this page gets loaded it needs to decide who goes first on a random dice roll. From there as the administrator of the battle I ask the characters if they want to fight or use thier special (if they have one). I click on the appropriate link (either fight or special) and it calculates the damage based on the rolldamage. (I am still creating the rolldamage function for when they use a special). Then it prints the results of the round to the screen. Then it increases the attackers counter by one when they get a certain amount they get to use thier special.

 

On the next persons turn it should give the same options either fight or special but what I need it to do is to add to the text already on the screen from the first round. It should then do the same thing as the first round (calculate damage ect.)

 

If you are wanting to know this is for a Live Action Roleplaying Game where I as the administrator pick the battles and ask what the combatants want to do (fight or use special).

 

Here is the code that I have so far for my system.

 

<?php require_once('../Connections/conn_users.php'); ?>
<?php
$colname_battles = "-1";
if (isset($_GET['battle_id'])) {
  $colname_battles = (get_magic_quotes_gpc()) ? $_GET['battle_id'] : addslashes($_GET['battle_id']);
}
mysql_select_db($database_conn_users, $conn_users);
$query_battles = sprintf("SELECT * FROM battles WHERE battle_id = %s", $colname_battles);
$battles = mysql_query($query_battles, $conn_users) or die(mysql_error());
$row_battles = mysql_fetch_assoc($battles);
$totalRows_battles = mysql_num_rows($battles);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<?php
global $player1,$player1_char,$player1_attack,$player1_defense,$player1_stamina,$player1_dexterity,$player1_special,$player1_health,$player1_counter;
global $player2,$player2_char,$player2_attack,$player2_defense,$player2_stamina,$player2_dexterity,$player2_special,$player2_health,$player2_counter;
global $attack,$defend;
global $turn,$special;
global $hits,$blocks,$damage,$victory;


$player1 = $row_battles['player_1'];
$player1_char = $row_battles['player1_char'];
$player1_attack = $row_battles['player1_attack'];
$player1_defense = $row_battles['player1_defense'];
$player1_stamina = $row_battles['player1_stamina'];
$player1_dexterity = $row_battles['player1_dexterity'];
$player1_special = $row_battles['player1_special'];
$player2 = $row_battles['player_2'];
$player2_char = $row_battles['player2_char'];
$player2_attack = $row_battles['player2_attack'];
$player2_defense = $row_battles['player2_defense'];
$player2_stamina = $row_battles['player2_stamina'];
$player2_dexterity = $row_battles['player2_dexterity'];
$player2_special = $row_battles['player2_special'];
$player1_health = $row_battles['player1_health'];
$player2_health = $row_battles['player2_health'];

$player1_health = $player1_health + player1_stamina;
$player2_health = $player2_health + player2_stamina;

function rolldamage(){
if ($player1_health > 0 && $player2_health > 0){
	if ($turn==1) {
		$attack = ($player1_attack);
		$defend = ($player2_defense + $player2_dexterity);
	}
	else {
		$attack = ($player2_attack);
		$defend = ($player1_defense + $player1_dexterity);
	} 
	while($attack>0){
		srand(time());
		$random = (rand()%9);
		$hits == $hits + $random;
	}
	while($defend>0) {
		srand(time());
		$random = (rand()%9);
		$blocks == $blocks + $random;
	}
	if ($hits == $blocks) {
		if(turn==1){
			output("$player1_char tries to attack but is blocked");	
		}
		else{
			output("$player2_char tries to attack but is blocked");
		}
	}
	elseif($hits > $blocks) {
		if(turn==1){
			$damage = $hits-$blocks;
			output("$player1_char hits $player2_char for $damage");
			$player2_health = $player2_health-$damage;
			output("player2 has $player2_health life left");
		}
		else{
			$damage = $hits-$blocks;
			output("$player2_char hits $player1_char for $damage");
			$player1_health = $player1_health-$damage;
			output("player1 has $player1_health life left");
		}
	}
	elseif($hits < $blocks) {
		if(turn==1){
			$damage = $blocks-$hits;
			output("$player1_char hits $player2_char for $damage");
			$player2_health = $player2_health-$damage;
			output("player1 has $player1_health life left");
		}
		else{
			$damage = $blocks-$hits;
			output("$player2_char hits $player1_char for $damage");
			$player1_health = $player1_health-$damage;
			output("player1 has $player1_health life left");
		}
	}
}
if($turn==1){
	$turn=0;
}
elseif($turn==0){
	$turn=1;
}
else {
	if($player1_health <= 0) {
		output("$player1_char was beaten by $player2");
			//increase player 2's wins by one
			//increase player 1's losses by one
			$victory=1;
	}
	elseif(player2_health <= 0) {
		output("$player2_char was beaten by $player1");
			//increase player 1's wins by one
			//increase player 1's losses by one
			$victory=1;
	}
}
}
?>
<head>
<title>Cosplay Combat</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1" />
<meta name="Robots" content="NOINDEX" />
<meta http-equiv="PRAGMA" content="NO-CACHE" /><!--
  Web Site: www.ssi-developer.net
  Comments: Copyright 2003 www.ssi-developer.net
  Licence:  Creative Commons - Non-commercial Share-Alike
-->
<link rel="stylesheet" type="text/css"
href="../2c-hd-lc-static-layout.css" />
<link rel="stylesheet" type="text/css"
href="../2c-hd-lc-static-presentation.css" />
<script type="text/JavaScript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//-->
</script>
</head>
<body>
<!-- Header -->
<div id="hdr">Cosplay Combat </div>
<!-- left column -->
<div id="lh-col">
<ul>
  <li><a href="../index.php">Index</a></li>
  <li><a href="../gallery.php">Gallery</a></li>
  <li><a href="../rankings.php">Rankings</a></li>
  <li><a href="../rules.php">Rules</a></li>
  <li><a href="../request.php">Request Event</a></li>
</ul> 
</div>
<!-- end of left column -->
<!-- right column -->
<div id="rh-col">
<div id="info"><a href="../login.php">Log In</a> | <a href="<?php echo $logoutAction ?>">Log Out</a> | <a href="../registration.php">Register </a></div>
<p>

</p>
</div>
</body>
</html>
<?php
mysql_free_result($battles);
?>

Link to comment
Share on other sites

  • 10 years later...

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.