Lowell

The Walking Atelier
Veteran
Joined
Apr 21, 2012
Messages
292
Reaction score
69
First Language
English
Primarily Uses
So I decided to try and write a somewhat complex damage script and keep getting 0 on the returns.

The math itself isn't the issue since I have it working in Excel. My problems lies with the script turning 0 damage, likely due to the fact that it's not getting the weapon type, but I honestly don't know what the issue is to be honest.

For clarification, I'm using Neldersons Xstat script and Kread_Ex's Skill Upgrades script

Neldersons script is where the xstat is drawn from.

Kread_Ex is where skill_level(skill) is drawn from

Code:
class Game_Battler < Game_BattlerBase  #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=  #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=		  def melee(base,a,b,mult)  #-----------------------------------------------------------  # Damage Formula: Dagger:   (a.xstat.str/2 + a.agi)  #-----------------------------------------------------------	if a.weapons[0].wtype_id == 1	    watk = (a.xstat.str/2 + a.agi)    return (5 + skill_level(skill) * Math.sqrt(watk/b.xstat.end * (a.atk + base) * mult * a.level/16)).to_i - b.def  #-----------------------------------------------------------  # Damage Formula: Sword:    (a.xstat.str)  #-----------------------------------------------------------  elsif a.weapons[0].wtype_id == 2	  watk = (a.xstat.str)      return (5 + skill_level(skill) * Math.sqrt(watk/b.xstat.end * (a.atk + base) * mult * a.level/16)).to_i - b.def  #-----------------------------------------------------------  # Damage Formula: Edge:     (a.xstat.str + a.xstat.tec/2)  #-----------------------------------------------------------  elsif a.weapons[0].wtype_id == 3	  watk = (a.xstat.str + a.xstat.tec/2)      return (5 + skill_level(skill) * Math.sqrt(watk/b.xstat.end * (a.atk + base) * mult * a.level/16)).to_i - b.def  #-----------------------------------------------------------  # Damage Formula: Foil:     (a.xstat.str/2 + a.xstat.dex)  #-----------------------------------------------------------  elsif a.weapons[0].wtype_id == 4	  watk = (a.xstat.str/2 + a.xstat.dex)      return (5 + skill_level(skill) * Math.sqrt(watk/b.xstat.end * (a.atk + base) * mult * a.level/16)).to_i - b.def  #-----------------------------------------------------------  # Damage Formula: Ax:       (a.xstat.str*2)  #-----------------------------------------------------------  elsif a.weapons[0].wtype_id == 5	  watk = (a.xstat.str*2)      return (5 + skill_level(skill) * Math.sqrt(watk/b.xstat.end * (a.atk + base) * mult * a.level/16)).to_i - b.def  #-----------------------------------------------------------  # Damage Formula: Bludgeon: (a.xstat.str*1.7)  #-----------------------------------------------------------  elsif a.weapons[0].wtype_id == 6	  watk = (a.xstat.str*1.7)      return (5 + skill_level(skill) * Math.sqrt(watk/b.xstat.end * (a.atk + base) * mult * a.level/16)).to_i - b.def  #-----------------------------------------------------------  # Damage Formula: Polearm:  (a.xstat.str + a.xstat.dex)  #-----------------------------------------------------------  elsif a.weapons[0].wtype_id == 7	  watk = (a.xstat.str + a.xstat.dex)      return (5 + skill_level(skill) * Math.sqrt(watk/b.xstat.end * (a.atk + base) * mult * a.level/16)).to_i - b.def  #-----------------------------------------------------------    # Damage Formula: Bow:      (a.xstat.str/2 + a.xstat.dex*2)  #-----------------------------------------------------------  elsif a.weapons[0].wtype_id == 8	  watk = (a.xstat.str/2 + a.xstat.dex*2)      return (5 + skill_level(skill) * Math.sqrt(watk/b.xstat.end * (a.atk + base) * mult * a.level/16)).to_i - b.def    #-----------------------------------------------------------  # Damage Formula: Staff:    (a.xstat.int*2)  #-----------------------------------------------------------  elsif a.weapons[0].wtype_id == 9	  watk = (a.xstat.int*2)      return (5 + skill_level(skill) * Math.sqrt(watk/b.xstat.end * (a.atk + base) * mult * a.level/16)).to_i - b.def  #-----------------------------------------------------------  # Damage Formula: Tome:     (a.xstat.wil*2)  #-----------------------------------------------------------  elsif a.weapons[0].wtype_id == 10	  watk = (a.xstat.wil*2)      return (5 + skill_level(skill) * Math.sqrt(watk/b.xstat.end * (a.atk + base) * mult * a.level/16)).to_i - b.def  #-----------------------------------------------------------  # Damage Formula: Melee:    (a.xstat.str/2 + a.agi/2)  #-----------------------------------------------------------  elsif a.weapons[0].wtype_id == 11	  watk = (a.xstat.str/2 + a.agi/2)      return (5 + skill_level(skill) * Math.sqrt(watk/b.xstat.end * (a.atk + base) * mult * a.level/16)).to_i - b.def  #-----------------------------------------------------------  # Damage Formula: Whip:     (a.xstat.str/2 + a.xstat.dex)  #-----------------------------------------------------------  elsif a.weapons[0].wtype_id == 12	  watk = (a.xstat.str/2 + a.xstat.dex)      return (5 + skill_level(skill) * Math.sqrt(watk/b.xstat.end * (a.atk + base) * mult * a.level/16)).to_i - b.def  #-----------------------------------------------------------  # Damage Formula: Firearm:  (a.xstat.dex*2 + a.agi)  #-----------------------------------------------------------  elsif a.weapons[0].wtype_id == 13	  watk = (a.xstat.dex*2 + a.agi)      return (5 + skill_level(skill) * Math.sqrt(watk/b.xstat.end * (a.atk + base) * mult * a.level/16)).to_i - b.def  #-----------------------------------------------------------  # Damage Formula: Default  #-----------------------------------------------------------  else	  watk = 16      return (5 + skill_level(skill) * Math.sqrt(watk/b.xstat.end * (a.atk + base) * mult * a.level/16)).to_i - b.def    end  end    def ether(base,a,b,mult,type)    case type.to_s  #-----------------------------------------------------------  # Damage Formula: Intelligence Damage  #-----------------------------------------------------------    when "INT"      return (5 + skill_level(skill) * Math.sqrt(a.xstat.int/b.xstat.wil * (a.mat + base) * mult * a.level/16)).to_i - b.mdf  #-----------------------------------------------------------  # Damage Formula: Willpower Damage  #-----------------------------------------------------------    when "WIL"      return (5 + skill_level(skill) * Math.sqrt(a.xstat.wil/b.xstat.wil * (a.mat + base) * mult * a.level/16)).to_i - b.mdf  #-----------------------------------------------------------  # Damage Formula: Tech Damage  #-----------------------------------------------------------    when "TEC"      return (5 + skill_level(skill) * Math.sqrt(a.xstat.tec/b.xstat.wil * (a.mat + base) * mult * a.level/16)).to_i - b.mdf  #-----------------------------------------------------------  # Damage Formula: Else Case  #-----------------------------------------------------------    else      return (5 + skill_level(skill) * Math.sqrt(16/b.xstat.wil * (a.mat + base) * mult * a.level/16)).to_i - b.mdf    end    end    #-----------------------------------------------------------  # Damage Formula: Thunderclap  #-----------------------------------------------------------    def recover(base,a,b,mult,type)    case type.to_s  #-----------------------------------------------------------  # Recovery Formula: INT  #-----------------------------------------------------------    when "INT"      return (5 + skill_level(skill) * Math.sqrt(a.xstat.int * (a.mat + base) * mult * a.level/16)).to_i  #-----------------------------------------------------------  # Recovery Formula: WIL  #-----------------------------------------------------------    when "WIL"      return (5 + skill_level(skill) * Math.sqrt(a.xstat.wil * (a.mat + base) * mult * a.level/16)).to_i  #-----------------------------------------------------------  # Recovery Formula: TEC  #-----------------------------------------------------------    when "TEC"      return (5 + skill_level(skill) * Math.sqrt(a.xstat.tec * (a.mat + base) * mult * a.level/16)).to_i  #-----------------------------------------------------------  # Recovery Formula: Else Case  #-----------------------------------------------------------    else      return (5 + skill_level(skill) * Math.sqrt(12 * (a.mat + base) * mult * a.level/16)).to_i    end    end    #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=  # CLOSING STATEMENT  #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=end
 
Last edited by a moderator:

Another Fen

Veteran
Veteran
Joined
Jan 23, 2013
Messages
608
Reaction score
320
First Language
German
Primarily Uses
Hi,

When any complex damage formula keeps returning 0, it might be because the formula evaluation causes an error. To prevent the game from hiding such errors, you can remove the "rescue 0" part from the evaluation method:

class RPG::UsableItem::Damage

  def eval(a, b, v)

    [Kernel.eval(@formula), 0].max * sign #rescue 0

  end

end

You can also modify your damage formula to

(original damage formula).tap { |res| p res }

to print the damage calculated by your damage formula to the console, which might also be helpful to track down the source of the error.

How do you include your method in your damage formula? Does this example work for you?
a.melee(10000, a, b, 999)

Does your attacker always have a weapon equipped in their first weapon slot? If the attacker is unarmed, accessing the weapon type results in a NoMethodError.

Editskill  is probably not defined, as it is neither used as a local variable nor does one of the scripts you mentioned define a method with this name. If you want to refer to the skill the attacker is currently using, you can try to replace it by

a.current_action.item

However, this will not work for skills used from the skills menu.
 
Last edited by a moderator:

Latest Threads

Latest Profile Posts

I played Deltarune chapter 2 today! It was great. No spoilers, but I hope one day I can design a world as interesting as Toby Fox and team.
Holy cow, I have made Row Formation work again with OTB!

Now, my devious machinations can finally be born...
finished the second chapter of deltarune today, I gotta say that the 3 years wait was worth it lol

Forum statistics

Threads
115,151
Messages
1,087,680
Members
149,685
Latest member
Dark_OP
Top