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.

[VX] Critical Strike Chance

I'm not sure if this is the right board to ask on, (please move this thread if it is the wrong board) but is there a way to control critical strike chance outside of scripting? The Help manual in RMVX says that all actors have a default 4% chance, an additional 4% if the weapon or the actor is noted as having a critical bonus. If I wanted to change these values/make a way for them to increase independent of these fixed settings, how would I go about doing it?

On the same note, would it be possible for a skill to add critical strike rating as a buff? ie. Focus Energy in Pokemon.
 

poccil

Sponsor

The critical hit chance is found in the cri method of Game_Actor and Game_Enemy
The rate can't be changed "outside of scripting", especially since you mentioned all the ways that the critical hit rate can increase normally.

The following script is an example of modifying the critical hit ratio for actors, in this case changing the rate to 8 percent. 

In addition, it adds a critical hit bonus if the actor has a state whose note includes [CriticalBonus: X] where X is the critical hit rate bonus.

Put the script after all other scripts in the Materials section of the script editor.

Code:
# Helper function to parse the state notes from the database
def parseStateNotes(tag)
 ret={}
 rgex=/\[#{tag}\:\s*(\d+)\]/i
 for skill in $data_states.compact
  skill.note.gsub!(rgex){|o|
   ret[skill.id]=$1.to_i
  }
 end
 return ret
end
class Game_Actor
attr_writer :critical_plus
def critical_plus
  @critical_plus=0 if !@critical_plus
  return @critical_plus
end
 @@_CriticalBonus=nil
 def cri
   if !@@_CriticalBonus
    @@_CriticalBonus=parseStateNotes("CriticalBonus")
   end
    n = 8
    n += 8 if actor.critical_bonus
    for weapon in weapons.compact
      n += 8 if weapon.critical_bonus
    end
    for state in states.compact
      bonus=@@_CriticalBonus[state.id]
      n += bonus if bonus
    end
    n+=@critical_plus if @critical_plus
    return n
 end
end
 
Sorry to doublepost, but I ran across an issue.

I'm trying to assign individual critical strike rates for certain actors, but I'm not quite sure what to do. I took the above script and tried to add little snippets around the def cri like:

if actor_id = 1
  then n = 5

But unfortunately, my syntax is wrong, and I have no idea if that's remotely close to correct.

Also, I was also wondering how I would go about altering this base number via script, aka increasing critical strike rating by 1 with an item or an event, etc.
 
Alright, that worked, thanks poccil.

How would I go about changing the value in this script from an event was my other question, though. Essentially what I want to do is make an event that increases critical strike by one permanently.
 

poccil

Sponsor

I modified the script above to deal with that.  Then, in an event, use a Script event command like the following:
Code:
$game_actors[X].critical_plus+=1
where X is the actor's ID.
 
Hmm...I plugged in the new script, but this time I'm getting a nomethod error on line 13 regarding 'attr_writer'

Nevermind, I fixed it by adding a class thingy around it as such:

Code:
class Game_Actor
attr_writer :critical_plus
def critical_plus
  @critical_plus=0 if !@critical_plus
  return @critical_plus
end
end
 

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