Battle Attack Formulas

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Battle Attack Formulas

Post by Epiales »

Okay, I've tried 100 different setups for the attack system and I can't seem to find anything worthwile that works well.

I have basic attack points and defense points and health system. I haven't added anything else yet, but might in the future. Anyone have any ideas? I do have bullets that you have to have in order to attack the person. Those bullets can be chosen b/w 1 and 20, 20 being the higher possible damage done to the player. And I have it setup to where you lose, that the health you lose goes to the other player. I like it like that, since health won't be able to be restored otherwise.
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
Callan S.
Posts: 2043
Joined: Sun Jan 24, 2010 5:43 am

Re: Battle Attack Formulas

Post by Callan S. »

Vampire bullets!

I think it's a question of what message are you trying to get across with a combat system, in terms of how you build it. What are you trying to get at?
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Battle Attack Formulas

Post by Epiales »

Callan S. wrote:Vampire bullets!

I think it's a question of what message are you trying to get across with a combat system, in terms of how you build it. What are you trying to get at?
haha Vampires YAY...

Well, it's a mafia style game, where you need bullets to hit em. I want them to be able to hit someone, but at the lower numbers of bullets chosen, have a possible chance of losing, but the higher bullets used, have a better chance of winning, but of course have it based off users atk/def.... I just can't come up with a good formula. If I go by basic atk/def by number of bullets, then the lower amount used on lower bullets you might lose, but the higher bullets, the MORE you lose... I don't want it like that. It's hard to come up with a battle system to be honest. At least for me lol
Nothing fancy, but a work in progress!

http://gameplaytoday.net
Sim
Posts: 412
Joined: Sat Dec 26, 2009 5:37 pm

Re: Battle Attack Formulas

Post by Sim »

Epiales wrote:
Callan S. wrote:Vampire bullets!

I think it's a question of what message are you trying to get across with a combat system, in terms of how you build it. What are you trying to get at?
haha Vampires YAY...

Well, it's a mafia style game, where you need bullets to hit em. I want them to be able to hit someone, but at the lower numbers of bullets chosen, have a possible chance of losing, but the higher bullets used, have a better chance of winning, but of course have it based off users atk/def.... I just can't come up with a good formula. If I go by basic atk/def by number of bullets, then the lower amount used on lower bullets you might lose, but the higher bullets, the MORE you lose... I don't want it like that. It's hard to come up with a battle system to be honest. At least for me lol
Well with only the 2 stats you gave us. Its kind of hard to come up with a good battle formula.

Maybe use an altered version of your formula. like a for loop for each bullet

Code: Select all

$hits = 0;
for($i = 0; $i < {INSERT_NUM_BULLETS_VAR}; $i++)
	$dice = rand(1,100);
	//20% chance of missing with bullet
	if($dice < 20)
	{
		//some sort of message maybe
	}
	else//bullet hit
	{
		//use altered version of your formula. Each bullet hit does damage
		
		//this will tell whoever how many times there bullet hit oppoment
		$hits++;
	}
}

//no hits
if($hits == 0)
{
	echo "DAMN I SUCK AT SHOOTING!!!";
}
else
{
	echo "whatever you want $hits";
}
oRPG Creator - Make Your Own Browser Game
oRPG Creator on Facebook
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Battle Attack Formulas

Post by Epiales »

Sim wrote:
Callan S. wrote:Vampire bullets!



Well with only the 2 stats you gave us. Its kind of hard to come up with a good battle formula.

Maybe use an altered version of your formula. like a for loop for each bullet

Code: Select all

$hits = 0;
for($i = 0; $i < {INSERT_NUM_BULLETS_VAR}; $i++)
	$dice = rand(1,100);
	//20% chance of missing with bullet
	if($dice < 20)
	{
		//some sort of message maybe
	}
	else//bullet hit
	{
		//use altered version of your formula. Each bullet hit does damage
		
		//this will tell whoever how many times there bullet hit oppoment
		$hits++;
	}
}

//no hits
if($hits == 0)
{
	echo "DAMN I SUCK AT SHOOTING!!!";
}
else
{
	echo "whatever you want $hits";
}
What is the if $dice is < 20 for? And the $hits? Since the $hits is always equaling 1 and no more?

I'm assuming that the < 20 is basically the formula for a 20% chance to miss and 80% chance to hit...

I thought the other would be like... You use 15 bullets to attack, but only like 6 of them hit the person and the others don't hit them. I thought that would be what the $hit would be, the number 6 to show 6 bullets hit them.... but the $hits always remain at 1 no matter what I put in there? I do n't see anything that would make that number go up, so not sure what it's there for. I like the idea of using so many bullets, and then having the chance to only have a few of them hit or all of them hit.

I guess something like:

Code: Select all

$r = rand(1, $_POST['dropdown']);
Would work for random bullets from the amount they use.
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Battle Attack Formulas

Post by Epiales »

Okay, I'm this far so far. I need to come up with some type of health loss to the person that loses now. At least I think I'm started in the right direction with u're formula. Thx! You can see below how I"ve used it so far.

Code: Select all

    if (isset($_POST['dropdown'])) {
        // cast to integer to avoid malicious values
        $dropdown = (int)$_POST['dropdown'];
        
$hits = 0;
for($i = 0; $i < $_POST['dropdown']; $i++)
$r = rand(1, $_POST['dropdown']);
   $dice = rand(1,100);
   //20% chance of missing with bullet
   if($dice < 20)
   {
      //some sort of message maybe
   }
   else//bullet hit
   {

//DEFENDERS FORMULAS//
$sql = "SELECT * FROM users WHERE `id`='".$id."'";
$user_query = mysqli_query($db_conx, $sql);
$numrows = mysqli_num_rows($user_query);
while ($row = mysqli_fetch_array($user_query, MYSQLI_ASSOC)) {

$def_user = $row['username'];
$defense_user_strength = $row['strength'];
$defense_user_defense = $row['defense'];

$defense_user_defense = $defense_user_strength + $defense_user_defense;

//ATTACKERS FORMULAS//
$sql = "SELECT * FROM users WHERE id = '$_SESSION[userid]'";
$user_query = mysqli_query($db_conx, $sql);
$numrows = mysqli_num_rows($user_query);
while ($row = mysqli_fetch_array($user_query, MYSQLI_ASSOC)) {

$attack_user_strength = $row['strength'];
$attack_user_defense = $row['defense'];

$attack_user_attack = $attack_user_strength + $attack_user_defense;

    }
}      
      //this will tell whoever how many times there bullet hit oppoment
      $hits++;      
      
   }
}

//no hits
if($hits == 0)
{
$sql = "SELECT * FROM users WHERE `id`='".$id."'";
$user_query = mysqli_query($db_conx, $sql);
$numrows = mysqli_num_rows($user_query);
while ($row = mysqli_fetch_array($user_query, MYSQLI_ASSOC)) {

$def_user = $row['username'];

$sql = "SELECT * FROM users WHERE id = '$_SESSION[userid]'";
$user_query = mysqli_query($db_conx, $sql);
$numrows = mysqli_num_rows($user_query);
while ($row = mysqli_fetch_array($user_query, MYSQLI_ASSOC)) {

$def_user_loss = .020 * $row['hpoints'];

   echo "DAMN YOU SUCK AT SHOOTING!!!  YOU SHOT AT $def_user $i TIMES, AND MISSED EVERY TIME!!!";
   echo "YOU LOSE $def_user_loss HEALTH (2%) FOR BEING A POOR SHOT!";
}}}
else
{
   echo "You shot $i times at $def_user and hit them $r times! ";
}
 
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
KyleMassacre
Posts: 573
Joined: Wed Nov 27, 2013 12:42 pm

Re: Battle Attack Formulas

Post by KyleMassacre »

Well if your using a bullet system I would base everything off of that. For example if you use one bullet then your chances of hitting them are slim as opposed to using 50. But I would set it up to where if they are using less bullets then the damage would be greater. For visual reference:

Code: Select all

$bullets = 4;
switch($bullets) {
        case $bullets:
            $damageX = $bullets * .5;
             $accuracy = $damageX / .4;
        break;
    }
echo $damageX. " Damage and ".$accuracy. " Accuracy";
You probably wouldn't need a switch() but ehh oh well. I will keep it because it can open up possibilities for you ;)
Post Reply

Return to “Beginner Help and Support”