entWatch4: Tweak registering, and formatting.
This commit is contained in:
		
							parent
							
								
									46beb23bc3
								
							
						
					
					
						commit
						aa2f02b141
					
				@ -18,6 +18,11 @@
 | 
			
		||||
#include "CConfig.inc"
 | 
			
		||||
#include "CItem.inc"
 | 
			
		||||
 | 
			
		||||
/* REGISTERTYPES */
 | 
			
		||||
#define REGISTERTYPE_WEAPON 1
 | 
			
		||||
#define REGISTERTYPE_BUTTON 2
 | 
			
		||||
#define REGISTERTYPE_TRIGGER 3
 | 
			
		||||
 | 
			
		||||
/* BOOLS */
 | 
			
		||||
bool g_bLate;
 | 
			
		||||
bool g_bIntermission;
 | 
			
		||||
@ -216,72 +221,79 @@ public void OnEntitySpawned(int entity)
 | 
			
		||||
 | 
			
		||||
			if (config.iWeaponID && config.iWeaponID == Entity_GetHammerId(entity))
 | 
			
		||||
			{
 | 
			
		||||
				if (PerformRegisterItem(config, entity, 1))
 | 
			
		||||
				bool bExisting;
 | 
			
		||||
				if ((bExisting = RegisterExistingItem(entity, REGISTERTYPE_WEAPON)))
 | 
			
		||||
				{
 | 
			
		||||
					if (!bExisting)
 | 
			
		||||
					{
 | 
			
		||||
						CItem item = new CItem(config);
 | 
			
		||||
 | 
			
		||||
						if (RegisterItemEntity(item, entity, REGISTERTYPE_WEAPON))
 | 
			
		||||
							g_hArray_Items.Push(item);
 | 
			
		||||
					}
 | 
			
		||||
 | 
			
		||||
					return;
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
			else if (config.iButtonID && config.iButtonID == Entity_GetHammerId(entity))
 | 
			
		||||
			{
 | 
			
		||||
				if (PerformRegisterItem(config, entity, 2))
 | 
			
		||||
				bool bExisting;
 | 
			
		||||
				if ((bExisting = RegisterExistingItem(entity, REGISTERTYPE_BUTTON)))
 | 
			
		||||
				{
 | 
			
		||||
					if (!bExisting)
 | 
			
		||||
					{
 | 
			
		||||
						CItem item = new CItem(config);
 | 
			
		||||
 | 
			
		||||
						if (RegisterItemEntity(item, entity, REGISTERTYPE_BUTTON))
 | 
			
		||||
							g_hArray_Items.Push(item);
 | 
			
		||||
					}
 | 
			
		||||
 | 
			
		||||
					return;
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
			else if (config.iTriggerID && config.iTriggerID == Entity_GetHammerId(entity))
 | 
			
		||||
			{
 | 
			
		||||
				if (PerformRegisterItem(config, entity, 3))
 | 
			
		||||
				bool bExisting;
 | 
			
		||||
				if ((bExisting = RegisterExistingItem(entity, REGISTERTYPE_TRIGGER)))
 | 
			
		||||
				{
 | 
			
		||||
					if (!bExisting)
 | 
			
		||||
					{
 | 
			
		||||
						CItem item = new CItem(config);
 | 
			
		||||
 | 
			
		||||
						if (RegisterItemEntity(item, entity, REGISTERTYPE_TRIGGER))
 | 
			
		||||
							g_hArray_Items.Push(item);
 | 
			
		||||
					}
 | 
			
		||||
 | 
			
		||||
					return;
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//----------------------------------------------------------------------------------------------------
 | 
			
		||||
// Purpose:
 | 
			
		||||
//----------------------------------------------------------------------------------------------------
 | 
			
		||||
stock bool PerformRegisterItem(CConfig config, int entity, int type)
 | 
			
		||||
stock bool RegisterExistingItem(int entity, int type)
 | 
			
		||||
{
 | 
			
		||||
	bool bSuccessful;
 | 
			
		||||
 | 
			
		||||
	if (Entity_IsValid(entity))
 | 
			
		||||
	{
 | 
			
		||||
		if (g_hArray_Items.Length)
 | 
			
		||||
	if (Entity_IsValid(entity) && 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 (RegisterItemEntity(item, entity, type))
 | 
			
		||||
				return true;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
		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;
 | 
			
		||||
	return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//----------------------------------------------------------------------------------------------------
 | 
			
		||||
// Purpose:
 | 
			
		||||
//----------------------------------------------------------------------------------------------------
 | 
			
		||||
stock bool AttemptRegisterItem(CItem item, int entity, int type)
 | 
			
		||||
stock bool RegisterItemEntity(CItem item, int entity, int type)
 | 
			
		||||
{
 | 
			
		||||
	if (Entity_IsValid(entity))
 | 
			
		||||
	{
 | 
			
		||||
@ -292,6 +304,7 @@ stock bool AttemptRegisterItem(CItem item, int entity, int type)
 | 
			
		||||
				if (!item.bWeapon && (Entity_GetOwner(entity) == INVALID_ENT_REFERENCE))
 | 
			
		||||
				{
 | 
			
		||||
					item.iWeapon = entity;
 | 
			
		||||
 | 
			
		||||
					return true;
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
@ -302,6 +315,7 @@ stock bool AttemptRegisterItem(CItem item, int entity, int type)
 | 
			
		||||
					SDKHook(entity, SDKHook_Use, OnButtonPress);
 | 
			
		||||
 | 
			
		||||
					item.iButton = entity;
 | 
			
		||||
 | 
			
		||||
					return true;
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
@ -314,12 +328,14 @@ stock bool AttemptRegisterItem(CItem item, int entity, int type)
 | 
			
		||||
					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;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
@ -350,14 +366,12 @@ public void OnEntityDestroyed(int entity)
 | 
			
		||||
			{
 | 
			
		||||
				item.iButton = INVALID_ENT_REFERENCE;
 | 
			
		||||
 | 
			
		||||
				g_hArray_Items.Set(index, item);
 | 
			
		||||
				return;
 | 
			
		||||
			}
 | 
			
		||||
			else if (item.bTrigger && item.iTrigger == entity)
 | 
			
		||||
			{
 | 
			
		||||
				item.iTrigger = INVALID_ENT_REFERENCE;
 | 
			
		||||
 | 
			
		||||
				g_hArray_Items.Set(index, item);
 | 
			
		||||
				return;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
@ -396,8 +410,6 @@ public void OnClientDisconnect(int client)
 | 
			
		||||
				Call_PushCell(client);
 | 
			
		||||
				Call_PushCell(index);
 | 
			
		||||
				Call_Finish();
 | 
			
		||||
 | 
			
		||||
				g_hArray_Items.Set(index, item);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
@ -424,8 +436,6 @@ public void OnClientDeath(Event hEvent, const char[] sEvent, bool bDontBroadcast
 | 
			
		||||
				Call_PushCell(client);
 | 
			
		||||
				Call_PushCell(index);
 | 
			
		||||
				Call_Finish();
 | 
			
		||||
 | 
			
		||||
				g_hArray_Items.Set(index, item);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
@ -451,7 +461,6 @@ public Action OnWeaponPickup(int client, int weapon)
 | 
			
		||||
				Call_PushCell(index);
 | 
			
		||||
				Call_Finish();
 | 
			
		||||
 | 
			
		||||
				g_hArray_Items.Set(index, item);
 | 
			
		||||
				return;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
@ -478,7 +487,6 @@ public Action OnWeaponDrop(int client, int weapon)
 | 
			
		||||
				Call_PushCell(index);
 | 
			
		||||
				Call_Finish();
 | 
			
		||||
 | 
			
		||||
				g_hArray_Items.Set(index, item);
 | 
			
		||||
				return;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
@ -500,9 +508,8 @@ public Action OnButtonPress(int button, int client)
 | 
			
		||||
		{
 | 
			
		||||
			CItem item = g_hArray_Items.Get(index);
 | 
			
		||||
 | 
			
		||||
			CConfig config = item.dConfig;
 | 
			
		||||
 | 
			
		||||
			if (item.bButton && item.iButton == button && item.bOwner && item.iOwner == client)
 | 
			
		||||
			if ((item.bButton && item.iButton == button) &&
 | 
			
		||||
				(item.bOwner  && item.iOwner  == client))
 | 
			
		||||
			{
 | 
			
		||||
				Action aResult;
 | 
			
		||||
				Call_StartForward(g_hFwd_OnClientItemCanActivate);
 | 
			
		||||
@ -510,21 +517,23 @@ public Action OnButtonPress(int button, int client)
 | 
			
		||||
				Call_PushCell(index);
 | 
			
		||||
				Call_Finish(aResult);
 | 
			
		||||
 | 
			
		||||
				if ((aResult == Plugin_Continue) || (aResult == Plugin_Changed))
 | 
			
		||||
				switch(aResult)
 | 
			
		||||
				{
 | 
			
		||||
					switch(config.iMode)
 | 
			
		||||
					case(Plugin_Continue, Plugin_Changed):
 | 
			
		||||
					{
 | 
			
		||||
						switch(item.dConfig.iMode)
 | 
			
		||||
						{
 | 
			
		||||
							case(1):
 | 
			
		||||
							{
 | 
			
		||||
								if (item.iTimeReady < RoundToCeil(GetEngineTime()))
 | 
			
		||||
								{
 | 
			
		||||
								item.iTimeReady = RoundToCeil(GetEngineTime()) + config.iCooldown;
 | 
			
		||||
									item.iTimeReady = RoundToCeil(GetEngineTime()) + item.dConfig.iCooldown;
 | 
			
		||||
								}
 | 
			
		||||
								else return Plugin_Handled;
 | 
			
		||||
							}
 | 
			
		||||
							case(2):
 | 
			
		||||
							{
 | 
			
		||||
							if (item.iTimesUsed < config.iMaxUses)
 | 
			
		||||
								if (item.iTimesUsed < item.dConfig.iMaxUses)
 | 
			
		||||
								{
 | 
			
		||||
									item.iTimesUsed++;
 | 
			
		||||
								}
 | 
			
		||||
@ -532,9 +541,9 @@ public Action OnButtonPress(int button, int client)
 | 
			
		||||
							}
 | 
			
		||||
							case(3):
 | 
			
		||||
							{
 | 
			
		||||
							if (item.iTimeReady < RoundToCeil(GetEngineTime()) && item.iTimesUsed < config.iMaxUses)
 | 
			
		||||
								if (item.iTimeReady < RoundToCeil(GetEngineTime()) && item.iTimesUsed < item.dConfig.iMaxUses)
 | 
			
		||||
								{
 | 
			
		||||
								item.iTimeReady = RoundToCeil(GetEngineTime()) + config.iCooldown;
 | 
			
		||||
									item.iTimeReady = RoundToCeil(GetEngineTime()) + item.dConfig.iCooldown;
 | 
			
		||||
									item.iTimesUsed++;
 | 
			
		||||
								}
 | 
			
		||||
								else return Plugin_Handled;
 | 
			
		||||
@ -545,9 +554,9 @@ public Action OnButtonPress(int button, int client)
 | 
			
		||||
								{
 | 
			
		||||
									item.iTimesUsed++;
 | 
			
		||||
 | 
			
		||||
								if (item.iTimesUsed >= config.iMaxUses)
 | 
			
		||||
									if (item.iTimesUsed >= item.dConfig.iMaxUses)
 | 
			
		||||
									{
 | 
			
		||||
									item.iTimeReady = RoundToCeil(GetEngineTime()) + config.iCooldown;
 | 
			
		||||
										item.iTimeReady = RoundToCeil(GetEngineTime()) + item.dConfig.iCooldown;
 | 
			
		||||
										item.iTimesUsed = 0;
 | 
			
		||||
									}
 | 
			
		||||
								}
 | 
			
		||||
@ -556,17 +565,21 @@ public Action OnButtonPress(int button, int client)
 | 
			
		||||
						}
 | 
			
		||||
 | 
			
		||||
						char sFilter[64];
 | 
			
		||||
					if (config.GetFilter(sFilter, sizeof(sFilter)))
 | 
			
		||||
						if (item.dConfig.GetFilter(sFilter, sizeof(sFilter)))
 | 
			
		||||
							Entity_SetName(client, sFilter);
 | 
			
		||||
 | 
			
		||||
						Call_StartForward(g_hFwd_OnClientItemActivate);
 | 
			
		||||
						Call_PushCell(client);
 | 
			
		||||
						Call_PushCell(index);
 | 
			
		||||
						Call_Finish();
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				g_hArray_Items.Set(index, item);
 | 
			
		||||
				return aResult;
 | 
			
		||||
						return Plugin_Continue;
 | 
			
		||||
					}
 | 
			
		||||
					default:
 | 
			
		||||
					{
 | 
			
		||||
						return Plugin_Handled;
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
@ -595,7 +608,6 @@ public Action OnTriggerTouch(int trigger, int client)
 | 
			
		||||
				Call_PushCell(index);
 | 
			
		||||
				Call_Finish(aResult);
 | 
			
		||||
 | 
			
		||||
				g_hArray_Items.Set(index, item);
 | 
			
		||||
				return aResult;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
@ -625,7 +637,6 @@ public Action OnWeaponTouch(int client, int weapon)
 | 
			
		||||
				Call_PushCell(index);
 | 
			
		||||
				Call_Finish(aResult);
 | 
			
		||||
 | 
			
		||||
				g_hArray_Items.Set(index, item);
 | 
			
		||||
				return aResult;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user