RE Weapon System II: Modify Reloading

Otto

Veteran
Veteran
Joined
Apr 24, 2015
Messages
119
Reaction score
70
First Language
Engilsh
Primarily Uses
RM2k3
Hi again,
I hate to bug you guys with this stuff because i know it's a silly detail that I'm missing è_é

So basically I have this ABS scritp that has weapons (firearms) and item that works as ammunitions (example: weapon 1 requires item 5, and so on...). What it does is, when the weapon is empty, you hit S and the game consumes 1 ammunition items and reload the weapon to the max capacity. What I wanted instead is:
1 - Reload the gun at any time, even if you don't have 0 ammo;
2 - Treat every "ammuniton item" as a single bullet (meaning that, for example, if my gun holds up to 15 bullets and i currently have 11, the game - upon reloading - will remove 4 ammos from my inventory and reload my gun to 15;

The first issue was easy to solve, all I did was, change this:

Code:
if Input.trigger?(Reload_Key)
        if @equipped_weapon.bullets == 0
          reload(@equipped_weapon)
        else
          Audio.se_play("Audio/Se/Buzzer1", 80, 100)
        end
      end
into this:

Code:
if Input.trigger?(Reload_Key)
        reload(@equipped_weapon)
even tho, It just occurred me that I should put some "if" condition, in case the player hits the reload button wile the weapon is full... something along the line of:

Code:
if Input.trigger?(Reload_Key)
        if @equipped_weapon.bullets < @equipped_weapon.max
          reload(@equipped_weapon)
        else
          Audio.se_play("Audio/Se/Buzzer1", 80, 100)
        end
      end
would be correct?

Second issue is what's bugging me, as I had to write myself some way to calculate how many bullets it has to reload everytime,
so I went ahead and change this:

Code:
 def reload(weapon)
    $game_party.items.each { |item|
      if item.id == weapon.magazine.id
        $game_party.lose_item(weapon.magazine,1)
        @equipped_weapon.bullets += @equipped_weapon.max
        Audio.se_play("Audio/Se/#{weapon.wav_name}_reload", 100, 100)
        @recover = @equipped_weapon.recover
        return
      end
    }
    Audio.se_play("Audio/Se/Buzzer1", 85, 100)
    @recover = (@equipped_weapon.recover > 40 ? @equipped_weapon.recover : 45)
  end
into this:

Code:
 def reload(weapon)  #MODIFIED BY OTTO TO TREAT EACH "AMMO ITEM" AS A SINGLE BULLET
    $game_party.items.each { |item|
      if item.template_id == weapon.magazine.id
        ammo_id = weapon.magazine.id
        ammunition = $game_party.item(weapon.magazine.class)[ammo_id]
        max_ammo = @equipped_weapon.max
        current_ammo = @equipped_weapon.bullets
        ammo_reloaded = ( max_ammo - current_ammo > ammunition ? ammunition : max_ammo - current_ammo )
        $game_party.lose_item(weapon.magazine, ammo_reloaded)
        @equipped_weapon.bullets += ammo_reloaded
        Audio.se_play("Audio/Se/#{weapon.wav_name}_reload", 100, 100)
        @recover = @equipped_weapon.recover
        return
      end
    }
    Audio.se_play("Audio/Se/Buzzer1", 85, 100)
    @recover = (@equipped_weapon.recover > 40 ? @equipped_weapon.recover : 45)
  end
I'm sure I'm on the right path but I get a crash as soon as I reload, that seems to be tied to this strig here:
ammunition = $game_party.item(weapon.magazine.class)[ammo_id]

Any advice?
:)
 

Roninator2

Gamer
Veteran
Joined
May 22, 2016
Messages
2,674
Reaction score
566
First Language
English
Primarily Uses
RMVXA
Code:
 def reload(weapon)
    $game_party.items.each { |item|
      if item.id == weapon.magazine.id
        $game_party.lose_item(weapon.magazine,1)
        @equipped_weapon.bullets += @equipped_weapon.max
        Audio.se_play("Audio/Se/#{weapon.wav_name}_reload", 100, 100)
        @recover = @equipped_weapon.recover
        return
      end
    }
    Audio.se_play("Audio/Se/Buzzer1", 85, 100)
    @recover = (@equipped_weapon.recover > 40 ? @equipped_weapon.recover : 45)
  end
I would have maybe just put in one extra line
Code:
 def reload(weapon)
    $game_party.items.each { |item|
      if item.id == weapon.magazine.id
        $game_party.lose_item(weapon.magazine,1)
        ammo_reload = @equipped_weapon.max -= @equipped_weapon.bullets
        @equipped_weapon.bullets += ammo_reload
        Audio.se_play("Audio/Se/#{weapon.wav_name}_reload", 100, 100)
        @recover = @equipped_weapon.recover
        return
      end
    }
    Audio.se_play("Audio/Se/Buzzer1", 85, 100)
    @recover = (@equipped_weapon.recover > 40 ? @equipped_weapon.recover : 45)
  end
 

Otto

Veteran
Veteran
Joined
Apr 24, 2015
Messages
119
Reaction score
70
First Language
Engilsh
Primarily Uses
RM2k3
@Roninator2 that didn't solve the problem of 1 item = 1 bullet unfortunately :(

anyway, I did it at last, apparently I had to put
ammunition = $game_party.item_container(weapon.magazine.class)[ammo_id] in that line indicated by the crash error.
Still not sure what that means, but at least it works lol
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Day 9 of giveaways! 8 prizes today :D
He mad, but he cute :kaopride:

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.

Forum statistics

Threads
106,040
Messages
1,018,476
Members
137,824
Latest member
dobratemporal
Top