Jump to content
MakeWebGames

Recommended Posts

Posted

Okay ... I have been working on this for over a week now, and I'll be damned if I can figure out why it is not working correctly. It is not deducting the damage from the health the way it should. I have made sure that the variables all are actually picking something up, there is no divide by zero errors. I am going to show you the one that is glaringly obvious that it is not working. I have chosen an NPC that has stats much larger than the ones I am testing with. I am including screenshots of the actual variables printing to the screen proving that they hold a value, and of the fight itself. It keeps "stalemating" when you can see by the stats printed that there is no way this should happen. It should be one shot and I am dead. Not happening. This also happens when attacking lesser NPCs as well. When they should be a one hit kill, it is taking 8-10 hits to do so.

 

 

And the code:

//~~~~~~~~~~~~~~~~~~~~~~ Getting weapon information
$themprimary=$db->query("SELECT * FROM items WHERE itmid=".$them['equip_primary']."");
$themfirst=$db->fetch_row($themprimary);
$themsecondary=$db->query("SELECT * FROM items WHERE itmid=".$them['equip_secondary']."");
$themsecond=$db->fetch_row($themsecondary);
$meprimary=$db->query("SELECT * FROM items WHERE itmid=".$me['equip_primary']."");
$mefirst=$db->fetch_row($meprimary);
$mesecondary=$db->query("SELECT * FROM items WHERE itmid=".$me['equip_secondary']."");
$mesecond=$db->fetch_row($mesecondary);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Getting health and armor information
$mehealth=$me['hp'];
$themhealth=$them['hp'];
$eq1=$db->query("SELECT i.head FROM items i WHERE itmid={$them['equip_head']} ORDER BY rand()");
$eq2=$db->query("SELECT i.neck FROM items i WHERE itmid={$them['equip_neck']} ORDER BY rand()");
$eq3=$db->query("SELECT i.arms FROM items i WHERE itmid={$them['equip_arms']} ORDER BY rand()");
$eq4=$db->query("SELECT i.torso FROM items i WHERE itmid={$them['equip_torso']} ORDER BY rand()");
$eq5=$db->query("SELECT i.legs FROM items i WHERE itmid={$them['equip_legs']} ORDER BY rand()");
$eq6=$db->query("SELECT i.feet FROM items i WHERE itmid={$them['equip_feet']} ORDER BY rand()");
$eq7=$db->query("SELECT i.special1 FROM items i WHERE itmid={$them['equip_special1']} ORDER BY rand()");
$eq8=$db->query("SELECT i.special2 FROM items i WHERE itmid={$them['equip_special2']} ORDER BY rand()");
$eq9=$db->query("SELECT i.special3 FROM items i WHERE itmid={$them['equip_special3']} ORDER BY rand()");
$themarmor=0;
if($db->num_rows($eq1)) { $themarmor+=$db->fetch_single($eq1); }
if($db->num_rows($eq2)) { $themarmor+=$db->fetch_single($eq2); }
if($db->num_rows($eq3)) { $themarmor+=$db->fetch_single($eq3); }
if($db->num_rows($eq4)) { $themarmor+=$db->fetch_single($eq4); }
if($db->num_rows($eq5)) { $themarmor+=$db->fetch_single($eq5); }
if($db->num_rows($eq6)) { $themarmor+=$db->fetch_single($eq6); }
if($db->num_rows($eq7)) { $themarmor+=$db->fetch_single($eq7); }
if($db->num_rows($eq8)) { $themarmor+=$db->fetch_single($eq8); }
if($db->num_rows($eq9)) { $themarmor+=$db->fetch_single($eq9); }

$eq1=$db->query("SELECT i.head FROM items i WHERE itmid={$me['equip_head']} ORDER BY rand()");
$eq2=$db->query("SELECT i.neck FROM items i WHERE itmid={$me['equip_neck']} ORDER BY rand()");
$eq3=$db->query("SELECT i.arms FROM items i WHERE itmid={$me['equip_arms']} ORDER BY rand()");
$eq4=$db->query("SELECT i.torso FROM items i WHERE itmid={$me['equip_torso']} ORDER BY rand()");
$eq5=$db->query("SELECT i.legs FROM items i WHERE itmid={$me['equip_legs']} ORDER BY rand()");
$eq6=$db->query("SELECT i.feet FROM items i WHERE itmid={$me['equip_feet']} ORDER BY rand()");
$eq7=$db->query("SELECT i.special1 FROM items i WHERE itmid={$me['equip_special1']} ORDER BY rand()");
$eq8=$db->query("SELECT i.special2 FROM items i WHERE itmid={$me['equip_special2']} ORDER BY rand()");
$eq9=$db->query("SELECT i.special3 FROM items i WHERE itmid={$me['equip_special3']} ORDER BY rand()");
$mearmor=0;
if($db->num_rows($eq1)) { $mearmor+=$db->fetch_single($eq1); }
if($db->num_rows($eq2)) { $mearmor+=$db->fetch_single($eq2); }
if($db->num_rows($eq3)) { $mearmor+=$db->fetch_single($eq3); }
if($db->num_rows($eq4)) { $mearmor+=$db->fetch_single($eq4); }
if($db->num_rows($eq5)) { $mearmor+=$db->fetch_single($eq5); }
if($db->num_rows($eq6)) { $mearmor+=$db->fetch_single($eq6); }
if($db->num_rows($eq7)) { $mearmor+=$db->fetch_single($eq7); }
if($db->num_rows($eq8)) { $mearmor+=$db->fetch_single($eq8); }
if($db->num_rows($eq9)) { $mearmor+=$db->fetch_single($eq9); }
//~~~~~~~~~~~~~~~~~~~~~~~~ Attack started
$hits=1;
while($mehealth>0 && $themhealth >0)// If the fight last 100+ rounds it's a stalemate
{
if ($hits>100)
{
echo"<center><h1><font color='red'><u>STALEMATE!</u></font></h1>
You lasted 100 rounds with ".$them['username']."<br />
There is no winner here.<br />
Go do some more training.<br />
Maybe then you might be able to beat them.<br />
<a href='explore.php'>Back to town</a><br />
<br />{$_SESSION['attacklog']}</center>";
$h->endpage();
$_SESSION['attacking']=0;
$me['attacking']=0;
$db->query("UPDATE users SET attacking='0', hp='$mehealth' WHERE userid=$userid");
$db->query("UPDATE users SET hp = '$themhealth' WHERE userid={$_GET['ID']}");
exit;
}
$_SESSION['attacklog'].="<b>Round {$hits}:</b> $mehealth Health <b>VS</b> $themhealth Health<br />\n";
// Declaring attacking persons fighting stats, hit ratio and damage
if($me['equip_primary']>0 && $me['equip_secondary']>0)
{
$mekill=(int)((($mefirst['weapon'] + $mesecond['weapon']) *  $me['strength'] / ($them['defense']/.76)) * (rand(6000,7000)/1000)); 
}
elseif($me['equip_primary']>0 && $me['equip_secondary']==0)
{
$mekill=(int)(( $mefirst['weapon'] *  $me['strength'] / ($them['defense']/.76)) * (rand(6000,7000)/1000)); 
}
elseif($me['equip_primary']==0 && $me['equip_secondary']>0)
{
$mekill=(int)(( $mesecond['weapon'] *  $me['strength'] / ($them['defense']/.76)) * (rand(6000,7000)/1000)); 
}
else
{
$mekill=(int)((((int)($me['strength'] / $them['defense'] / 100))+1) * (rand(6000,7000)/1000));

}
$myhitratio=max(10,min(20*(($me['speed']/$them['agility'])),95));
$mydamage=($mekill-$themarmor);
// Delcaring attacked persons fighting stats, hit ration and damage
if($them['equip_primary']>0 && $them['equip_secondary']>0)
{
$themkill=(int)((($themfirst['weapon'] + $themsecond['weapon']) *  $them['strength'] / ($me['defense']/.76)) * (rand(6000,7000)/1000)); 
}
elseif($them['equip_primary']>0 && $them['equip_secondary']==0)
{
$themkill=(int)(( $themfirst['weapon'] *  $them['strength'] / ($me['defense']/.76)) * (rand(6000,7000)/1000)); 
}
elseif($them['equip_primary']==0 && $them['equip_secondary']>0)
{
$themkill=(int)(( $themsecond['weapon'] *  $them['strength'] / ($me['defense']/.76)) * (rand(6000,7000)/1000)); 
}
else
{
$themkill=(int)((((int)($them['strength'] / $me['defense'] / 100))+1) * (rand(6000,7000)/1000));
}
$theirhitratio=max(10,min(20*(($them['speed']/$me['agility'])),95));
$theirdamage=($themkill-$mearmor);
//If attackers or attackeds damage is less then 1 then damage = 1
$mydamage=($mydamage<1) ? 1 : $mydamage;
$theirdamage=($theirdamage<1) ? 1 : $theirdamage;
//Start the rounds of attack
if($wait==0)
{
if(rand(1,100)<=$myhitratio)
{
$themhealth=$themhealth-$mydamage;
$_SESSION['attacklog'].="<font color='green'> {$me['username']} hit {$them['username']} doing 
".number_format($mydamage)." damage.</font><br />\n";
}
else
{
$_SESSION['attacklog']."{$me['username']} tried to hit {$them['username']} but missed.<br />\n";
}
}
else
{
$wait=0;
}
if($themhealth>0)
{
if(rand(1,100)<=$themhitratio)
{
$mehealth=$mehealth-$theirdamage;
$_SESSION['attacklog'].="<font color='red'>{$them['username']} hit {$me['username']} doing
".number_format($theirdamage)." damage.</font><br />\n";
}
else
{
$_SESSION['attacklog'].="{$them['username']} tried to hit {$me['username']} but missed.<br />\n";
}
$hits++;
}
}

 

If you have any suggestions at all ... anything that will help me to get this working correctly. Thanks.

statsvariables.jpg.a71bfc87328c89d4d59d62ea48d0e8d1.jpg

stalemate.jpg.35167772114111537f597418f9da23db.jpg

Posted

I understand that, and I have no idea why based on the code. It's not "stepping" the way it should. The health declarations are there, the damage declarations are there, the declaration to subtract the damage from the health is there, the hit ration is there ... no matter what I try I can not get them to hit instead of miss.

Posted
I understand that, and I have no idea why based on the code. It's not "stepping" the way it should. The health declarations are there, the damage declarations are there, the declaration to subtract the damage from the health is there, the hit ration is there ... no matter what I try I can not get them to hit instead of miss.

What is the NPC's speed/agility? And what is yours? It might not be a problem with the coding, just the stats.

Posted
What is the NPC's speed/agility? And what is yours? It might not be a problem with the coding, just the stats.

 

The first screen shot shows the stats that are involved. I had everything print to the screen just to make sure that they were holding values.

Posted
You do have a separate speed column in your database then?

What is the output for the hitratio for both you and the npc?

Yuppers definately a separate column for each stat.

If you look at the first screen shot you will see that their hitratio for them is 95 and mine is 10.

Posted
The issue could be the value of $wait and I would also check what number is being spat out by the rand

The rand for the hitration?

If that's the one you mean ... it shouldn't matter what the rand is because for them they have 5 chances of missing where as I have 90 chances of missing.

As for the $wait. I'll run a test by removing it to see if it make a change. Thanks for the suggestion. I'll let you know what happens with the $wait removed.

Posted

Below is the area in question. Dont see the point in the rand actually as it defeats the point of all the code before it. What is the point in having a ratio for the npc and a ratio for yourself if then it comes down to a rand if you hit or not as you have already determined who is going to receive damage above.

 

if(rand(1,100)<=$myhitratio)

 

Posted (edited)
Below is the area in question. Dont see the point in the rand actually as it defeats the point of all the code before it. What is the point in having a ratio for the npc and a ratio for yourself if then it comes down to a rand if you hit or not as you have already determined who is going to receive damage above.

 

if(rand(1,100)<=$myhitratio)

 

It's something that was in the original McCodes attack file. I can hear you screaming from here. *laughs* It does make sense though, even the best will occasionally miss.

If the players were closely matched ... you would need the random in there in order for them to fair odds. In that case, I think it would depend on who started the fight to determine the winner though.

As for the $wait it doesn't echo out anything. If I understand correctly though ... it is needed in just that way in order for it to step through the fight correctly.

Edited by newttster
Posted

Okay ... I feel like a real idiot now. :(

See this;

$theirhitratio=max(10,min(20*(($them['speed']/$me['agility'])),95)); 

 

then this;

if(rand(1,100)<=$themhitratio)  

<- Wrong!!!

 

Should be this;

if(rand(1,100)<=$theirhitratio)

 

My apologies to everyone for the waste of time.

Posted
Okay ... I feel like a real idiot now. :(

See this;

$theirhitratio=max(10,min(20*(($them['speed']/$me['agility'])),95)); 

 

then this;

if(rand(1,100)<=$themhitratio)  

<- Wrong!!!

 

Should be this;

if(rand(1,100)<=$theirhitratio)

 

My apologies to everyone for the waste of time.

Always the simplest of things, isn't it? :P

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