//420's Bad Strref Item Property Filter
//Created: January 18, 2007
//Last Update: May 20, 2007
//Put in OnClientEnter
void main()
{
//Declare variables
object oPC = GetEnteringObject();
object oItem;
itemproperty ipProp;
int iType;
string sType;
string sSubTypeResRef;
int iSubType;
string sSubType;
int iCounter;
//Cycle through all equipped items
for (iCounter = 0; iCounter <= NUM_INVENTORY_SLOTS; iCounter++)
{
oItem = GetItemInSlot(iCounter, oPC);
if(GetIsObjectValid(oItem))
{
//Cycle through item's properties
ipProp = GetFirstItemProperty(oItem);
while(GetIsItemPropertyValid(ipProp))
{
//Check for bad strref property types and remove them
iType = GetItemPropertyType(ipProp);
sType = Get2DAString("itempropdef", "Name", iType);
sSubTypeResRef = Get2DAString("itempropdef", "SubTypeResRef", iType);
if(sType == "")
{
RemoveItemProperty(oItem, ipProp);
}
//Check for valid property subtype if property type is valid
else if(sSubTypeResRef != "")
{
//Check for bad strref property sub types and remove them
iSubType = GetItemPropertySubType(ipProp);
sSubType = Get2DAString(sSubTypeResRef, "Name", iSubType);
if(sSubType == "")
{
RemoveItemProperty(oItem, ipProp);
}
}
ipProp = GetNextItemProperty(oItem);
}
}
}
//Cycle through all inventory items
oItem = GetFirstItemInInventory(oPC);
while(GetIsObjectValid(oItem) == TRUE)
{
//Cycle through item's properties
ipProp = GetFirstItemProperty(oItem);
while(GetIsItemPropertyValid(ipProp))
{
//Check for bad strref property types and remove them
iType = GetItemPropertyType(ipProp);
sType = Get2DAString("itempropdef", "Name", iType);
sSubTypeResRef = Get2DAString("itempropdef", "SubTypeResRef", iType);
if(sType == "")
{
RemoveItemProperty(oItem, ipProp);
}
//Check for valid property subtype if property type is valid
else if(sSubTypeResRef != "")
{
//Check for bad strref property sub types and remove them
iSubType = GetItemPropertySubType(ipProp);
sSubType = Get2DAString(sSubTypeResRef, "Name", iSubType);
if(sSubType == "")
{
RemoveItemProperty(oItem, ipProp);
}
}
ipProp = GetNextItemProperty(oItem);
}
oItem = GetNextItemInInventory(oPC);
}
}
If you have any problems with this filter please tell me and I'll fix it.Ser Red Ronnet Connington brought to my attention that the bad strref filter I posted was getting stuck in an infinite loop. While looking into this I actually decided to test it with a bad strref item and sure enough, the script was completely wrong!
Well, I fixed the infinite loop and the item property sub-type check and even streamlined the code a bit to make it more efficient. I've tested this script with a bad strref item equipped and with one in the inventory and it now properly removes all bad strref properties on items.
Thanks to Ser for bringing my attention to this problem.
Cheers,
420[snapback]35284[/snapback]