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