Chaos Project

RPG Maker => RPG Maker Scripts => Script Requests => Topic started by: Shining Riku on April 27, 2009, 08:22:38 pm

Title: Class based Critical Hit adjustment
Post by: Shining Riku on April 27, 2009, 08:22:38 pm
Ok...I'm not good at making scripts by myself but I understand them enough to use them.

Now, on to the topic.

Script Title:
Perhaps "Critical Hit modifier"?

RMXP or RMVX:
Definitely RMXP.

Detailed Description:
Nothing to it. Based on an actor's class, they would either gain a boost in ability to land critical hits or be less likely. I don't know much about critical hits, but is it based on percentages? Oh well, anything is fine.

Not so sure how such a thing would be set up, so I honestly can't say whether it'd be easy or not. It would add a strategic element to a Class Change system. I'd love it if somebody could write one up sometime but I understand if it's too difficult or messy to attempt.

Thanks for taking the time to read this!
Title: Re: Class based Critical Hit adjustment
Post by: Jackolas on April 27, 2009, 08:56:15 pm
the whole dmg calculations etc is in the script called: Game_Battler 3
on line 58 till 60 is described how crits work
        if rand(100) < 4 * attacker.dex / self.agi
          self.damage *= 2
          self.critical = true

Attacker.dex = the dexterity of the attacker
Self.Agi = the agility of the defender.

so if the attacker has 50 dex and the defender has 50 agy you get:

(4 x 50) / 50 = 4% if I'm correct
so the most logical way to improve a crit rating of a class is to improve his Dex

*this is how i read this little bid of code. can be wrong.
Title: Re: Class based Critical Hit adjustment
Post by: Shining Riku on April 27, 2009, 09:03:59 pm
So....Would there be a way for me to insert some If-then statements that would affect different classes?

I dunno if it's just me, but that looks like the base formula used to determine critical hits.

I'm not complaining or anything. I appreciate you pointing that out. I just don't know how i'd apply that knowledge.

Hmm...I'll look into some scripts and start thinking things out. Maybe I'll become a scripter after this. Who knows. If I figure out class related stuff......we'll just see.

:wacko:
EDIT:
It wouldn't be smart for me to edit a script like that, i'd probably break something. I'm thinking more along the lines of a plug-in. So begins my journey into scripting?...Maybe?

'NOTHER Edit: Dex increases accuracy too, doesn't it? I was wanting to increase crit without increasing accuracy. I think that's how it goes, right?
Title: Re: Class based Critical Hit adjustment
Post by: Jackolas on April 27, 2009, 09:05:29 pm
I also tried to search for the class of the actor to apply different dmg calculations. but failed.
somehow I could not find a way to check for a class :S

atm I use this as a plugin(warning this is adjusted for my purpose)
Spoiler: ShowHide
# Custom Damage Script
#   Edited By: Jackolas
#   Last updated: 28-03-09
#==============================================================================
#==============================================================================
#  Instructions:
#  -Place this script above Main and all costume scripts,
#   but below all other default scripts.
#==============================================================================

#==============================================================================
# Custom damage script
#------------------------------------------------------------------------------
#
#==============================================================================

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
      case attacker.weapon_id
      when 17,18,19,20,21,22,23,24 #range attack
        atk = [((attacker.atk + attacker.agi) * (100 - self.pdef/10))/100, 0].max
      when 29,30,31,32 #caster attack
        atk = [((attacker.atk) * (100 - self.pdef/10))/100, 0].max
      else
        if attacker.atk < 10  # unarmed attack
          atk = [((attacker.atk + (attacker.str/10)) * (100 - self.pdef/10))/100, 0].max
        else  #normal attack
          atk = [((attacker.atk + attacker.str) * (100 - self.pdef/10))/100, 0].max
        end 
      end
      self.damage = atk
      # 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
  #--------------------------------------------------------------------------
  # * 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
    # First hit detection
    hit = skill.hit
    if skill.atk_f > 0
      hit *= user.hit / 100
    end
    hit_result = (rand(100) < hit)
    # Set effective flag if skill is uncertain
    effective |= hit < 100
    # If hit occurs
    if hit_result == true
      # Calculate power
      power = skill.power + user.atk * skill.atk_f / 100
      if power > 0
        power -= self.pdef * skill.pdef_f / 200
        power -= self.mdef * skill.mdef_f / 200
        power = [power, 0].max
      end
      # Calculate rate
      rate = 20
      rate += (user.str * skill.str_f / 100)
      rate += (user.dex * skill.dex_f / 100)
      rate += (user.agi * skill.agi_f / 100)
      rate += (user.int * skill.int_f / 100)
      # Calculate basic damage
      self.damage = power * rate / 20
      # 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
      # Dispersion
      if skill.variance > 0 and self.damage.abs > 0
        amp = [self.damage.abs * skill.variance / 100, 1].max
        self.damage += rand(amp+1) + rand(amp+1) - amp
      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
        # 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
  #--------------------------------------------------------------------------
  # * Application of Item Effects
  #     item : item
  #--------------------------------------------------------------------------
  def item_effect(item)
    # Clear critical flag
    self.critical = false
    # If item scope is for ally with 1 or more HP, and your own HP = 0,
    # or item scope is for ally with 0 HP, and your own HP = 1 or more
    if ((item.scope == 3 or item.scope == 4) and self.hp == 0) or
       ((item.scope == 5 or item.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 |= item.common_event_id > 0
    # Determine hit
    hit_result = (rand(100) < item.hit)
    # Set effective flag is skill is uncertain
    effective |= item.hit < 100
    # If hit occurs
    if hit_result == true
      # Calculate amount of recovery
      recover_hp = maxhp * item.recover_hp_rate / 100 + item.recover_hp
      recover_sp = maxsp * item.recover_sp_rate / 100 + item.recover_sp
      if recover_hp < 0
        recover_hp += self.pdef * item.pdef_f / 20
        recover_hp += self.mdef * item.mdef_f / 20
        recover_hp = [recover_hp, 0].min
      end
      # Element correction
      recover_hp *= elements_correct(item.element_set)
      recover_hp /= 100
      recover_sp *= elements_correct(item.element_set)
      recover_sp /= 100
      # Dispersion
      if item.variance > 0 and recover_hp.abs > 0
        amp = [recover_hp.abs * item.variance / 100, 1].max
        recover_hp += rand(amp+1) + rand(amp+1) - amp
      end
      if item.variance > 0 and recover_sp.abs > 0
        amp = [recover_sp.abs * item.variance / 100, 1].max
        recover_sp += rand(amp+1) + rand(amp+1) - amp
      end
      # If recovery code is negative
      if recover_hp < 0
        # Guard correction
        if self.guarding?
          recover_hp /= 2
        end
      end
      # Set damage value and reverse HP recovery amount
      self.damage = -recover_hp
      # HP and SP recovery
      last_hp = self.hp
      last_sp = self.sp
      self.hp += recover_hp
      self.sp += recover_sp
      effective |= self.hp != last_hp
      effective |= self.sp != last_sp
      # State change
      @state_changed = false
      effective |= states_plus(item.plus_state_set)
      effective |= states_minus(item.minus_state_set)
      # If parameter value increase is effective
      if item.parameter_type > 0 and item.parameter_points != 0
        # Branch by parameter
        case item.parameter_type
        when 1  # Max HP
          @maxhp_plus += item.parameter_points
        when 2  # Max SP
          @maxsp_plus += item.parameter_points
        when 3  # Strength
          @str_plus += item.parameter_points
        when 4  # Dexterity
          @dex_plus += item.parameter_points
        when 5  # Agility
          @agi_plus += item.parameter_points
        when 6  # Intelligence
          @int_plus += item.parameter_points
        end
        # Set to effective flag
        effective = true
      end
      # If HP recovery rate and recovery amount are 0
      if item.recover_hp_rate == 0 and item.recover_hp == 0
        # Set damage to empty string
        self.damage = ""
        # If SP recovery rate / recovery amount are 0, and parameter increase
        # value is ineffective.
        if item.recover_sp_rate == 0 and item.recover_sp == 0 and
           (item.parameter_type == 0 or item.parameter_points == 0)
          # If state is unchanged
          unless @state_changed
            # Set damage to "Miss"
            self.damage = "Miss"
          end
        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
Title: Re: Class based Critical Hit adjustment
Post by: fugibo on April 27, 2009, 09:07:54 pm

actor.class_id
$game_party[<place>].class_id
$game_actors[<id>].class_id


I think.

EDIT:

Oh, and I doubt it would be very easy to make a plug-and-play script for this. The DBS has next to no modularity.

EDIT2:

This would work well for the intended purpose:

critical = case self.class_id
#EDIT THIS PART
when <your_id> then <your_percent_in_integer_form>
when <your_next_id> then <your_next_percent>
#END EDITING
end
if rand(100) < critical
            self.damage *= 2
            self.critical = true


Try that.
Also, I might just write a script for more effects like this.
Title: Re: Class based Critical Hit adjustment
Post by: Jackolas on April 27, 2009, 09:09:24 pm
Quote
actor.class_id
$game_party[<place>].class_id
$game_actors[<id>].class_id


every time i use that code i get an error that he do's not know class.id ore class_id
but it can be that i just use it wrong
Title: Re: Class based Critical Hit adjustment
Post by: Shining Riku on April 27, 2009, 09:13:56 pm
DBS? It makes sense that it wouldn't be too modifiable (Yay, new word?)

It'd be like taking a cornerstone out from underneath a building I guess.

I appreciate the trouble you guys went through to tell me this stuff. I honestly can't claim to know much about scripts, but everything you've told me makes sense.

Maybe I made a hard request. PROBABLY did. Most likely did. Thanks for your time, Jackolas and WcW. I gotta start somewhere if i'm gonna learn anything about scripting, lol.
Title: Re: Class based Critical Hit adjustment
Post by: fugibo on April 27, 2009, 09:15:28 pm
Try this

if $game_party.actors[0].kind_of?(Game_Actor)
 begin
   print "Class: ", $game_party.actors[0].class_id
 rescue
   print "Yeah, I was wrong :/"
 end
else
 print "Hehe. Game_Party doesn't contain Actors directly, apparently."
end


And tell me what the output is.
Title: Re: Class based Critical Hit adjustment
Post by: Shining Riku on April 27, 2009, 09:17:19 pm
Where would I stick that again?  :P
Title: Re: Class based Critical Hit adjustment
Post by: fugibo on April 27, 2009, 09:17:56 pm
An event.
Title: Re: Class based Critical Hit adjustment
Post by: Jackolas on April 27, 2009, 09:19:46 pm
NoMethodError occurred while running script.
undefined method '[] for #<Game_Party:0x3d0b7f8>
Title: Re: Class based Critical Hit adjustment
Post by: fugibo on April 27, 2009, 09:20:26 pm
Repaste the script, I made an oopsie while you were copying
Title: Re: Class based Critical Hit adjustment
Post by: Jackolas on April 27, 2009, 09:25:57 pm
can't get it into an event.. its to big (ore there is a way i dunno)
Title: Re: Class based Critical Hit adjustment
Post by: fugibo on April 27, 2009, 09:26:54 pm
AAAAAAAAAGGGGGGGGHHHHHHHHHH

Stick it into the initialize method of Scene_Menu, right after

@index = index


And open the menu X|
Title: Re: Class based Critical Hit adjustment
Post by: Jackolas on April 27, 2009, 09:30:26 pm
its below     @menu_index = menu_index

did it.. got return Class: 1

guess you fixed a lot of problems for me :P
can't wait to use this for real :P
(power up)
Title: Re: Class based Critical Hit adjustment
Post by: fugibo on April 27, 2009, 09:33:39 pm
So, I gots it figured out. Proper method:

$game_party.actors[<actor_id>].class_id


My code above should work if you fix that bit.
I have a script for this around 7 posts up, second edit.
Title: Re: Class based Critical Hit adjustment
Post by: Jackolas on April 28, 2009, 07:56:03 am
so many thanks WcW. it works like a dream. it also fixed my problem with the skill shop I use (topic: http://forum.chaos-project.com/index.php?topic=3398.msg67268#msg67268 )
I can't thank you enough for this :P