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)
|
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;
|
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:
|
// 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 (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;
|
CItem item = g_hArray_Items.Get(index);
|
||||||
return true;
|
|
||||||
|
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;
|
if (!bSuccessful)
|
||||||
return true;
|
{
|
||||||
|
CItem item = new CItem(config);
|
||||||
|
|
||||||
|
if (AttemptRegisterItem(item, entity, type))
|
||||||
|
{
|
||||||
|
g_hArray_Items.Push(item);
|
||||||
|
bSuccessful = true;
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
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)))
|
|
||||||
{
|
{
|
||||||
SDKHook(entity, SDKHook_StartTouch, OnTriggerTouch);
|
LogError("Attempted to register new item, but failed! This should never happen.");
|
||||||
SDKHook(entity, SDKHook_EndTouch, OnTriggerTouch);
|
|
||||||
SDKHook(entity, SDKHook_Touch, OnTriggerTouch);
|
|
||||||
|
|
||||||
item.iTrigger = entity;
|
delete item;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
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