scoreboard objectives add ar23_ammo dummy

scoreboard players add @s ar23_ammo 1

execute @s[scores={ar23_ammo=45},hasitem={item=hd:ar-23,location=slot.weapon.mainhand}] ~~~ replaceitem entity @s slot.weapon.mainhand 0 hd:ar-23_empty 1 0