I'm having an issue with the function below. It works fine when I use it on myself. However, when used as part of a mass target (such as @all or @bots) I find that it only works on 20-50 % of the targets.
Any idea on how to improve the function so I don't get the dreaded "Item definition index 65535 is not valid"?
Here's the error I receive:
Code:
L 12/22/2021 - 12:28:10: [SM] Exception reported: Item definition index 65535 is not valid
L 12/22/2021 - 12:28:10: [SM] Blaming: tf_econ_data.smx
L 12/22/2021 - 12:28:10: [SM] Call stack trace:
L 12/22/2021 - 12:28:10: [SM] [0] ThrowNativeError
L 12/22/2021 - 12:28:10: [SM] [1] Line 127, tf_econ_data/item_definition.sp::Native_GetItemEquipRegionMask
L 12/22/2021 - 12:28:10: [SM] [3] TF2Econ_GetItemEquipRegionMask
L 12/22/2021 - 12:28:10: [SM] [4] Line 609, gimme.sp::RemoveConflictWearables
L 12/22/2021 - 12:28:10: [SM] [5] Line 500, gimme.sp::Items_CreateNamedItem
L 12/22/2021 - 12:28:10: [SM] [6] Line 349, gimme.sp::EquipItemByItemIndex
L 12/22/2021 - 12:28:10: [SM] [7] Line 318, gimme.sp::Command_GiveItem
Here's the function I'm using:
PHP Code:
bool RemoveConflictWearables(int client, int newindex)
{
int wearable = -1;
while ((wearable = FindEntityByClassname(wearable, "tf_wearable*")) != -1)
{
if(GetEntPropEnt(wearable, Prop_Send, "m_hOwnerEntity") == client)
{
int oldindex = GetEntProp(wearable, Prop_Send, "m_iItemDefinitionIndex");
//PrintToChatAll("Debug: Wearable: %i, Player: %N, Old Index: %i, New Index: %i, Mask Bit total: %i", wearable, client, oldindex, newindex, (TF2Econ_GetItemEquipRegionMask(oldindex) & TF2Econ_GetItemEquipRegionMask(newindex)));
if(TF2Econ_GetItemEquipRegionMask(oldindex) & TF2Econ_GetItemEquipRegionMask(newindex) > 0)
{
//PrintToChatAll("Debug: Removed %N's item: %i", client, oldindex);
TF2_RemoveWearable (client, wearable);
}
}
}
}