Coly010 Posted December 25, 2014 Share Posted December 25, 2014 I'm trying to do my own attack code, and honestly, I'm finding it very difficult, mainly the maths behind it. If someone has a general theory for how an attack script should go then that would be very much appreciated. But at the moment I'm trying to have it so that there is a chance that when the user attacks, they miss. But i want this chance to depend on the user's agility. I dont know how to go about this. Obviously I cant have if($user['agility'] > 100 ) { // attack } I'm thinking I need to use the $user['agility'] to form a decimal or an odd(chance), but I dont know what I can use to compare it. I know I could use something like if(mt_rand(1,2) == 1) { // attack } but it seems too trivial, means there is only a 50/50 (theoretically) chance and doesn't incorporate the users agility. any help on this matter would be very much appreciated! Thanks guys, Colum Quote Link to comment Share on other sites More sharing options...
KyleMassacre Posted December 25, 2014 Share Posted December 25, 2014 What you could do is if the attackers agility is stronger than the attacked then do some sort of randomization that's not so wide and give them a boost to their agility like some sort of multiplier Quote Link to comment Share on other sites More sharing options...
Coly010 Posted December 25, 2014 Author Share Posted December 25, 2014 Now that I've sat for a minute and thought about it, I was thinking, maybe I could use a randomisation, like you said, but in a different kind of way: $max_rand = floor(1000 / $user['agility']); $chance = ($max_rand / (floor(0.02 * $user['agility'])); if(mt_rand(0, $max_rand) < $chance ) { // attack } would this be plausible ? I know it would mean setting a cap on the agility stat :/ Quote Link to comment Share on other sites More sharing options...
Veramys Posted December 26, 2014 Share Posted December 26, 2014 What Kyle is saying to do, is take the agility the user who is attacking and the user they are attacking. Like how mccodes does it. Quote Link to comment Share on other sites More sharing options...
Sim Posted December 26, 2014 Share Posted December 26, 2014 I think Coly's idea would work. He just need's an attack formula now =) Quote Link to comment Share on other sites More sharing options...
Zettieee Posted December 26, 2014 Share Posted December 26, 2014 (edited) $myAgi = (($ir['agility'] / 100) * 2.5); $enemyAgi = (($r['agility'] / 100) * 2.5); if($myAgi > $enemyAgi) { $speed = 1; } else { $speed = 0; } if($speed > 0){ //you attak } else { //they attack } Edited December 26, 2014 by KyleMassacre Code tags Quote Link to comment Share on other sites More sharing options...
KyleMassacre Posted December 26, 2014 Share Posted December 26, 2014 $myAgi = (($ir['agility'] / 100) * 2.5); $enemyAgi = (($r['agility'] / 100) * 2.5); if($myAgi > $enemyAgi) { $speed = 1; } else { $speed = 0; } if($speed > 0){ //you attak } else { //they attack } I think that can potentiall mean 1 of the 2 people will never be able to attack. I was thinking more along the lines of: $dodge = rand(1,6); if($dodge == 3) { //Make the player dodge the attack } else { //Make them hit } You can potentiall use a switch to add more like give some sort of attack multipliers like a critical hit, miss, or some kind of guard increase or something Quote Link to comment Share on other sites More sharing options...
Zettieee Posted December 26, 2014 Share Posted December 26, 2014 Yup your right kyle. I should go change my attack real quick! :D Quote Link to comment Share on other sites More sharing options...
Coly010 Posted December 26, 2014 Author Share Posted December 26, 2014 I think that can potentiall mean 1 of the 2 people will never be able to attack. I was thinking more along the lines of: $dodge = rand(1,6); if($dodge == 3) { //Make the player dodge the attack } else { //Make them hit } You can potentiall use a switch to add more like give some sort of attack multipliers like a critical hit, miss, or some kind of guard increase or something i guess that would work, but i still need to incorporate agility, otherwise one of my only two stats only counts for making the user attack first Quote Link to comment Share on other sites More sharing options...
KyleMassacre Posted December 26, 2014 Share Posted December 26, 2014 Now that's up to your imagination :p Quote Link to comment Share on other sites More sharing options...
Coly010 Posted December 26, 2014 Author Share Posted December 26, 2014 I've had a different idea built off the code snippet i posted. the idea came from kyle mentioning dodge in his post. $max_rand = floor((100*$user['agility'] )/ $opp['agility']); $chance = floor(($opp['agility'] / (0.2 * $user['agility']))); if(mt_rand(0, $max_rand) < $chance ) { // miss } right so basically, it works like this. the stronger your opponent is, the greater their agility is going to be, the bigger that agility, the smaller $chance is going to be. ill give a few example values EG $u['agility'] = 20; $o['agility'] = 15; $max_rand = 2000 / 20 = 100; $chance = floor(15 / (20*0.2) ) = 3; if(mt_rand(0, 100) < 3){ // opponent dodges } basically this means the higher the users agility, the greater chance they have of attacking (because their agility increases the range for the random while also decreasing the range for the dodge), whilst the greater agility the opponent has, the greater chance they have of dodging (because their agility increases their range for their chance to dodge). thank god i do maths and further maths at school... Quote Link to comment Share on other sites More sharing options...
Sim Posted December 26, 2014 Share Posted December 26, 2014 $max_rand = 2000 / 20 = 100; $chance = floor(15 / (20*0.2) ) = 3; if(mt_rand(0, 100) < 3){ // opponent dodges } 2% chance of dodging everytime? Quote Link to comment Share on other sites More sharing options...
Coly010 Posted December 26, 2014 Author Share Posted December 26, 2014 $max_rand = 2000 / 20 = 100; $chance = floor(15 / (20*0.2) ) = 3; if(mt_rand(0, 100) < 3){ // opponent dodges } 2% chance of dodging everytime? nope, those values are coming from the users and the opponents agility stats, so it changes depending. i just subbed example values into the code i have the attack code finished now, thanks for all the help guys Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.