Minase Posted August 15, 2008 Share Posted August 15, 2008 i think here it should be posted. i am working on a game,almoust finished,but now i dont know how to do the attack formula. i do have this variables $attacker->Strenght $attacker->Defence $attacker->Dexterity $attacker->Charisma $defender->Strenght $defender->Defence $defender->Dexterity $defender->Charisma dexterity = ability to protect from attacks so how would you suggest to make this formula,cause i have no clue... thanks Quote Link to comment https://forums.phpfreaks.com/topic/119885-attack-formula/ Share on other sites More sharing options...
corbin Posted August 15, 2008 Share Posted August 15, 2008 Well, you would basically want it based on the attacker's strength, and the defenders defense, yes? So, you would want the damage to grow as the strength grows, but you would also want it to shrink as the defense grows. (I'm ignoring dexterity because I'm lazy, and this is easier to explain with 2 variables.) You could do something as simple as: damage = Strength-Defense Really it depends on what type of game play you want. You'll obviously need to find a fair formula. Also, it would depend on how high hit points are in your game. You obviously don't want to make a formula that takes 1k life if players have like 100 life. Quote Link to comment https://forums.phpfreaks.com/topic/119885-attack-formula/#findComment-617657 Share on other sites More sharing options...
Andy-H Posted August 19, 2008 Share Posted August 19, 2008 if ($killss > 5){ $kills = 5; } $bulletneed = abs((($drankpos + 4) / ($rankpos + 4)) * ((((30000 - ($kills * 1000)) - ($wep * 1000)) + ($def * 1000)))); $new = ($bulls / $bulletneed) * 100; $newhealth = round($health - $new); That was my formula for my old mafia game... $drankpos = defender rank position, $rankpos = attacker rankposition, $bulls = bullets shot Rank positions were 1-22... Weapon/Protection were 0-4 Quote Link to comment https://forums.phpfreaks.com/topic/119885-attack-formula/#findComment-619930 Share on other sites More sharing options...
MasterACE14 Posted August 20, 2008 Share Posted August 20, 2008 you can also add a random factor. So the damage is never the same every time you attack. its say randomly 80% to 100% of your total potential damage. Quote Link to comment https://forums.phpfreaks.com/topic/119885-attack-formula/#findComment-620863 Share on other sites More sharing options...
.josh Posted August 26, 2008 Share Posted August 26, 2008 Traditionally: Strength = damage Defense = absorbed damage Dexterity = speed (how fast you attack, ability to dodge attack) Charisma = not really associated with battles. Has to do with for example, getting better deals when buying things These are all modifiers to other things, like what weapon one has, what armor one has, any race/class modifiers if applicable, etc... and traditionally, a dice is rolled to determine certain things like who gets first hit, whether something is dodged or blocked and how much, etc... For instance, just because I have more strength than you doesn't mean I'm going to always hit harder than you on my "turn." If those variables are the only thing you are considering in your game, then you still need to explain how fighting is done in the first place. Do both people have X health and basically each person takes turns swinging at each other until one of them dies? Does the script automatically do this or is it done in "real time" somehow (using flash, ajax, whatever)? The reason I ask these things is because we could throw out any battle "formula" but it may or may not work for you, balance-wise. Do you just want some kind of generic "okay, let's just take turns swinging at each other, first person to 0 loses?" If $a->strength = 10 and $d->strength = 5, do you always want $a to hit for 10 straight damage, $d for 5? Do you want attacks to be absorbed by exactly what defense defender has? Chance of dodge/parry/evade? Chance of getting extra swing in, due to more dexterity? Incorporate charisma in it somehow, like...idk, someone loses a turn due to other one being more charismatic? Chance of critical hits? Are there any weapons or armor being considered? Any other game "features" like spells, potions, scrolls, etc..? Some kind of character level to consider? Figuring out your game mechanics is the hardest part of game design. It's also the funnest, because you get to make the rules. But it's hard because you will quickly learn from testing that any little one thing can end up vastly throwing off the balance of everything else. You need to sit down and picture in your head exactly how you want a "battle" to go. Write it down on paper. Put down everything that can happen during this battle and when. Once you have that down, the coding part will be easy. Quote Link to comment https://forums.phpfreaks.com/topic/119885-attack-formula/#findComment-626004 Share on other sites More sharing options...
paschim Posted August 29, 2008 Share Posted August 29, 2008 Well, assuming yours to be a generic turnbased fight system, I Would say: damage= Strength-((defence+dexterity/random(1))/random(5)+2); Quote Link to comment https://forums.phpfreaks.com/topic/119885-attack-formula/#findComment-628476 Share on other sites More sharing options...
.josh Posted August 29, 2008 Share Posted August 29, 2008 Look at that formula. let's assume: strength = 5 defence = 5 dexterity = 5 5-((5+5/[0,1])/[0,1,2,3,4,5]+2) possible outcomes: 5-((10/0)/2) = error (can't divide by 0) 5-((10/0)/3) = error (can't divide by 0) 5-((10/0)/4) = error (can't divide by 0) 5-((10/0)/5) = error (can't divide by 0) 5-((10/0)/6) = error (can't divide by 0) 5-((10/0)/7) = error (can't divide by 0) 5-((10/1)/2) = 0 5-((10/1)/3) = 1.66666666667 5-((10/1)/4) = 2.5 5-((10/1)/5) = 3 5-((10/1)/6) = 3.33333333333 5-((10/1)/7) = 3.57142857143 Your formula won't work half the time, because it will throw out an error. Even if you fix that (like doing rand(1,2) instead), you have to decide whether you want someone to be doing 0-3.5 damage with those levels or not. That may or may not work for your game. Traditionally, defense is not part of a damage equation to begin with, unless you are wanting to consider damage reduction, due to the opponent's defense. Traditionally, dexterity isn't party of a damage equation, unless you are wanting to consider the opponent being able to dodge or parry the attack. Something like this would be more "accurate" traditionally: // find out whether attack will be dodged or not. If it's dodged, no need to calculate damage $dodge = rand(1, 20) + $defender->dexterity; // success is traditionally based on rolling 1d20 with 15+ roll // if successful... if ($dodge > 15) { // damage is nothing $attacker->damage = 0; // if not successful dodge... } else { // example. You would use this to scale $defense = rand(1, $defender->defense); // damage is traditionally calculated by rolling 1d20 and adding modifiers (like strength) // you could in addition include something like player's level by doing rand($level, 20) but you // would have to scale 20 to always be at least equal to level $damage = rand(1,20); // if you scale $defense, you might have to scale this // add the base damage to strength modifier and subtract how much damage was 'absorbed' $attacker->damage = ($damage + $attacker->strength) - $defense; // make sure attacker doesn't end up doing negative damage if ($attacker->damage < 0) { $attacker->damage = 0; } } // subtract damage done from defender's health $defender->health -= $attack->damage; But even that may or may not work for your specific game. Point of my example over paschim's is that you need to use the vars logically, as in, what are those variables representing in your game mechanics. You need to base your formula on what makes sense "physically" in your game reality. Quote Link to comment https://forums.phpfreaks.com/topic/119885-attack-formula/#findComment-628526 Share on other sites More sharing options...
Minase Posted September 1, 2008 Author Share Posted September 1, 2008 sorry for my long reply,but i had some projects to do let me explain and thank you all for your replys. i never designed an attack formula (complex like this) so thats why im asking for help dexterity is the ability to dodge the enemy here is how i would like the dodge formula when attacker turn $defender->Dexterity - $attacker->Dexterity = 10 //lets say he has 10 % chance to dodge that hit charisma is a chance to make a 2 hit if attacker turn $attacker->Charisma - $defender->Charisma = 5 // just example 5 % chance to do a 2 hit damage is influenced by level diference if ($attacker->Level < $defender->Level) { $dmg_minus = $level_difference * 9; // the $dmg_minus represent how much procent we decrease from damage // if diference is 10 then 10*9 = 90.If attacker damage was 100 - 90% = just 10 dmg. the battles should have random factor based on charisma and dexterity too. even if attacker has strenght and defence higher than oponent,openent can still give higher hits. if ones health <= 0 battle stop. thank you very much again if you have more questions you can ask Quote Link to comment https://forums.phpfreaks.com/topic/119885-attack-formula/#findComment-630974 Share on other sites More sharing options...
xoligy Posted September 17, 2008 Share Posted September 17, 2008 Charisma seems like a stupid one to me should either be speed, hp or intelligence Speed is still as charisma but makes more sense imo hp is health points Intelligence could be an added bonus to do a crit hit i would say have a look at a game called duels.com but i know its changed alot since i played it back in jan (was enjoyable back then) Quote Link to comment https://forums.phpfreaks.com/topic/119885-attack-formula/#findComment-643669 Share on other sites More sharing options...
Andy-H Posted September 22, 2008 Share Posted September 22, 2008 Generally when comparing stats you haveto work out a division formula so that you dont end up with a negative number and adding hp or set a maximum and check if the attacker / defender level is higher, if not they get nothing, if it is a little less/extra damage... Quote Link to comment https://forums.phpfreaks.com/topic/119885-attack-formula/#findComment-647688 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.