If I understand you correctly, you want to rewrite the code you provided in a way to randomly remove an item from the player's inventory when they are hit.? If so, then maybe something like the following code ?
// Event handler for when the player is hit on a specific body part
player addEventHandler ["HitPart", {
private ["_unit", "_shooter", "_bullet", "_pos", "_vel", "_hitLoc", "_item"];
// Assign parameters to variables in the Array
_unit = _this select 0;
_hitLoc = _this select 5;
// Check if the unit has any items in the inventory
if (count (items _unit) > 0) then {
// Select a random item from the inventory
_item = (items _unit) select (floor (random (count (items _unit))));
// Remove the selected item
_unit removeItem _item;
// Display a hint to inform the player about the lost item
hint format ["You lost %1", displayName _item];
};
}];
Keep in mind that I am a bit new to SQF Scripting, so you can try and test it to see if it works correctly. I hope that helps.