- 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:
into this:
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:
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:
into this:
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?

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
Code:
if Input.trigger?(Reload_Key)
reload(@equipped_weapon)
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
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
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
ammunition = $game_party.item(weapon.magazine.class)[ammo_id]
Any advice?
