There is another bug with prepareitemhandle.. When parsing empty strings it tries to grab attribs from the item, when it shiuld just be setting the attrib count to zero,this results in the attrib zero error as well.
Something like this may work for prepareitemhandle, PL suggested checking for the delim, or you could use strlen. I think it's safe to decl the array here, since presumably you will parse out pairs and they will fill the array. If you have bad input for ongivenameditem -- which does not come from boss configs, that's a pretty big problem anyways. I have been using something similar to this, but mine is a bit different.. 99% of my ff2 item handling is done ongivenameditem, and I use a global handle, but I think this will work...
PHP Code:
stock Handle:PrepareItemHandle(Handle:hItem, String:name[] = "", index = -1, const String:att[] = "", bool:dontpreserve = false)
{
static Handle:hWeapon;
new addattribs = 0;
decl String:weaponAttribsArray[32][32];
decl attribCount;
if(att[0] != '\0')
{
attribCount = ExplodeString(att, " ; ", weaponAttribsArray, 32, 32);
}
else
{
attribCount = 0;
}
new flags = OVERRIDE_ATTRIBUTES;
if (!dontpreserve)
{
flags |= PRESERVE_ATTRIBUTES;
}
if (hWeapon == INVALID_HANDLE)
{
hWeapon = TF2Items_CreateItem(flags);
}
else
{
TF2Items_SetFlags(hWeapon, flags);
}
if (hItem != INVALID_HANDLE)
{
if(!dontpreserve) // don't bother reading attribs if we are discarding them?
{
addattribs = TF2Items_GetNumAttributes(hItem);
}
if (addattribs > 0)
{
for (new i = 0; i < 2 * addattribs; i += 2)
{
new bool:dontAdd = false;
new attribIndex = TF2Items_GetAttributeId(hItem, i);
for (new z = 0; z < attribCount+i; z += 2)
{
if (StringToInt(weaponAttribsArray[z]) == attribIndex)
{
dontAdd = true;
break;
}
}
if (!dontAdd)
{
IntToString(attribIndex, weaponAttribsArray[i+attribCount], 32);
FloatToString(TF2Items_GetAttributeValue(hItem, i), weaponAttribsArray[i+1+attribCount], 32);
}
}
attribCount += 2 * addattribs;
}
CloseHandle(hItem); //probably returns false but whatever
}
if (name[0] != '\0')
{
flags |= OVERRIDE_CLASSNAME;
TF2Items_SetClassname(hWeapon, name);
}
if (index != -1)
{
flags |= OVERRIDE_ITEM_DEF;
TF2Items_SetItemIndex(hWeapon, index);
}
if (attribCount)
{
TF2Items_SetNumAttributes(hWeapon, (attribCount/2));
new i2 = 0;
for (new i = 0; i < attribCount && i2 < 32; i += 2)
{
TF2Items_SetAttribute(hWeapon, i2, StringToInt(weaponAttribsArray[i]), StringToFloat(weaponAttribsArray[i+1]));
i2++;
}
}
else
{
TF2Items_SetNumAttributes(hWeapon, 0);
}
TF2Items_SetFlags(hWeapon, flags);
return hWeapon;
}
and for the instances of spawnweapon:
PHP Code:
stock SpawnWeapon(client,String:name[],index,level,qual,String:att[])
{
new Handle:hWeapon = TF2Items_CreateItem(OVERRIDE_ALL|FORCE_GENERATION);
if (hWeapon == INVALID_HANDLE)
return -1;
TF2Items_SetClassname(hWeapon, name);
TF2Items_SetItemIndex(hWeapon, index);
TF2Items_SetLevel(hWeapon, level);
TF2Items_SetQuality(hWeapon, qual);
new String:atts[32][32];
new count = ExplodeString(att, " ; ", atts, 32, 32);
if (count > 1) // attribute pairs
{
TF2Items_SetNumAttributes(hWeapon, count/2);
new i2 = 0;
for (new i = 0; i < count; i+= 2)
{
TF2Items_SetAttribute(hWeapon, i2, StringToInt(atts[i]), StringToFloat(atts[i+1]));
i2++;
}
}
else
TF2Items_SetNumAttributes(hWeapon, 0);
new entity = TF2Items_GiveNamedItem(client, hWeapon);
CloseHandle(hWeapon);
EquipPlayerWeapon(client, entity);
return entity;
}
Edit: oh, and as voided pointed out.. if you use the stock version which injects the stupid stock values, you'll need to do something about the trailing semicolon. I think this might work =/
PHP Code:
EquipBoss(index)
{
DoOverlay(Boss[index],"");
TF2_RemoveAllWeapons(Boss[index]);
decl String:s[64];
decl String:s2[128];
for(new j = 1; ; j++)
{
KvRewind(BossKV[Special[index]]);
Format(s,10,"weapon%i",j);
if (KvJumpToKey(BossKV[Special[index]],s))
{
KvGetString(BossKV[Special[index]], "name",s, 64);
KvGetString(BossKV[Special[index]], "attributes",s2, 128, "");
if(s2[0] != '\0')
{
Format(s2,128,"68 ; 2 ; 2 ; 3.0 ; 259 ; 1 ; 269 ; 1 ; %s",s2);
}
else
{
Format(s2,128,"68 ; 2 ; 2 ; 3.0 ; 259 ; 1 ; 269 ; 1");
}
__________________