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.

Weapon based accuracy

I'm trying to make the actor's hit rate dependent on both the actor's Int level and the equipped weapon. I haven't figured out a good algorithm yet, but I've made this block of code so far (in Game_Battler):

Code:
  #--------------------------------------------------------------------------

  # * Get Hit Rate

  #--------------------------------------------------------------------------

  def hit

    n = (int + 85) / 2

    case $data_weapons[@actor.weapon_id]

    when 1

      n = (int + 95) / 2

    when 2

      n = (int + 95) / 2

    when 3

      n = (int + 95) / 2

    when 11

      n = (int + 75) / 2

    end

    for i in @states

      n *= $data_states[i].hit_rate / 100.0

    end

    return Integer(n)

  end

 

The problem is that I get an 'undefined method' error pointing to 'weapon_id'. Any help would be greatly appreciated!
 
Ok, I think this topic is resolved now.

A suggestion: If someone has the talent, the time and the energy, a distributable & streamlined script for weapon based accuracy would be a cool addition to XP/VX. It was an integrated feature in 2000/2003 and I think the fact that it is not included in later versions is a big disapointment.
 

Zeriab

Sponsor

Note that $data_weapons[@weapon_id].id can give you an error if the actor has no weapon equipped.
In that case you have $data_weapons[@weapon_id] == nil
nil.id gives you an error
 
just do this:

[rgss] 
 
class NilClass
  def id
    return 1
  end
end
 
 
[/rgss]

You can use $data_weapons[@weapon_id] == nil,
but this works for armors, actors, and stuff without
the '== nil'.
 

Zeriab

Sponsor

I forgot that .id is a method in the Object class, so nil.id should not give an error, but instead a number. I dunno which.
My point with checking for nil still stands and I strongly advice against doing what Near's suggesting. Especially now that you know will overwrite an already existing function.
But even if that weren't the case adding properties to the NilClass like that is just horrible and it is something which can come back and bite you.

*hugs*
 
Having no weapon equipped has not caused any errors for me yet. Atleast in my menu system it shows this value when the actor is unarmed:
Code:
def hit

    [color=#FF0000]n = (int + 85) / 2[/color]

    case ...

I haven't been able to test the code in battle yet, though. I'm using GubiD's TBS, and I haven't been able to get it working properly. Anyways, after I make a topic of my game in the project discussion I may upload some kind f a demo and someone more advanced in RGSS might be able to take a look at my mess of scripts... :barf:
 

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