try:
retrieve_item(2 - available_amount($item[bar whip]), $item[bar whip]);
in the off hand function
and:
retrieve_item(1 - available_amount($item[bar whip]), $item[bar whip]);
in the weapon section.
It looks like you are equipping it to weapon in the weapon function, then retrieving 2 which...