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.

CW: DnD Battle Formula

Minor Update (02/04/08): Condensed the script some and took out the unedited parts to make it shorter (DEMO has NOT been updated with shorter script - but it still works the same).

This is my DnD damage formula. The regular attack formula is almost the same as the real one. The skill formula on the other hand has a home brewed twist. The biggest advantage of this DnD system is that you can control the number of "dice" and the number of "sides" on the dice in the database. You can also set weapons to be melee and ranged, but that has to be done within the script (at the top).

Anyway here's a quick overview of what I think are the pros and cons...
Advantages:
-control damage rolls from database!
-melee and range weapons types
-DnD style damage

Disadvantages:
-can only roll up to 9, 99 sided dice (for normal attack)
-weapon types still have to be assigned in script
-script still needs a little tidying

Ok now for a quick run down of how to control the "dice" in the database...

First we need to go to weapons.
Here the value of ATT is broken down into two parts:
> the first digit is the number of dice
> the second digits are the number of side on the dice
so for example...
106 = 1d6
210 = 2d10
and so on
this means if you had a weapon with 2d8 (ATT = 108) you could "roll" as much as 16
(plus modifiers) or as little as 2 (plus mods).

Further Explanations on Normal Attack:
str, dex and int and the modifiers work same as in DnD
(for those of you that aren't familar mod = (stat - 10)/ 2 )
and agi is the attack bonus (AB)

attack roll:
a few of the numbers in the formulas are slightly different (ie: 19 for critical chance and 9 in armour class) because I used rand(20) for attack rolls which includes 0...19 rather then 1...20 but in theory it works almost the same (actually one has a slightly better chance to hit)
again for those who aren't familar with DnD or D20
hit[DnD] = attack roll + stat mod + AB > 10 + AR + dex mod
or 
hit[this one] = rand(20) + stat mod + AB > 9 + def + dex mod
(where stat mod is either dex(range) or str(melee))

damage roll:
damage rolls are the same as DnD
dmg = XdY + stat mod (min of 1)
(where X = number of dice and Y = sides)

Skills - a quick run down of what you might wanta know:
Skills have more options to them but run similarly to the normal attack.
Rather then explaining the formulas I'll explain how each value in the Skills section of the data base effects them.
SP Cost: same as always
Power: a "skill damage roll" like normal attacks except now the first TWO numbers control the number of dice and the last TWO control the sides. use a negative power for healing skills.
ATK-F: multiplier based on NORMAL damage (note** value is divided by 10)
STR-F: control whether or not a strength modifier is used in the calculations the value controls how much of the multiplier is used by a percent, 100 being the full thing 0 being none at all, a 50 would use half the multiplier.
DEX-F,
INT-F,
AGI-F: all the same as STR-F except for the other stats note you can use as many or as little of the modifiers as you want in your skill calculation
Hit Rate: adjust hit rate by a %
PDEF:  controls how much and whether pdef is used in checking if an attack succeeds
MDEF:  same as PDEF except for with MDEF
Varaince: nothing at the moment
note* if there is a value > 0 in both Power and ATK-F then the result is added together.
(if one is zero that part will be ignored)

After looking at the script one can probably tell I'm still new at scripting so if
anyone finds any bugs or notices something that can be cleaned up please let me
know. (For example how to group all of the 'range' keys together rather then having
to keep making new ones).

Demo: http://www.mediafire.com/?wzyxnbxwy6b
(note* I forgot to set the gun to range attack when I uploaded the demo)
Script:
#==============================================================================
# ** CW: DnD Formula **                                    ver. 1.01 (02/04/08)
#------------------------------------------------------------------------------
# Clockwise [B.Gale]
#  PLEASE GIVE CRIDIT IF YOU ARE GOING TO USE THIS SCRIPT

#==============================================================================

class Game_Battler
  Default_Weapn = 'Melee'
  Type = { 1 => 'Range', 5 => 'Range'}
#===============================================================================
# How to control the "dice" in the database...
# First we need to go to weapons.
# Here the value of ATT is broken down into two parts:
# > the first digit is the number of dice
# > the second digits are the number of side on the dice
# so for example...
# 106 = 1d6
# 210 = 2d10
# and so on
# this means if you had a weapon with 2d8 (ATT = 108) you could "roll" as much as
# 16 (plus modifiers) or as little as 2 (plus mods)
#===============================================================================

  #--------------------------------------------------------------------------
  # * Applying Normal Attack Effects
  #    attacker : battler
  #--------------------------------------------------------------------------
  def attack_effect(attacker)
    # Clear critical flag
    self.critical = false
    # Formulas #
    atk_roll = rand(20)
    atk_bonus = attacker.agi
    dodge = ((self.dex - 10) / 2)
    hit_con = attacker.hit
    if Type.has_key?(attacker.weapon_id)
      atk_mod  = (attacker.dex - 10) / 2    #Range
    else
      atk_mod  = (attacker.str - 10) / 2    #Melee or Enemy
    end
    #### CALCULATE #####========================================================
    # Hit Detection #
    hit_result = (hit_con * (atk_mod + atk_roll + atk_bonus) > 9 + self.pdef + dodge)
      if hit_result == true or atk_roll == 19
        # Calculate Base Damage #---------------------------------------------
        atk = attacker.atk.to_s
        dice  = atk.chop.chop.to_i
        side = atk[-2,2].to_i
        self.damage = [dice * rand(side) + atk_mod,1].max
        #---------------------------------------------------------------------
        # Element correction
        self.damage *= elements_correct(attacker.element_set)
        self.damage /= 100
        # If damage value is strictly positive
        if self.damage > 0
          # Critical Chance #-------------------------------------------------
          if atk_roll == 19
            crit_roll = rand(20)
            crit_result = (atk_mod + crit_roll + atk_bonus > 9 + self.pdef + dodge)
            if crit_result == true
              self.damage *= 2
              self.critical = true
            end
          end
          #-------------------------------------------------------------------
          # Guard correction
          if self.guarding?
            self.damage /= 2
          end
        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
  #--------------------------------------------------------------------------
  # * Apply Skill Effects
  #    user  : the one using skills (battler)
  #    skill : skill
  #--------------------------------------------------------------------------
  def skill_effect(user, skill)
    # Clear critical flag
    self.critical = false
    # If skill scope is for ally with 1 or more HP, and your own HP = 0,
    # or skill scope is for ally with 0, and your own HP = 1 or more
    if ((skill.scope == 3 or skill.scope == 4) and self.hp == 0) or
      ((skill.scope == 5 or skill.scope == 6) and self.hp >= 1)
      # End Method
      return false
    end
    # Clear effective flag
    effective = false
    # Set effective flag if common ID is effective
    effective |= skill.common_event_id > 0
   
    ####  SKILL FORMULAS  #####================================================
    # Basic Damage Roll #
      b_atk  = user.atk.to_s
      b_dice  = b_atk.chop.chop.to_i
      b_side  = b_atk[-2,2].to_i
    base_dmg  = [b_dice * rand(b_side),1].max
    # Skill Damage Roll # 
      s_atk  = skill.power.to_s
      s_dice  = s_atk.chop.chop.to_i
      s_side  = s_atk[-2,2].to_i
    skill_dmg = s_dice * rand(s_side)
    # Basic Damage Multiplier #
    dmg_mod  = skill.atk_f
    # Stat Modifiers #
    stat_mod =  ((user.str - 10) / 2) * (skill.str_f / 100)
    stat_mod += ((user.dex - 10) / 2) * (skill.dex_f / 100)
    stat_mod += ((user.int - 10) / 2) * (skill.int_f / 100)
    stat_mod += ((user.agi - 10) / 2) * (skill.agi_f / 100)
    # Defenses #
    skill_pdef  = (self.pdef * skill.pdef_f / 100)
    skill_mdef  = (((user.int - 10) / 2) + self.mdef) * (skill.mdef_f / 100)
    dodge = ((self.dex - 10) / 2)
    #===========================================================================
    # Hit Detection#
    hit = skill.hit
    if skill.power > 0 or skill.atk_f > 0
      hit *= user.hit / 100
      skill_roll = rand(20)
      hit_result = (hit * (skill_roll + stat_mod) > skill_pdef + skill_mdef + dodge)
    else
      hit_result = (hit > rand(100))
      stat_mod *=  (-1)
    end
      # Set effective flag if skill is uncertain
    effective |= hit < 100 # Set effective flag if skill is uncertain
      # If hit occurs
    if hit_result == true or skill_roll == 19
     
      ### DAMAGE ###------------------------------------------------------------
      self.damage = (skill_dmg + (base_dmg * dmg_mod / 10) + stat_mod).to_i
      #-------------------------------------------------------------------------
     
      # Element correction #
      self.damage *= elements_correct(skill.element_set)
      self.damage /= 100
      # If damage value is strictly positive
      if self.damage > 0
        # Guard correction
        if self.guarding?
          self.damage /= 2
        end
      end
      # Second hit detection
      eva = 8 * self.agi / user.dex + self.eva
      hit = self.damage < 0 ? 100 : 100 - eva * skill.eva_f / 100
      hit = self.cant_evade? ? 100 : hit
      hit_result = (rand(100) < hit)
      # Set effective flag if skill is uncertain
      effective |= hit < 100
    end
    # If hit occurs
    if hit_result == true
      # If physical attack has power other than 0
      if skill.power != 0 and skill.atk_f > 0
        # State Removed by Shock
        remove_states_shock
        # Set to effective flag
        effective = true
      end
      # Substract damage from HP
      last_hp = self.hp
      self.hp -= self.damage
      effective |= self.hp != last_hp
      # State change
      @state_changed = false
      effective |= states_plus(skill.plus_state_set)
      effective |= states_minus(skill.minus_state_set)
      # If power is 0
      if skill.power == 0 and skill.atk_f == 0
        # Set damage to an empty string
        self.damage = ""
        # If state is unchanged
        unless @state_changed
          # Set damage to "Miss"
          self.damage = "Miss"
        end
      end
    # If miss occurs
    else
      # Set damage to "Miss"
      self.damage = "Miss"
    end
    # If not in battle
    unless $game_temp.in_battle
      # Set damage to nil
      self.damage = nil
    end
    # End Method
    return effective
  end
end

Anyways hope you like it!
 
You beat me to it!!!!!!!!!!!!!!!

I'm working on a breath of fire 3 starter project at the moment...... my next project was going to be a d&d/d20 overhaul to the RPG Maker VX! i'm still gonna go with it and have coded many.... many.... many d&d projects in c#, java, python..... but nice work!
 
Nice work, new battle damage formulas are always a nice touch to games. Something I found weird was that the enemies kept hitting big, long decimals on me.
 
@ TywinLannister2 
thanks,
though I've never played through BoF3 your scripts for it seem really good, I look forward to see what you do with the DnD / D20 system when you get to it. You'll probably be able to get a lot closer to the true system then me, as I'm still very newb at scripting anything =).

@baniff
hmm.. I don't notice anything that should be keeping decimals
(though that could be due to make lack of scripting skills =P)
could try putting ().to_i around the main damage calculations but that should just fix the decimals
um...
assuming your using RMXP and don't have any conflicting scripts I'm not sure what would be wrong at the moment.
is it happening for normal attacks and skills?
 

merfie

Member

Nice job

anything that covers the multiple attacks when BAB gets higher?

I understand most of the script except where in the script and how is the weapon attack converted to dice rolls?
 
Nothing covers multiple attacks with higher BAB yet, I may be able to add something this weekend though.
Not entirely sure how I'm going to make it work yet, as it generally takes a full round action in DnD /D20 (if i remember correctly).
Thanks for reminding me though =).

For the script...
weapon attack is converted into dice rolls in the lines like these
        > atk = attacker.atk.to_s
        > dice  = atk.chop.chop.to_i
        > side = atk[-2,2].to_i
        > self.damage = [dice * rand(side) + dex_mod,1].max
the atk is the takes the weapon attack and puts it into a string (.to_s)
the dice takes that string and 'chops' of the last two digits (.chop.chop) and then turns the string back into an interger (.to_i)
while the side side takes the weapon attack string and only holds onto the last two digits ([-2,2]) and then turns it back into an interger (.to_i)
the self damage just multiplies them out

hope that helps =)
 
Hey! Awesome script! I love it! My dream was making a DnD game... and you helped! But, can you make this RTAB compatible? When you put RTAB below damage formula, it completly over rides it, and when you put it over a error appears.
 
I can try to make it compatible with RTAB.
If its one of DerVVulfman's this should mostly work (still don't have all the extra parts working with it)
Code:
#==============================================================================
# ** CW: DnD Formula **                                     ver. 1.0 (01/03/08)
#------------------------------------------------------------------------------
# Clockwise [B.Gale] 
#   PLEASE GIVE CRIDIT IF YOU ARE GOING TO USE THIS SCRIPT
#   
#==============================================================================

class Game_Battler
  Default_Weapn = 'Melee'
  Type = { 17 => 'Range', 18 => 'Range'}
#=============================================================================== 
# How to control the "dice" in the database...
# First we need to go to weapons.
# Here the value of ATT is broken down into two parts:
# > the first digit is the number of dice
# > the second digits are the number of side on the dice
# so for example...
# 106 = 1d6
# 210 = 2d10
# and so on
# this means if you had a weapon with 2d8 (ATT = 108) you could "roll" as much as
# 16 (plus modifiers) or as little as 2 (plus mods)
#===============================================================================

  #--------------------------------------------------------------------------
  # * Applying Normal Attack Effects
  #     attacker : battler
  #--------------------------------------------------------------------------
  def attack_effect(attacker)
    # Clearing the critical flag
    self.critical[attacker] = false
    state_p[attacker] = []
    state_m[attacker] = []
    # Formulas #
    atk_roll = rand(20)
    atk_bonus = attacker.agi
    dodge = ((self.dex - 10) / 2)
    hit_con = attacker.hit
    if Type.has_key?(attacker.weapon_id)
      atk_mod  = (attacker.dex - 10) / 2     #Range
    else
      atk_mod  = (attacker.str - 10) / 2     #Melee or Enemy
    end
    #### CALCULATE #####========================================================
    # Hit Detection #
    hit_result = (hit_con * (atk_mod + atk_roll + atk_bonus) > 9 + self.pdef + dodge)
      if hit_result == true or atk_roll == 19
        # Calculate Base Damage #---------------------------------------------
        atk = attacker.atk.to_s
        dice  = atk.chop.chop.to_i
        side = atk[-2,2].to_i
        self.damage[attacker] = [dice * rand(side) + atk_mod,1].max
        #---------------------------------------------------------------------
        # Element correction
        self.damage[attacker] *= elements_correct(attacker.element_set)
        self.damage[attacker] /= 100
        # If damage value is strictly positive,
        if self.damage[attacker] > 0
          # Critical Chance #-------------------------------------------------
          if atk_roll == 19
            crit_roll = rand(20) 
            crit_result = (atk_mod + crit_roll + atk_bonus > 9 + self.pdef + dodge)
            if crit_result == true 
              self.damage[attacker] *= 2
              self.critical[attacker] = true
            end
          end
          #---------------------------------------------------------------------
        # Defense correction
        if self.guarding?
          self.damage[attacker] /= 2
        end
      end
      # Second on-target hit decision
      eva = 8 * self.agi / attacker.dex + self.eva
      hit = self.damage[attacker] < 0 ? 100 : 100 - eva
      hit = self.cant_evade? ? 100 : hit
      hit_result = (rand(100) < hit)
    end
    # In case of on-target hit
    if hit_result == true
      # State shocking cancellation
      remove_states_shock
      # From HP damage subtraction
      # State change
      @state_changed = false
      states_plus(attacker, attacker.plus_state_set)
      states_minus(attacker, attacker.minus_state_set)
    # In case of miss
    else
      # Setting "Miss" to the damage
      self.damage[attacker] = "Miss"
      # Clearing the critical flag
      self.critical[attacker] = false
    end
    # Method end
    return true
  end
  #--------------------------------------------------------------------------
  # * Apply Skill Effects
  #     user  : the one using skills (battler)
  #     skill : skill
  #--------------------------------------------------------------------------
  def skill_effect(user, skill)
    # Clearing the critical flag
    self.critical[user] = false
    state_p[user] = []
    state_m[user] = []
    # Effective range of skill with friend of HP 1 or more, your own HP 0,
    # Or when the effective range of skill with the friend of HP 0, your own HP are 1 or more
    if ((skill.scope == 3 or skill.scope == 4) and self.hp == 0) or
       ((skill.scope == 5 or skill.scope == 6) and self.hp >= 1)
      # Method end
      return false
    end
    # Clearing the effective flag
    effective = false
    # When common event ID is valid setting the effective flag
    effective |= skill.common_event_id > 0
    
     ####  SKILL FORMULAS   #####================================================
    # Basic Damage Roll #
      b_atk   = user.atk.to_s
      b_dice  = b_atk.chop.chop.to_i
      b_side  = b_atk[-2,2].to_i
    base_dmg  = [b_dice * rand(b_side),1].max
    # Skill Damage Roll #   
      s_atk   = skill.power.to_s
      s_dice  = s_atk.chop.chop.to_i
      s_side  = s_atk[-2,2].to_i
    skill_dmg = s_dice * rand(s_side)
    # Basic Damage Multiplier #
    dmg_mod   = skill.atk_f
    # Stat Modifiers #
    stat_mod =  ((user.str - 10) / 2) * (skill.str_f / 100)
    stat_mod += ((user.dex - 10) / 2) * (skill.dex_f / 100)
    stat_mod += ((user.int - 10) / 2) * (skill.int_f / 100)
    stat_mod += ((user.agi - 10) / 2) * (skill.agi_f / 100)
    # Defenses #
    skill_pdef  = (self.pdef * skill.pdef_f / 100)
    skill_mdef  = (((user.int - 10) / 2) + self.mdef) * (skill.mdef_f / 100)
    dodge = ((self.dex - 10) / 2)
    #===========================================================================
    # Hit Detection#
    hit = skill.hit
    if skill.power > 0 or skill.atk_f > 0
      hit *= user.hit / 100
      skill_roll = rand(20)
      hit_result = (hit * (skill_roll + stat_mod) > skill_pdef + skill_mdef + dodge)
    else
      hit_result = (hit > rand(100))
      stat_mod *=  (-1)
    end
      # Set effective flag if skill is uncertain
    effective |= hit < 100 
      # If hit occurs
    if hit_result == true or skill_roll == 19
      
      ### DAMAGE ###------------------------------------------------------------
      self.damage[user] = (skill_dmg + (base_dmg * dmg_mod / 10) + stat_mod).to_i
      #-------------------------------------------------------------------------
      
      # Element correction #
      self.damage[user] *= elements_correct(skill.element_set)
      self.damage[user] /= 100
      # When the mark of the damage is correct
      if self.damage[user] > 0
        # Defense correction
        if self.guarding?
          self.damage[user] /= 2
        end
      end
      # Second on-target hit decision
      eva = 8 * self.agi / user.dex + self.eva
      hit = self.damage[user] < 0 ? 100 : 100 - eva * skill.eva_f / 100
      hit = self.cant_evade? ? 100 : hit
      hit_result = (rand(100) < hit)
      # In case of uncertain skill setting the effective flag
      effective |= hit < 100
    end
    # In case of on-target hit
    if hit_result == true 
      # In case of physical attack other than power 0
      if skill.power != 0 and skill.atk_f > 0
        # State shocking cancellation
        remove_states_shock
        # Setting the effective flag
        effective = true
      end
      # The fluctuation decision of HP
      last_hp = [[self.hp - self.damage[user], self.maxhp].min, 0].max      
      # Effective decision
      effective |= self.hp != last_hp
      # State change
      @state_changed = false
      effective |= states_plus(user, skill.plus_state_set)
      effective |= states_minus(user, skill.minus_state_set)
      unless $game_temp.in_battle
        self.damage_effect(user, 1)
      end
      # When power 0 is,
      if skill.power == 0 and skill.atk_f == 0
        # Setting the null line to the damage
        self.damage[user] = ""
        # When there is no change in the state,
        unless @state_changed
          # Setting "Miss" to the damage
          self.damage[user] = "Miss"
        end
      end
    # In case of miss
    else
      # Setting "Miss" to the damage
      self.damage[user] = "Miss"
    end
    # When it is not in the midst of fighting,
    unless $game_temp.in_battle
      # Setting nil to the damage
      self.damage[user] = nil
    end
    # Method end
    return effective
  end
end

If it's another RTAB you'll probably have to post a link to it so I can see where its messing up.
 

merfie

Member

Thanks... that was really helpful, I wanted to make my own dnd system but I never figured out how to get the attack to dice translation so I was curious how it actually worked
 
Okay RTAB works now, but, I also like cogwheels HP/SP/EXP bars, can you make this compatible?
Code:
# HP/SP/EXPゲージ表示スクリプト Ver 1.00
# é…
 
Strange, the bar script that was with the RTAB I downloaded seemed to still work

Code:
#===========================================================================
# *** HP/MP/ATB/LimitBreak bar Slanted Style Compatible with RTAB ***
# *** Version 2.1
#---------------------------------------------------------------------------
# by Clive 
# based on Cogwheel's Bars and Sephiroth Spawn's Slanted Bars.
#---------------------------------------------------------------------------
# ----- GREAT THANKS to DerVVulfman for solving the lag problem
#------This is a plug and play script so it should work without any problem!
#=============================================================================

# If using with Limit Break, must paste BELOW the Limit Break script as it re-
# writes the 'Gauge drawing' system.  Will cause an error if not properly put.

# If used with Trickster's STEAL SCRIPT version 6 R1 (revision 1), then the
# height of RTAB's AT Bar (Draw Actor ATG) may not be smaller than 5 pixels 
# due to a float-to-float error.  A height of 6 pixels is the smallest.


#==============================================================================
# ** Game_Actor
#------------------------------------------------------------------------------
#  This class handles the actor. It's used within the Game_Actors class
#  ($game_actors) and refers to the Game_Party class ($game_party).
#==============================================================================

class Game_Actor < Game_Battler
  #--------------------------------------------------------------------------
  # * Get the current EXP
  #--------------------------------------------------------------------------
  def now_exp
    return @exp - @exp_list[@level]
  end
  #--------------------------------------------------------------------------
  # * Get the next level's EXP
  #--------------------------------------------------------------------------
  def next_exp
    return @exp_list[@level+1] > 0 ? @exp_list[@level+1] - @exp_list[@level] : 0
  end
end


#==============================================================================
# ** Window_Base 
#------------------------------------------------------------------------------
#  This class is for all in-game windows.
#==============================================================================

class Window_Base < Window  
  
  #==========================================================================
  # * Draw Slant Bar(by SephirothSpawn)
  #==========================================================================
  def draw_slant_bar(x, y, min, max, width = 152, height = 6,
      bar_color = Color.new(150, 0, 0, 255),
      end_color = Color.new(255, 255, 60, 255))
    # Draw Border
    for i in 0..height
      self.contents.fill_rect(x + i, y + height - i, width + 1, 1, Color.new(50, 50, 50, 255))
    end
    # Draw Background
    for i in 1..(height - 1)
      r = 100 * (height - i) / height + 0 * i / height
      g = 100 * (height - i) / height + 0 * i / height
      b = 100 * (height - i) / height + 0 * i / height
      a = 255 * (height - i) / height + 255 * i / height
      self.contents.fill_rect(x + i, y + height - i, width, 1, Color.new(r, b, g, a))
    end
    # Draws Bar
    for i in 1..( (min.to_f / max.to_f) * width - 1)
      for j in 1..(height - 1)
        r = bar_color.red * (width - i) / width + end_color.red * i / width
        g = bar_color.green * (width - i) / width + end_color.green * i / width
        b = bar_color.blue * (width - i) / width + end_color.blue * i / width
        a = bar_color.alpha * (width - i) / width + end_color.alpha * i / width
        self.contents.fill_rect(x + i + j, y + height - j, 1, 1, Color.new(r, g, b, a))
      end
    end
  end
  
  #==========================================================================
  # * Draw HP
  #     actor : actor
  #     x     : draw spot x-coordinate
  #     y     : draw spot y-coordinate
  #     width : draw spot width
  #==========================================================================
  alias :draw_actor_hp_hpsp :draw_actor_hp
  def draw_actor_hp(actor, x, y, width = 144)   
    draw_slant_bar(x, y + 12, actor.hp, actor.maxhp, width, 6, 
      bar_color = Color.new(150, 0, 0, 255), 
      end_color = Color.new(255, 255, 60, 255))
    draw_actor_hp_hpsp(actor, x, y, width)
   end
  #==========================================================================
  # * Draw SP
  #     actor : actor
  #     x     : draw spot x-coordinate
  #     y     : draw spot y-coordinate
  #     width : draw spot width
  #==========================================================================
  alias :draw_actor_sp_hpsp :draw_actor_sp
  def draw_actor_sp(actor, x, y, width = 144)
    draw_slant_bar(x, y + 12, actor.sp, actor.maxsp, width, 6,
      bar_color = Color.new(0, 0, 155, 255), 
      end_color = Color.new(255, 255, 255, 255))
    draw_actor_sp_hpsp(actor, x, y, width)
  end
  #==========================================================================
  # * Draw EXP
  #     actor : actor
  #     x     : draw spot x-coordinate
  #     y     : draw spot y-coordinate
  #==========================================================================
  alias raz_bars_base_exp draw_actor_exp  
  def draw_actor_exp(actor, x, y)
    if actor.level == 99
      draw_slant_bar(x, y + 18, 1, 1, 190, 6, bar_color = Color.new(0, 100, 0, 255), end_color = Color.new(0, 255, 0, 255))
    else
      draw_slant_bar(x, y + 18, actor.now_exp, actor.next_exp, 190, 6, bar_color = Color.new(0, 100, 0, 255), end_color = Color.new(255, 255, 255, 255))
    end
    raz_bars_base_exp(actor, x, y)
  end
  #==========================================================================
  # * Draw Parameter
  #     actor : actor
  #     x     : draw spot x-coordinate
  #     y     : draw spot y-coordinate
  #     type  : parameter type (0-6)
  #==========================================================================
  alias raz_bars_base_parameter draw_actor_parameter  
  def draw_actor_parameter(actor, x, y, type)
    case type
    when 0
      para_color1 = Color.new(100,0,0)
      para_color2 = Color.new(255,0,0)
      para_begin = actor.atk
    when 1
      para_color1 = Color.new(100,100,0)
      para_color2 = Color.new(255,255,0)
      para_begin = actor.pdef
    when 2
      para_color1 = Color.new(100,0,100)
      para_color2 = Color.new(255,0,255)
      para_begin = actor.mdef
    when 3
      para_color1 = Color.new(50,0,100)
      para_color2 = Color.new(50,0,255)
      para_begin = actor.str
    when 4
      para_color1 = Color.new(0,100,0)
      para_color2 = Color.new(0,255,0)
      para_begin = actor.dex
    when 5
      para_color1 = Color.new(50,0,50)
      para_color2 = Color.new(255,0,255)
      para_begin = actor.agi
    when 6
      para_color1 = Color.new(0,100,100)
      para_color2 = Color.new(0,255,255)
      para_begin = actor.int
    end
    draw_slant_bar(x, y + 18, para_begin, 999, 155, 4, bar_color = para_color1,
      end_color = para_color2)
    raz_bars_base_parameter(actor, x, y, type)
  end
  #=========================================================================
  # * Draw Actor ATG
  #     actor : Actor
  #     x     : draw spot x-coordinate
  #     y     : draw spot y-coordinate
  #     width : draw spot width
  #=========================================================================
  def draw_actor_atg(actor, x, y, width = 144, height = 6)
    if @at_gauge == nil
      # plus_x:     revised x-coordinate
      # rate_x:     revised X-coordinate as (%)
      # plus_y:     revised y-coordinate
      # plus_width: revised width
      # rate_width: revised width as (%)
      # height:     Vertical width
      # align1: Type 1 ( 0: left justify  1: center justify 2: right justify )
      # align2: Type 2 ( 0: Upper stuffing 1: Central arranging  2:Lower stuffing )
      # align3: Gauge type 0:Left justify 1: Right justify
      @plus_x = 0
      @rate_x = 0
      @plus_y = 16
      @plus_width = 0
      @rate_width = 100
      @width = @plus_width + width * @rate_width / 100
      @height = 6
      @align1 = 0
      @align2 = 1
      @align3 = 0
      # Gradation settings:  grade1: Empty gauge   grade2:Actual gauge
      # (0:On side gradation   1:Vertically gradation    2: Slantedly gradation)
      grade1 = 1
      grade2 = 0
      # Color setting. color1: Outermost framework, color2: Medium framework
      # color3: Empty framework dark color, color4: Empty framework light/write color
      color1 = Color.new(0, 0, 0)
      color2 = Color.new(255, 255, 192)
      color3 = Color.new(0, 0, 0, 192)
      color4 = Color.new(0, 0, 64, 192)
      # Color setting of gauge
      # Usually color setting of the time
      color5 = Color.new(0, 64, 80)
      color6 = Color.new(255, 255, 255)#(0, 128, 160)
      # When gauge is MAX, color setting
      color7 = Color.new(80, 0, 0)
      color8 = Color.new(255, 255,255) #(240,0,0)
      # Color setting at time of cooperation skill use
      color9 = Color.new(80, 64, 32)
      color10 = Color.new(255, 255, 255) #(240, 192, 96)
      # Color setting at time of skill permanent residence
      color11 = Color.new(80, 0, 64)
      color12 = Color.new(255,255, 255) #(240, 0, 192)
      # Drawing of gauge
      gauge_rect_at(@width, @height, @align3, color1, color2, color3, color4,
          color5, color6, color7, color8, color9, color10, color11, color12,
          grade1, grade2)
    end
    # Variable at substituting the width of the gauge which is drawn
    if actor.rtp == 0
      at = (width + @plus_width) * actor.atp * @rate_width / 10000
    else
      at = (width + @plus_width) * actor.rt * @rate_width / actor.rtp / 100
    end
    # AT Width Check
    if at > width
      at = width
    end
    # Revision such as the left stuffing central posture of gauge
    case @align1
    when 1
      x += (@rect_width - width) / 2
    when 2
      x += @rect_width - width
    end
    case @align2
    when 1
      y -= @height / 2
    when 2
      y -= @height
    end
    # Draw Border
    for i in 0..height
      self.contents.fill_rect(x + 1.5 + i, y + 12 + height - i, width - 2 , 3,
        Color.new(50, 50, 50, 255))
    end
    # Draw Background
    for i in 1..(height - 1)
      r = 100 * (height - i) / height + 0 * i / height
      g = 100 * (height - i) / height + 0 * i / height
      b = 100 * (height - i) / height + 0 * i / height
      a = 255 * (height - i) / height + 255 * i / height
      self.contents.fill_rect(x + 1.5 + i, y + 12 + height - i, width - 3, 3, 
        Color.new(r, b, g, a))
    end
    # Rect_X control
    if @align3 == 0
      rect_x = 0
    else
      x += @width - at - 1
      rect_x = @width - at - 1
    end

    # Color setting of gauge
    if at == width 
    #Gauge drawing at the time of MAX
      for i in 0..height
        self.contents.blt(x + i + @plus_x + @width * @rate_x / 100, y -i + 
        @plus_y, @at_gauge, Rect.new(rect_x, @height * 2, at, @height))
      end
    else
      if actor.rtp == 0
        for i in 0..height
          # Usually gauge drawing of the time
          self.contents.blt(x + i + @plus_x + @width * @rate_x / 100, y- i + 
            @plus_y, @at_gauge,Rect.new(rect_x, @height, at, @height))
        end
      else
        if actor.spell == true
          for i in 0..height
            #Gauge drawing at time of cooperation skill use
            self.contents.blt(x + i + @plus_x + @width * @rate_x / 100, y - i + 
              @plus_y, @at_gauge, Rect.new(rect_x, @height * 3, at, @height))
          end
        else
          for i in 0..height              
            # Gauge drawing at time of skill permanent residence
            self.contents.blt(x + i + @plus_x + @width * @rate_x / 100, y - i +
              @plus_y, @at_gauge, Rect.new(rect_x, @height * 4, at, @height))
          end
        end
      end
    end
  end
  #=========================================================================
  # * Draw Actor Limit Break Bar
  #     actor : Actor
  #     x     : draw spot x-coordinate
  #     y     : draw spot y-coordinate
  #     width : draw spot width
  #=========================================================================
  def draw_actor_lb(actor, x, y, width = 144)
    rate = actor.limitbreak.to_f / LB_MAX
    plus_x = 0
    rate_x = 0
    plus_y = 15
    plus_width = 0
    rate_width = 100
    height = 7
    lb = (width + plus_width) * actor.limitbreak * rate_width / 100 / LB_MAX
    # Drawing of gauge
    if actor.limitbreak == LB_MAX
      # Draw Silver Blue Bar
      draw_slant_bar(x + plus_x + width * rate_x / 100, y + plus_y, lb, width,
        width, height, od_color1 = Color.new(0,80,200,192), 
        od_color2 = Color.new(255,255,255,192))
    else
      # Draw Green Bar
      draw_slant_bar(x + plus_x + width * rate_x / 100, y + plus_y, lb, width,
        width, height, od_color1 = Color.new(31, 128, 0, 128), 
        od_color2 = Color.new(255, 255, 191))
    end
  end  
end

(note** this is not mine it was in the RTAB script I downloaded [ http://www.rmxp.org/forums/index.php?topic=4919.0 ])
 

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