Custom Damage Formulas on certain weapons

Discussion in 'RGSS Script Requests' started by AceTheMad, Nov 6, 2018.

  1. AceTheMad

    AceTheMad Village Madman Veteran

    Messages:
    224
    Likes Received:
    70
    Location:
    Nowhere, Mars
    First Language:
    English
    Hello.

    I was trying to make a script that gives specific weapons custom damage formulas (guns are based off of dex, and swords are based off of str), but then I realized I have literally no idea what I am doing, so I gave up and came here.

    I was hoping if anybody could help me out and...you get the idea.

    Thanks.

    AceTheMad
     
    #1
  2. ultimagicka

    ultimagicka Villager Member

    Messages:
    28
    Likes Received:
    5
    Location:
    Beyond the Event Horizon
    First Language:
    English
    Primarily Uses:
    RMMV
    You can define all sorts of cool stuff inside the formula box in the damage section of skills you make, so gun damage based on agility is definitely a thing. I recently seen this article a Steam user had made which looks really amazing. Give it a look and maybe you can realize your vision. Good luck. https://steamcommunity.com/sharedfiles/filedetails/?id=681253029


    Edit: sorry this is in RGSS. Disregard
     
    #2
  3. DerVVulfman

    DerVVulfman Resident Werewolf Veteran

    Messages:
    314
    Likes Received:
    150
    First Language:
    English
    Primarily Uses:
    RMXP
    There's just no love for the monsters. C'mon. Not every monster attacks by brute strength, ya know? We werewolves are a dextrous lot.

    Oh, alright. I cobbled this up. Basically, I made a module for you to pick and choose what weapons ... AND MONSTERS.... apply a stat other than strength to the self.damage calculation. If you don't have a weapon or monster defined within, it defaults back to strength..

    For this, I also directly edited the Game_Battler class's attack_effect method. It's cheesy and simple, putting in a section that reads from the config and decides which stat to use. But as one said: "If it's stupid and it works, it's not stupid." :D

    If you have any other script that modifies the attack_effect method, put this one above that method. This one overwrites changes while other scripts may merely add new options. I hope it's easy enough to understand.

    Code:
    module DVCalc
     
      #--------------------------------------------------------------------------
      WEAPON, MONSTER = {}, {} # Do Not Touch
      #--------------------------------------------------------------------------
     
      # The basic idea is to make MONSTER or WEAPON entries like below.  What is
      # in the brackets [ ] is the ID of the monster or weapon from the database.
     
      # Valid entries on the right are the 4 stats "Str", "Agi", "Dex" and "Int".
      # If no monster or weapon has an entry, it defaults to "Str" as normal.
     
      # I set up Knives to use Agility
      WEAPON[13]  = "Agi"
      WEAPON[14]  = "Agi"
      WEAPON[15]  = "Agi"
      WEAPON[16]  = "Agi"
      # I set up Bows and Guns to use Dexterity
      WEAPON[17]  = "Dex"
      WEAPON[18]  = "Dex"
      WEAPON[19]  = "Dex"
      WEAPON[20]  = "Dex"
      WEAPON[21]  = "Dex"
      WEAPON[22]  = "Dex"
      WEAPON[23]  = "Dex"
      WEAPON[24]  = "Dex"
     
     
      # I set up a bunch of 'Demon' and 'Angel' types for Intelligence attacks
      MONSTER[1]  = "Int"
      MONSTER[7]  = "Int"
      MONSTER[8]  = "Int"
      MONSTER[16] = "Int"
      MONSTER[23] = "Int"
      MONSTER[24] = "Int"
      MONSTER[25] = "Int"
      MONSTER[31] = "Int"
      MONSTER[32] = "Int"
      # Some rather reptilian or aquatics use their speed
      MONSTER[10] = "Agi"
      MONSTER[11] = "Agi"
      MONSTER[15] = "Agi"
      MONSTER[18] = "Agi"
      MONSTER[19] = "Agi"
     
    end
    
    
    #==============================================================================
    # ** Game_Battler
    #------------------------------------------------------------------------------
    #  This class deals with battlers. It's used as a superclass for the Game_Actor
    #  and Game_Enemy classes.
    #==============================================================================
    
    class Game_Battler
     
      #--------------------------------------------------------------------------
      # * Applying Normal Attack Effects
      #     attacker : battler
      #--------------------------------------------------------------------------
      def attack_effect(attacker)
        # Clear critical flag
        self.critical = false
        # First hit detection
        hit_result = (rand(100) < attacker.hit)
        # If hit occurs
        if hit_result == true
          # Calculate basic damage
          atk = [attacker.atk - self.pdef / 2, 0].max
          # ---------------------------------------------------------------------
          # Start of Change Here
          # ---------------------------------------------------------------------
          stat    = attacker.str
          hash    = (attacker.is_a?(Game_Enemy)) ? DVCalc::MONSTER : DVCalc::WEAPON
          id      = (attacker.is_a?(Game_Enemy)) ? attacker.id : attacker.weapon_id
          stat_id = hash[id] if hash.has_key?(id)
          unless stat_id.nil?
            case stat_id
            when "Str" ;  stat  = attacker.str
            when "Dex" ;  stat  = attacker.dex
            when "Agi" ;  stat  = attacker.agi
            when "Int" ;  stat  = attacker.int
            else ;        stat  = attacker.str
            end
          end
          self.damage = atk * (20 + stat) / 20
          # ---------------------------------------------------------------------
          # End of Change Here
          # ---------------------------------------------------------------------
          # Element correction
          self.damage *= elements_correct(attacker.element_set)
          self.damage /= 100
          # If damage value is strictly positive
          if self.damage > 0
            # Critical correction
            if rand(100) < 4 * attacker.dex / self.agi
              self.damage *= 2
              self.critical = true
            end
            # Guard correction
            if self.guarding?
              self.damage /= 2
            end
          end
          # Dispersion
          if self.damage.abs > 0
            amp = [self.damage.abs * 15 / 100, 1].max
            self.damage += rand(amp+1) + rand(amp+1) - amp
          end
          # Second hit detection
          eva = 8 * self.agi / attacker.dex + self.eva
          hit = self.damage < 0 ? 100 : 100 - eva
          hit = self.cant_evade? ? 100 : hit
          hit_result = (rand(100) < hit)
        end
        # If hit occurs
        if hit_result == true
          # State Removed by Shock
          remove_states_shock
          # Substract damage from HP
          self.hp -= self.damage
          # State change
          @state_changed = false
          states_plus(attacker.plus_state_set)
          states_minus(attacker.minus_state_set)
        # When missing
        else
          # Set damage to "Miss"
          self.damage = "Miss"
          # Clear critical flag
          self.critical = false
        end
        # End Method
        return true
      end
    end
     
    #3
  4. AceTheMad

    AceTheMad Village Madman Veteran

    Messages:
    224
    Likes Received:
    70
    Location:
    Nowhere, Mars
    First Language:
    English
    Thank you, DerVVulfman! I'm gonna try it out.

    (Also, remind me to add you to the credits. And send you a completed copy of the game I am working on, if you want.)

    Update: Works beautifully. Thank you.

    Update: So...I do have one issue. So, I have tried to fix this myself, but it seems that, on line 97, I have a problem. Basically, when the conditional has a "<", the actor crits every turn. However, when I switch it to a ">", the enemy crits every turn...Hmmm...
     
    Last edited: Nov 20, 2018
    #4
  5. DerVVulfman

    DerVVulfman Resident Werewolf Veteran

    Messages:
    314
    Likes Received:
    150
    First Language:
    English
    Primarily Uses:
    RMXP
    The key factor is the line:
    Code:
    if rand(100) < 4 * attacker.dex / self.agi
    It only permits the victim (or self) to be struck with a critical hit based on the attacker's dexterity vs the victim's agility. This portion of the method was not changed within this script, so the victim's chance of suffering a critical hit was likewise not changed.

    If my actor has an extra high dexterity compared to my ghosts, he's always going to deliver a crit.
     
    #5
  6. AceTheMad

    AceTheMad Village Madman Veteran

    Messages:
    224
    Likes Received:
    70
    Location:
    Nowhere, Mars
    First Language:
    English
    Ah alright. I'm gonna go ahead and make sure that my stats are not out of the wazoo. X'D

    Edit: OKAAAAYYYY...So it seems like I accidentally set my actor's dexterity to be 900. Oops. X'D
     
    #6
    DerVVulfman likes this.

Share This Page