so there will be the function enemy...
when the health is =0, the function call another one, that will create an entity (weapon or health)
then that weapon has an function it self so when player touches it, it will be removed, and add the weapon to the player.
that more less how things are done generaly speaking. But i guess you can find some tutorials about that here.