From a39cb610fcbbbef8eef072f777766f5adc2894d9 Mon Sep 17 00:00:00 2001
From: Mario <mario@smbclan.net>
Date: Mon, 12 Aug 2019 19:43:29 +1000
Subject: [PATCH] If an item has a valid target, use it on touch (defrag
 support)

---
 qcsrc/common/t_items.qc | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/qcsrc/common/t_items.qc b/qcsrc/common/t_items.qc
index 466b38311..a6b3f45ce 100644
--- a/qcsrc/common/t_items.qc
+++ b/qcsrc/common/t_items.qc
@@ -927,6 +927,9 @@ void Item_Touch(entity this, entity toucher)
 
 LABEL(pickup)
 
+	if(this.target && this.target != "" && this.target != "###item###") // defrag support
+		SUB_UseTargets(this, toucher, NULL);
+
 	STAT(LAST_PICKUP, toucher) = time;
 
 	Send_Effect(EFFECT_ITEM_PICKUP, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
@@ -1314,7 +1317,11 @@ void _StartItem(entity this, entity def, float defaultrespawntime, float default
 			|| (def.instanceOfHealth && def != ITEM_HealthSmall)
 			|| (def.instanceOfArmor && def != ITEM_ArmorSmall)
 			|| (itemid & (IT_KEY1 | IT_KEY2))
-		) this.target = "###item###"; // for finding the nearest item using findnearest
+		) 
+		{
+			if(!this.target || this.target == "")
+				this.target = "###item###"; // for finding the nearest item using findnearest
+		}
 
 		Item_ItemsTime_SetTime(this, 0);
 	}
-- 
2.39.5