My own script - Having Problems

● ARCHIVED · READ-ONLY
Started by Ultima01 4 posts View original ↗
  1. I have the script
     
    def magic_evade?( a, b )
      c = rand(100000) / 100000.0
      if c < b.mev
        return true
      else
        return false
      end
    end

    I'm trying to emulate Breath Weapons from Dungeons and Dragons, which did half damage instead of none when magic resist was in effect.
     
    example damage formula: ( magic_evade?( a, b ) ) ? x : 2x
     
    But calling this seems to make the skill do absolutely nothing regardless of the target's MEV.  I have no idea what's causing this.
  2. if I understand you try to cut the damage by half when the magic evade is actif?
  3. all numbers are integer by default until they are converted to float - and in your case, c is always lower than 1 and thereby the function will always return true.


    also, how did you define x as a damage number?


    and 2x is not a valid mathematical statement...
  4. nio kasgami said:
    if I understand you try to cut the damage by half when the magic evade is actif?
    Pretty much, yeah.

    Andar said:
    all numbers are integer by default until they are converted to float - and in your case, c is always lower than 1 and thereby the function will always return true.
    Tried that. Went so far as to convert them to floats too. (using .to_f, making the denominator in the script 100000.0)
    UPDATE: I take that back. Your suggestion worked.

    Andar said:
    also, how did you define x as a damage number?
    In the case I was testing, x = a.mat * 2 - b.mdf * 1

    Andar said:
    and 2x is not a valid mathematical statement...
    I meant 2 * x