I know that I can use a [x,y].max in the formula. But I want a minimum damage applied to ALL attacks as a percentage based on the attack-value-formula-part.
Let's say I have 100 attack, and the creature has 500 defense, then I still want to deal 20% of the attack-damage minimum. I also want the minimum percentage to be able to crit.
Formula: a.atk * 4 - b.def * 2
I cant extract the total a.attack from RPG::UsableItem::Damage. Basically I need the 100x4=400, 400 *20% = 80 damage. Then multiply 80 by the crit modifier (if any).
I found this:
http://forums.rpgmakerweb.com/index.php?/topic/27240-setting-a-minimum-damage-using-percentages/
But then I have to manually put it in every single damage formula... And the little script does not provide a minimum damage percentage.
Basically some automated form of:
[a.atk * 4 - b.def * 2, a.atk * 4 * 0.2].max
P.S.
I wasn't sure if this belongs here or in script support/request.
Minimum Damage (by Percentage!)
● ARCHIVED · READ-ONLY
-
-
I would do it by rewriting the "Calculate Damage" method in Game_Battler, as such:
#-------------------------------------------------------------------------- # * Calculate Damage #-------------------------------------------------------------------------- def make_damage_value(user, item) value = item.damage.eval(user, self, $game_variables) ### Modification Begin if ((value <= (user.atk * 0.8)) and item.physical?) value = (user.atk * 0.8) elsif ((value <= (user.mat * 0.8)) and item.magical?) value = (user.mat * 0.8) end ### Modification End value *= item_element_rate(user, item) value *= pdr if item.physical? value *= mdr if item.magical? value *= rec if item.damage.recover? value = apply_critical(value) if @result.critical value = apply_variance(value, item.damage.variance) value = apply_guard(value) @result.make_damage(value.to_i, item) endIf you are using different formulae for skills so that the amount won't always be a.atk * 4 * 0.2 or a.mat * 4 * 0.2, then you're getting into much more complicated territory, and you'll either have to do the normal ".max" processing in each formula like you mentioned before, or request a script that breaks down each part of the formula line and evaluates it as two separate kernels. -
Just place this in your scripts section somewhere. Crits works (along with misses and everything else).
class RPG::UsableItem::Damagealias_method:)min_auto_eval, :eval)def eval(a, b, v) damage = min_auto_eval(a, b, v) [damage, a.atk * 4 * 0.2].maxendendreplace a.atk * 4 * 0.2 with whatever you want the minimum to be.
Hope this helps. :) -
Thanks guys. Both answers helped a lot. :)
class RPG::UsableItem::Damagealias_method:)min_auto_eval, :eval) def eval(a, b, v) damage = min_auto_eval(a, b, v) p "dmg: #{damage} dmg. min: #{[damage, a.atk * 2 * 0.2].max}" [damage, a.atk * 2 * 0.2].max endendIndeed works. But it causes problems when using magic-attacks. There is no reference here to the item-variable so you can't check the attack-type (magical vs physical/certain-hit)
This one:
works for magical, physical and certain attack types. But it uses an overwrite (still good though).Spoilerclass Game_Battler < Game_BattlerBase #-------------------------------------------------------------------------- # * Calculate Damage #-------------------------------------------------------------------------- def make_damage_value(user, item) value = item.damage.eval(user, self, $game_variables) ### Modification Begin if ((value <= (user.atk * 0.8)) and (item.physical? || item.certain?)) # Added code: || item.certain? value = (user.atk * 0.8) elsif ((value <= (user.mat * 0.8)) and item.magical?) value = (user.mat * 0.8) end ### Modification End value *= item_element_rate(user, item) value *= pdr if item.physical? value *= mdr if item.magical? value *= rec if item.damage.recover? value = apply_critical(value) if @result.critical value = apply_variance(value, item.damage.variance) value = apply_guard(value) @result.make_damage(value.to_i, item) endend
Note: I tested this with a battle-test from the system > troops tab and both the player and the slimes had 999 defense.
Minor note: if you have an attack value of 1 then it will still be 0 due to the rounding. So you still need a [damage, 1].min line on top of it :p -
I didn't think of magic attack lol. Glad I could help though.
-
I found a way to do it without an overwrite (using a game variable instead) and by combining both solutions:
SpoilerCode:#===============================================================================# Settings#===============================================================================module Nap; module Battle MIN_DMG_PERC = 0.3 # A value between 0.0 and 1.0 MIN_DMG = 1 # The absolute minimum amount of damage dealt no matter what GAME_VAR_IDX = 90 # The game variable to use to store the user in.end; end#===============================================================================# RPG::UsableItem::Damage# For: Never deal less than 1 damage for a damaging-ability#===============================================================================class RPG::UsableItem::Damage alias nap_min_dmg_eval eval def eval(a, b, v) damage = nap_min_dmg_eval(a, b, v) [damage, Nap::Battle::MIN_DMG].max endend#===============================================================================# Game Battler# For: To ensure to deal a minimum amount of damage (in %) when the target's# defense is too high (part 1/2).#===============================================================================class Game_Battler < Game_BattlerBase #----------------------------------------------------------------------------- # Make Damage Value [ALIAS] #----------------------------------------------------------------------------- alias nap_min_dmg_perc_make_damage_value make_damage_value def make_damage_value(user, item) $game_variables[Nap::Battle::GAME_VAR_IDX] = user nap_min_dmg_perc_make_damage_value(user, item) endend#===============================================================================# Game Action Result# For: To ensure to deal a minimum amount of damage (in %) when the target's# defense is too high (part 2/2).#===============================================================================class Game_ActionResult #----------------------------------------------------------------------------- # Make Damage [ALIAS] #----------------------------------------------------------------------------- alias nap_min_dmg_perc_make_damage make_damage def make_damage(value, item) user = $game_variables[Nap::Battle::GAME_VAR_IDX] $game_variables[Nap::Battle::GAME_VAR_IDX] = nil if ((item.physical?) || item.certain?) && (value <= (user.atk * Nap::Battle::MIN_DMG_PERC)) value = (user.atk * Nap::Battle::MIN_DMG_PERC) elsif value <= (user.mat * Nap::Battle::MIN_DMG_PERC) value = (user.mat * Nap::Battle::MIN_DMG_PERC) end nap_min_dmg_perc_make_damage(value.to_i, item) endend