Hello everyone!
I have created a function that changes the colors of an item randomly. It checks the color channels the item have then in a while loop it creates copy, changing one channel at the same time.
The function works fine, but don’t know why produces a big lag spike when the item passed in is a torso. Tested with cloaks and helms and no lag is generated. I though that the issue was the creating a copy to change each color ( 6 copies in total per torso, altho depending on the cloak it will copy 6 too…) but it works inside a random shop system that creates 80+ diferent items in each store and only have lag spikes when modifying torsos >.<
The script is as follows:
object RandomColor(object oItem)
{
int iCount = 0;
int LEATHER_1 = 0;
int LEATHER_2 = 0;
int CLOTH_1 = 0;
int CLOTH_2 = 0;
int METAL_1 = 0;
int METAL_2 = 0;
if(GetItemAppearance(oItem,ITEM_APPR_TYPE_ARMOR_COLOR,ITEM_APPR_ARMOR_COLOR_LEATHER1) != 1)
LEATHER_1 = TRUE;
if(GetItemAppearance(oItem,ITEM_APPR_TYPE_ARMOR_COLOR,ITEM_APPR_ARMOR_COLOR_LEATHER2)!= 1)
LEATHER_2 = TRUE;
if(GetItemAppearance(oItem,ITEM_APPR_TYPE_ARMOR_COLOR,ITEM_APPR_ARMOR_COLOR_CLOTH1)!= 1)
CLOTH_1 = TRUE;
if(GetItemAppearance(oItem,ITEM_APPR_TYPE_ARMOR_COLOR,ITEM_APPR_ARMOR_COLOR_CLOTH2)!= 1)
CLOTH_2 = TRUE;
if(GetItemAppearance(oItem,ITEM_APPR_TYPE_ARMOR_COLOR,ITEM_APPR_ARMOR_COLOR_METAL1)!= 1)
METAL_1 = TRUE;
if(GetItemAppearance(oItem,ITEM_APPR_TYPE_ARMOR_COLOR,ITEM_APPR_ARMOR_COLOR_METAL2)!= 1)
METAL_2 = TRUE;
while(iCount < 6)
{
switch(iCount)
{
case 0:
{
if(LEATHER_1 == TRUE)
{
oItem = CopyItemAndModify(oItem,ITEM_APPR_TYPE_ARMOR_COLOR,iCount,Random(176));
}
break;
}
case 1:
{
if(LEATHER_2 == TRUE)
{
oItem = CopyItemAndModify(oItem,ITEM_APPR_TYPE_ARMOR_COLOR,iCount,Random(176));
}
break;
}
case 2:
{
if(CLOTH_1 == TRUE)
{
oItem = CopyItemAndModify(oItem,ITEM_APPR_TYPE_ARMOR_COLOR,iCount,Random(176));
}
break;
}
case 3:
{
if(CLOTH_2 == TRUE)
{
oItem = CopyItemAndModify(oItem,ITEM_APPR_TYPE_ARMOR_COLOR,iCount,Random(176));
}
break;
}
case 4:
{
if(METAL_1 == TRUE)
{
oItem = CopyItemAndModify(oItem,ITEM_APPR_TYPE_ARMOR_COLOR,iCount,Random(176));
}
break;
}
case 5:
{
if(METAL_2 == TRUE)
{
oItem = CopyItemAndModify(oItem,ITEM_APPR_TYPE_ARMOR_COLOR,iCount,Random(176));
}
break;
}
}
iCount++;
}
return oItem;
}
Any help or opinion is apreciated^^