entWatch4: Rework registering, aka make it actually work.
And change some other small stuff.
This commit is contained in:
		
							parent
							
								
									9f3e89514d
								
							
						
					
					
						commit
						2912450e40
					
				| @ -210,29 +210,24 @@ public void OnEntitySpawned(int entity) | ||||
| { | ||||
| 	if (Entity_IsValid(entity) && g_hArray_Configs.Length) | ||||
| 	{ | ||||
| 		for (int index; index < g_hArray_Items.Length; index++) | ||||
| 		{ | ||||
| 			CItem item = g_hArray_Items.Get(index); | ||||
| 
 | ||||
| 			CConfig config = item.dConfig; | ||||
| 
 | ||||
| 			if (RegisterItem(item, config, entity)) | ||||
| 			{ | ||||
| 				g_hArray_Items.Set(index, item); | ||||
| 				return; | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		for (int index; index < g_hArray_Configs.Length; index++) | ||||
| 		{ | ||||
| 			CItem item = new CItem(g_hArray_Configs.Get(index)); | ||||
| 			CConfig config = g_hArray_Configs.Get(index); | ||||
| 
 | ||||
| 			CConfig config = item.dConfig; | ||||
| 
 | ||||
| 			if (RegisterItem(item, config, entity)) | ||||
| 			if (config.iWeaponID && config.iWeaponID == Entity_GetHammerId(entity)) | ||||
| 			{ | ||||
| 				g_hArray_Items.Push(item); | ||||
| 				return; | ||||
| 				if (PerformRegisterItem(config, entity, 1)) | ||||
| 					return; | ||||
| 			} | ||||
| 			else if (config.iButtonID && config.iButtonID == Entity_GetHammerId(entity)) | ||||
| 			{ | ||||
| 				if (PerformRegisterItem(config, entity, 2)) | ||||
| 					return; | ||||
| 			} | ||||
| 			else if (config.iTriggerID && config.iTriggerID == Entity_GetHammerId(entity)) | ||||
| 			{ | ||||
| 				if (PerformRegisterItem(config, entity, 3)) | ||||
| 					return; | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| @ -241,41 +236,95 @@ public void OnEntitySpawned(int entity) | ||||
| //---------------------------------------------------------------------------------------------------- | ||||
| // Purpose: | ||||
| //---------------------------------------------------------------------------------------------------- | ||||
| stock bool RegisterItem(CItem item, CConfig config, int entity) | ||||
| stock bool PerformRegisterItem(CConfig config, int entity, int type) | ||||
| { | ||||
| 	bool bSuccessful; | ||||
| 
 | ||||
| 	if (Entity_IsValid(entity)) | ||||
| 	{ | ||||
| 		if (config.iWeaponID && config.iWeaponID == Entity_GetHammerId(entity)) | ||||
| 		if (g_hArray_Items.Length) | ||||
| 		{ | ||||
| 			if (!item.bWeapon && (Entity_GetOwner(entity) == INVALID_ENT_REFERENCE)) | ||||
| 			for (int index; index < g_hArray_Items.Length; index++) | ||||
| 			{ | ||||
| 				item.iWeapon = entity; | ||||
| 				return true; | ||||
| 				CItem item = g_hArray_Items.Get(index); | ||||
| 
 | ||||
| 				if (AttemptRegisterItem(item, entity, type)) | ||||
| 				{ | ||||
| 					g_hArray_Items.Set(index, item); | ||||
| 					bSuccessful = true; | ||||
| 					break; | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 		else if (config.iButtonID && config.iButtonID == Entity_GetHammerId(entity)) | ||||
| 		{ | ||||
| 			if (!item.bButton && (Entity_GetParent(entity) == INVALID_ENT_REFERENCE || (item.bWeapon && Entity_GetParent(entity) == item.iWeapon))) | ||||
| 			{ | ||||
| 				SDKHook(entity, SDKHook_Use, OnButtonPress); | ||||
| 
 | ||||
| 				item.iButton = entity; | ||||
| 				return true; | ||||
| 		if (!bSuccessful) | ||||
| 		{ | ||||
| 			CItem item = new CItem(config); | ||||
| 
 | ||||
| 			if (AttemptRegisterItem(item, entity, type)) | ||||
| 			{ | ||||
| 				g_hArray_Items.Push(item); | ||||
| 				bSuccessful = true; | ||||
| 			} | ||||
| 		} | ||||
| 		else if (config.iTriggerID && config.iTriggerID == Entity_GetHammerId(entity)) | ||||
| 		{ | ||||
| 			if (!item.bTrigger && (Entity_GetParent(entity) == INVALID_ENT_REFERENCE ||	(item.bWeapon && Entity_GetParent(entity) == item.iWeapon))) | ||||
| 			else | ||||
| 			{ | ||||
| 				SDKHook(entity, SDKHook_StartTouch, OnTriggerTouch); | ||||
| 				SDKHook(entity, SDKHook_EndTouch, OnTriggerTouch); | ||||
| 				SDKHook(entity, SDKHook_Touch, OnTriggerTouch); | ||||
| 				LogError("Attempted to register new item, but failed! This should never happen."); | ||||
| 
 | ||||
| 				item.iTrigger = entity; | ||||
| 				return true; | ||||
| 				delete item; | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	return bSuccessful; | ||||
| } | ||||
| 
 | ||||
| //---------------------------------------------------------------------------------------------------- | ||||
| // Purpose: | ||||
| //---------------------------------------------------------------------------------------------------- | ||||
| stock bool AttemptRegisterItem(CItem item, int entity, int type) | ||||
| { | ||||
| 	if (Entity_IsValid(entity)) | ||||
| 	{ | ||||
| 		switch(type) | ||||
| 		{ | ||||
| 			case(1): | ||||
| 			{ | ||||
| 				if (!item.bWeapon && (Entity_GetOwner(entity) == INVALID_ENT_REFERENCE)) | ||||
| 				{ | ||||
| 					item.iWeapon = entity; | ||||
| 					return true; | ||||
| 				} | ||||
| 			} | ||||
| 			case(2): | ||||
| 			{ | ||||
| 				if (!item.bButton && (Entity_GetParent(entity) == INVALID_ENT_REFERENCE || (item.bWeapon && Entity_GetParent(entity) == item.iWeapon))) | ||||
| 				{ | ||||
| 					SDKHook(entity, SDKHook_Use, OnButtonPress); | ||||
| 
 | ||||
| 					item.iButton = entity; | ||||
| 					return true; | ||||
| 				} | ||||
| 			} | ||||
| 			case(3): | ||||
| 			{ | ||||
| 				if (!item.bTrigger && (Entity_GetParent(entity) == INVALID_ENT_REFERENCE ||	(item.bWeapon && Entity_GetParent(entity) == item.iWeapon))) | ||||
| 				{ | ||||
| 					SDKHook(entity, SDKHook_StartTouch, OnTriggerTouch); | ||||
| 					SDKHook(entity, SDKHook_EndTouch, OnTriggerTouch); | ||||
| 					SDKHook(entity, SDKHook_Touch, OnTriggerTouch); | ||||
| 
 | ||||
| 					item.iTrigger = entity; | ||||
| 					return true; | ||||
| 				} | ||||
| 			} | ||||
| 			default: | ||||
| 			{ | ||||
| 				LogError("Attempted to register item with invalid type: %d! This should never happen.", type); | ||||
| 				return false; | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	return false; | ||||
| } | ||||
| 
 | ||||
| @ -293,18 +342,18 @@ public void OnEntityDestroyed(int entity) | ||||
| 			if (item.bWeapon && item.iWeapon == entity) | ||||
| 			{ | ||||
| 				g_hArray_Items.Erase(index); | ||||
| 
 | ||||
| 				delete item; | ||||
| 				return; | ||||
| 			} | ||||
| 
 | ||||
| 			if (item.bButton && item.iButton == entity) | ||||
| 			else if (item.bButton && item.iButton == entity) | ||||
| 			{ | ||||
| 				item.iButton = INVALID_ENT_REFERENCE; | ||||
| 
 | ||||
| 				g_hArray_Items.Set(index, item); | ||||
| 				return; | ||||
| 			} | ||||
| 
 | ||||
| 			if (item.bTrigger && item.iTrigger == entity) | ||||
| 			else if (item.bTrigger && item.iTrigger == entity) | ||||
| 			{ | ||||
| 				item.iTrigger = INVALID_ENT_REFERENCE; | ||||
| 
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user