entWatch4: Add 'sorting' to make it more similiar to old entWatch.

And reset client('owner') when weapon dies.
This commit is contained in:
zaCade 2019-04-11 14:01:57 +02:00
parent d0f49b369a
commit 92748fe274
2 changed files with 43 additions and 0 deletions

View File

@ -16,6 +16,7 @@ methodmap CConfig < Basic
myclass.SetString("sFilter", ""); myclass.SetString("sFilter", "");
myclass.SetInt("iButtonID", 0); myclass.SetInt("iButtonID", 0);
myclass.SetInt("iConfigID", 0);
myclass.SetInt("iWeaponID", 0); myclass.SetInt("iWeaponID", 0);
myclass.SetInt("iTriggerID", 0); myclass.SetInt("iTriggerID", 0);
@ -82,6 +83,18 @@ methodmap CConfig < Basic
} }
} }
property int iConfigID
{
public get()
{
return this.GetInt("iConfigID");
}
public set(int value)
{
this.SetInt("iConfigID", value);
}
}
property int iWeaponID property int iWeaponID
{ {
public get() public get()

View File

@ -137,6 +137,8 @@ public void OnMapStart()
if (hConfig.GotoFirstSubKey()) if (hConfig.GotoFirstSubKey())
{ {
int iConfigID;
do do
{ {
CConfig config = new CConfig(); CConfig config = new CConfig();
@ -152,6 +154,7 @@ public void OnMapStart()
config.SetColor(sColor); config.SetColor(sColor);
config.SetFilter(sFilter); config.SetFilter(sFilter);
config.iConfigID = iConfigID++;
config.iWeaponID = hConfig.GetNum("weaponid"); config.iWeaponID = hConfig.GetNum("weaponid");
config.iButtonID = hConfig.GetNum("buttonid"); config.iButtonID = hConfig.GetNum("buttonid");
config.iTriggerID = hConfig.GetNum("triggerid"); config.iTriggerID = hConfig.GetNum("triggerid");
@ -228,7 +231,11 @@ public void OnEntitySpawned(int entity)
CItem item = new CItem(config); CItem item = new CItem(config);
if (RegisterItemEntity(item, entity, REGISTER_WEAPON)) if (RegisterItemEntity(item, entity, REGISTER_WEAPON))
{
g_hArray_Items.Push(item); g_hArray_Items.Push(item);
SortADTArrayCustom(g_hArray_Items, SortItemsArray);
}
} }
} }
else if (config.iButtonID && config.iButtonID == iHammerID) else if (config.iButtonID && config.iButtonID == iHammerID)
@ -238,7 +245,11 @@ public void OnEntitySpawned(int entity)
CItem item = new CItem(config); CItem item = new CItem(config);
if (RegisterItemEntity(item, entity, REGISTER_BUTTON)) if (RegisterItemEntity(item, entity, REGISTER_BUTTON))
{
g_hArray_Items.Push(item); g_hArray_Items.Push(item);
SortADTArrayCustom(g_hArray_Items, SortItemsArray);
}
} }
} }
else if (config.iTriggerID && config.iTriggerID == iHammerID) else if (config.iTriggerID && config.iTriggerID == iHammerID)
@ -248,7 +259,11 @@ public void OnEntitySpawned(int entity)
CItem item = new CItem(config); CItem item = new CItem(config);
if (RegisterItemEntity(item, entity, REGISTER_TRIGGER)) if (RegisterItemEntity(item, entity, REGISTER_TRIGGER))
{
g_hArray_Items.Push(item); g_hArray_Items.Push(item);
SortADTArrayCustom(g_hArray_Items, SortItemsArray);
}
} }
} }
} }
@ -341,6 +356,7 @@ public void OnEntityDestroyed(int entity)
if (item.bWeapon && item.iWeapon == entity) if (item.bWeapon && item.iWeapon == entity)
{ {
item.iClient = INVALID_ENT_REFERENCE;
item.iWeapon = INVALID_ENT_REFERENCE; item.iWeapon = INVALID_ENT_REFERENCE;
return; return;
@ -361,6 +377,20 @@ public void OnEntityDestroyed(int entity)
} }
} }
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public int SortItemsArray(int index1, int index2, Handle array, Handle hndl)
{
CConfig config1 = view_as<CItem>(g_hArray_Items.Get(index1)).dConfig;
CConfig config2 = view_as<CItem>(g_hArray_Items.Get(index2)).dConfig;
if (config1.iConfigID < config2.iConfigID) return -1;
if (config1.iConfigID > config2.iConfigID) return 1;
return 0;
}
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
// Purpose: // Purpose:
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------