scoreboard objectives add ar23p_ammo dummy

scoreboard players add @s ar23p_ammo 1

execute @s[scores={ar23p_ammo=30},hasitem={item=hd:ar-23p,location=slot.weapon.mainhand}] ~~~ replaceitem entity @s slot.weapon.mainhand 0 hd:ar-23p_empty 1 0