Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Keeping the Battle System, But Changing the Calculations

Sooth

Sponsor

Hey, folks. So I recently upgraded from RM2k to RMXP; I think I'm familiar with most of the basic Rpgmaker functions, but my scripting ability is severely lacking.

I'd like to change the scale - as well as the calculations - that're done to determine damage, evasion, etc, in the battle system, and in doing so change many basic assumptions. First:

--- Add 1/2 of Strength to attack power.
--- Add 1/2 of Dexterity to physical defense.
--- Add 1/2 of Intelligence to magical defense.

These seemed simple enough, so I tried tackling them on my own before asking for help. I just went into Game_Actor and added dex*0.5 to the end of the return for "Basic Physical Defense", and did the same for Int & magical defense. Things've gone splendidly, but when I did the same for attack, I got an error concerning the lack of a + method. So I fooled around with it drawing from my infinitesimal programming experience and made it into:

#--------------------------------------------------------------------------
# * Get Basic Attack Power
#--------------------------------------------------------------------------
def base_atk
weapon = $data_weapons[@weapon_id]
n = weapon != nil ? weapon.atk: 0
n2 = str*0.5
return n + n2
end

While this appears to work, I can only wonder if this "jury rig" coding might cause problems? I don't trust it. At all.

Next, the calculations. I'd like to make it so that:

--- One point of attack means one damage. One point of defense means one less damage. With variance and multipliers for elements, etc, but that basically being it. Damage can never be negative unless the base power is negative. If a skill is supposed to add 100% Intelligence to damage or a base number - such as 50 power - it only adds that much. (Some of these almost appear to be the case already, but I wanted to make sure...).
--- Base evasion chance = 20%, plus or minus one for every difference between attacker's Dexterity and defender's Agility. (So 60 Dex vs 50 Agility = 10% miss chance, and vice versa = 30% miss chance)
--- I read somewhere that a character will just about always act before another with 30 less agility than them; is this true?

Changing these seems like only a matter of mixing numbers around in the scripts, but looking at Game_Battler3 and trying to figure it out, all I managed to do was remove "attacker.str" from the basic damage calculation (so that when Strength *does* effect attack power, it won't effect damage -again-... right?) and make:

# Calculate basic damage
atk = [attacker.atk - self.pdef].max
self.damage = atk

My questions, then:

--- How would I go about making the above changes happen?

--- Have the things I've already done been horrible, horrible mistakes? Will complications arise (aside from having to carefully balance the attack/damage of everything in lieu of the new scale)? Will enemies be effected the same as actors? Am I silly for thinking this can work without a massive script addition? Will the code (and subsequently, my game) crash and burn in a brightly colored nova of apocalyptic destruction?

Thanks,
- Kriss
 
If you are modifying Game_Battler, then enemies WILL be affected. If you modify Game_Actor, they will not.

Adding another attribute in the form of a simple method is fine, but I would try and put most of your changes in the Attack_Effect method (and Skill_Effect).

The second block of code you wrote (the one after #Calculate basic damage) could result in negative numbers. If target pdef is greater than attacker atk, it will result in an attack that heals. Use this instead:
Code:
atk = [attacker.base_atk - self.pdef, 0].max

self.damage = atk

I change attacker.atk to attacker.base_atk since it matches up with your new method. You should use whatever you name that method that adds strength and attack.

By default, RMXP has two hit-or-miss checks. The first checks against the attacker's hit chance which can be affected by being blinded, dazzled, etc. If that check is passed, it will calculate damage and near the end before it applies damage to the target's HP, it checks against the target's evasion, which can be altered by status effects.

To change the evasion part, you'll want to look for the section that starts: # Second hit detection. As it stands, it adds whatever your evade stat is (which is solely based on equipment) to 8 * target's agility / attacker's dexterity. You'll first probably want to modify how evade is created instead of modifying the formula directly, so you can still affect the chance with equipment. Just go to Game_Battler1 and find "def eva" and chance "return n" to "return n+20." Now base evade before equipment (or database for enemies) will be 20%. Then in the first line of the second hit detection, change it to "eva = self.eva - (attacker.dex - self.agi)"

As far as attack speed, at lower Agility values, this theory holds true, but as the agility climbs, the 30 pts no longer guarantee priority. For example, at 960 your "action speed" can be anywhere between 960 and 1209. At 990 agility, it can vary from 990 to 1247. So there is significant overlap. But yes, for the first 100 pts or so, that 30 pt. difference means a LOT.
 

Sooth

Sponsor

That is exactly the sort of helpful response I was hoping for. Thank you. I realized I had made the changes to Actor instead of Battler and've fixed that.

A few more questions....

I actually haven't tweaked the skills yet, but I'm looking at it now. Will I need to do anything fundamentally different to make the desired effects?

(in Game_Battler3, starting at line 134):
# Calculate rate
rate = 20
rate += (user.str * skill.str_f / 100)
rate += (user.dex * skill.dex_f / 100)
rate += (user.agi * skill.agi_f / 100)
rate += (user.int * skill.int_f / 100)
# Calculate basic damage
self.damage = power * rate / 20

That's before I change anything. Does that mean... say, for a skill with 100% Strength, exactly all of the attacker's Strength will be added to the damage? And half for 50%, etc? Does that initial rate of 20 add to the damage, and can I get away with making it 0? Will a skill with a power of 1, 100% attack, and no percentages on other stats, do more-or-less the same damage as an ordinary attack? (Ideally, I would like to have a lot of melee-oriented skills be like ordinary attacks that cause or disable status effects, or are harder to dodge/of a different damage type, etc, as opposed to scaling rapidly in damage).

(UPDATE: Testing out fights with the scripts. Working wonderfully, but skills seem to be doing much more damage than they should. A skill with 1 power, 0% strength and 100% attack does substantially more damage than an ordinary attack. What else is being added that's making them rock so hard?).
 

Sooth

Sponsor

UPDATE: After playing around with it some more, I'm still genuinely confused as to why skills seem to arbitrarily do more damage than the calculations list. I changed the code in a few ways that I thought might reduce the damage dealt by skills, but to no avail.

The section under my Game_Battler 3, "Apply Skill Effects", reads:

# Calculate power
power = skill.power + user.atk * skill.atk_f / 100
if power > 0
power -= self.pdef * skill.pdef_f / 100 # (this used to be / 200)
power -= self.mdef * skill.mdef_f / 100 # (ditto)
power = [power, 0].max
end
# Calculate rate
rate = 1 # (this used to be 20)
rate += (user.str * skill.str_f / 100)
rate += (user.dex * skill.dex_f / 100)
rate += (user.agi * skill.agi_f / 100)
rate += (user.int * skill.int_f / 100)
# Calculate basic damage
self.damage = power * rate # (this used to be rate / 20)


A character with 60 Strength and a skill with 100% ATK-F, 100% PDEF-F, 10% STR-F, 1 power and 0 variance does 322 damage, whereas regular attacks deal 40-50 or so damage against the same opponent. The elements are exactly the same. When I set the STR-F to zero, the skill still does slightly more damage, and I am left scratching my head wondering how this makes sense. The formula -looks- like one attack should be adding one damage, 10% of strength should go to damage - plus the power - and that's *it.*

As discussed above, I did change the calculations so that regular attacks mean 1 attack = 1 damage, instead of the difference being halved. I also made 1/2 of Strength apply to attack power for all creatures, but since attack power is a variable in both attacking and skills, I don't see how this would mess things up.

Would anyone be able to offer any insights here? Is there something I'm overlooking?

Thanks,
- Kriss
 

Sooth

Sponsor

FINAL UPDATE:

Apparently I didn't realize that I had to close the project and re-open it for the script changes to take effect in test battles. Changing the 200 to 100 and putting the 'rate' calculations back the way they were has made everything work the way it should. Situation resolved.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top