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.

Two Scripts: Weapon Hit% + Critical%

OK a few tips on getting better

1) do not post the whole class if someone where to add that it may overwrite another script, just include it as one script (single script) with only the methods you modify/alias

2) instead of this
Code:
  def base_hit
    ### PhotonWeapon Note:
    ### There's actually no base_hit by default; I added this myself.
    ### This script will give each hero their own hit% depending on
    ### the weapon they have equipped via case statement.
    ### First, we'll set default_hit_rate = whatever. This makes it so that
    ### the hero's default hit rate is always the value of default_hit_rate
    ### until they equip a certain weapon. This is so that you don't have
    ### to make a case statement for every single weapon in the game;
    ### just the ones you'd want to change the hit% for when equipped.
    ### NOTE: 90% is the default hit rate in RM2K/3; 100% is the default
    ### hit rate in RMXP. Up to you which one you choose.
    default_hit_rate = 90
    hit_rate = default_hit_rate
    case @weapon_id ### If equipped with certain weapon (by its ID# in Database)
    when 10 ### Bronze Axe
      hit_rate = 85
    when 11 ### Iron Axe
      hit_rate = 85
    when 12 ### Steel Axe
      hit_rate = 85
    when 13 ### Mythril Axe
      hit_rate = 85
    when 21 ### Bronze Gun
      hit_rate = 95
    when 22 ### Iron Gun
      hit_rate = 95
    when 23 ### Steel Gun
      hit_rate = 95
    when 24 ### Mythril Gun
      hit_rate = 95
    end
    ### PhotonWeapon Note:
    ### This checks to see if the hero has no weapon equipped.
    ### If the hero doesn't have any weapon equipped, their hit%
    ### becomes the default_hit_rate. Not that it would matter
    ### much, since they'll just deal 0 damage, unless
    ### you do something about the default Attack Power script.
    weapon = $data_weapons[@weapon_id]
    hit_rate = weapon != nil ? hit_rate : default_hit_rate
    return hit_rate
  end

Code:
  def base_hit
    case @weapon_id ### If equipped with certain weapon (by its ID# in Database)
    when 10 ### Bronze Axe
      hit_rate = 85
    when 11 ### Iron Axe
      hit_rate = 85
    when 12 ### Steel Axe
      hit_rate = 85
    when 13 ### Mythril Axe
      hit_rate = 85
    when 21 ### Bronze Gun
      hit_rate = 95
    when 22 ### Iron Gun
      hit_rate = 95
    when 23 ### Steel Gun
      hit_rate = 95
    when 24 ### Mythril Gun
      hit_rate = 95
    else ## The Default
      hit_rate = 90
    end
    return hit_rate
  end

Or Even Better
Code:
class Game_Actor
Weapon_Hit_Rates = {10 => 85, 11 => 85, 12 => 85, 13 => 85, 21 => 95, 22 => 95, 23 => 95, 24 => 95}
Weapon_Hit_Rates.default = 90
  def base_hit
    return Weapon_Hit_Rates[@weapon_id]
  end
end

But yeah my preference is with the hash setup rather than using a big long case statement but it is up to you

3)
Code:
        ### PhotonWeapon Note:
        ### I've editted the critical hit rate. Dexterity now = Critical Hit %.
        ### First, subtract Dex by 1; that way, if the attacker's
        ### Dex is 1, it becomes 0 (no chance of criticals).
        ### Of course, this means you need their Dex
        ### set to 2 to give them a 1% critical chance (2Dex - 1 = 1), and set
        ### to 101 to give them a 100% critical chance (101Dex - 1 = 100).
        ### After that, if their Dex is greater than or equal to 101,
        ### have it equal 100 (or 100%).
        attacker.dex - 1
        if attacker.dex >= 101
          attacker.dex = 100
                end

You didn't subtract dex by 1

Also it would have been better if you had created another stat for critical hit % and rate

but yeah the big problem is that you are posting whole classes instead of just methods you edited as most of the code you posted is unnecessary.

Also. your scripts do not conflict in any way with SDK. SDK overwrites Game_, Scene_, and Sprite_ classes and Game_Battler, and Game_Enemy were not split up. The only method that was split in Game_Actor was exp= so there aren't any problems.

overall, good job.
 
I'm liking the idea Photon Weapon, good work. Just one question about your hit% script, is the overall chance to hit the hit% - evasion% or is it the hit% - the default way of calculating a hit?
 
Trickster;256675 said:
OK a few tips on getting better

1) do not post the whole class if someone where to add that it may overwrite another script, just include it as one script (single script) with only the methods you modify/alias

*slaps forehead* D'oh. Yeah, that did cross my mind, actually...

2) instead of this

<snip, snip and snip, don't wanna make the quote too long now>

But yeah my preference is with the hash setup rather than using a big long case statement but it is up to you

The hash setup is interesting. It does make the code a lot shorter/neater-looking. I think the case statement would be a little easier on me, though, because then I can fit in a comment on the name of the weapon beside their ID.

Question: Is it possible, instead of making separate case statements for weapons 10, 11, 12, and 13 to get 85% accuracy, I could do something like 10-13 in one case statement?

3)

You didn't subtract dex by 1

Really? I thought it would. Well, there has to be some way to get their critical chance to 0 if they have 1 Dex. Like, if you don't want someone to do critical hits at all.

Also it would have been better if you had created another stat for critical hit % and rate

Yeah. Leaving Dex alone would allow the default second-hit detection and dex_f to remain as they are. I used Dex because, well it's already there, plus it's easier (on me) to set the critical hit rates... i.e. giving a weapon 10 Dex = 10% extra criticals, etc.

I don't know how to do this with an entirely new stat, though. Arc had something going, though.

but yeah the big problem is that you are posting whole classes instead of just methods you edited as most of the code you posted is unnecessary.

Yeah. I'm still learning. ^_^ I think I'm getting a little better. I doubt I'd reach the level of creating loopable maps (world maps) or vehicles or other things I miss in RM2K/3 anytime soon, but it's a start I think.

I'll keep my post as it is for now, so I can see what I did wrong when I look back here.

Also. your scripts do not conflict in any way with SDK. SDK overwrites Game_, Scene_, and Sprite_ classes and Game_Battler, and Game_Enemy were not split up. The only method that was split in Game_Actor was exp= so there aren't any problems.

Ah, okay. I was just making sure.

overall, good job.

Yay, I got a "good job" from the Trickster! ^_^


The Wizard;256691 said:
I'm liking the idea Photon Weapon, good work. Just one question about your hit% script, is the overall chance to hit the hit% - evasion% or is it the hit% - the default way of calculating a hit?

The second one. The only thing I changed about it is that the attacker's Agi, not Dex, is used this time.


I'll probably edit my post and scripts later -- gotta get to college.
 
Sorry for Necro Post but i would need this Script in a final, easy 2 paste version ^^. Would be nice if someone could help :))
 
I have a question how to setup critical hit like the maximum hit is 9999 instead of Unlimited?
It preety easy to play if the maximum hit is unlimited.please tell me how i'm making a game and it really easy to kill monster
 

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