So I run a Jailbreak server and I needed to block some weapons. I decided to try and make a plugin using TF2Items to replace the items with the stock counterparts. The code works fine but for some reason, every so often the weapon will be replaced with a Valve quality version of the replacement and I have no idea what could possibly be causing it.
I've been compiling the plugin on Sourcemod build 1.7.0-git5105.
My code (horrendous, I know) is below. Anything standing out?
PHP Code:
BlockWeapons(client, blockid, replacementid, String:classname[])
{
new slot1 = GetPlayerWeaponSlot(client, 0);
new slot2 = GetPlayerWeaponSlot(client, 1);
new slot3 = GetPlayerWeaponSlot(client, 2);
if(IsValidEntity(slot1))
{
new slot1ID = GetEntProp(slot1, Prop_Send, "m_iItemDefinitionIndex");
if (slot1ID == blockid)
{
TF2_RemoveWeaponSlot(client, 0);
hWeaponBlocked = TF2Items_CreateItem(OVERRIDE_ALL);
TF2Items_SetClassname(hWeaponBlocked, classname);
TF2Items_SetItemIndex(hWeaponBlocked, replacementid);
TF2Items_SetQuality(hWeaponBlocked, 0);
new iEntity = TF2Items_GiveNamedItem(client, hWeaponBlocked);
EquipPlayerWeapon(client, iEntity);
}
}
if(IsValidEntity(slot2))
{
new slot2ID = GetEntProp(slot2, Prop_Send, "m_iItemDefinitionIndex");
if (slot2ID == blockid)
{
TF2_RemoveWeaponSlot(client, 1);
hWeaponBlocked = TF2Items_CreateItem(OVERRIDE_ALL);
TF2Items_SetClassname(hWeaponBlocked, classname);
TF2Items_SetItemIndex(hWeaponBlocked, replacementid);
TF2Items_SetQuality(hWeaponBlocked, 0);
new iEntity = TF2Items_GiveNamedItem(client, hWeaponBlocked);
EquipPlayerWeapon(client, iEntity);
}
}
if(IsValidEntity(slot3))
{
new slot3ID = GetEntProp(slot3, Prop_Send, "m_iItemDefinitionIndex");
if (slot3ID == blockid)
{
TF2_RemoveWeaponSlot(client, 2);
hWeaponBlocked = TF2Items_CreateItem(OVERRIDE_ALL);
TF2Items_SetClassname(hWeaponBlocked, classname);
TF2Items_SetItemIndex(hWeaponBlocked, replacementid);
TF2Items_SetQuality(hWeaponBlocked, 0);
new iEntity = TF2Items_GiveNamedItem(client, hWeaponBlocked);
EquipPlayerWeapon(client, iEntity);
}
}
}
I've also attached the full plugin in case it sheds some light on the problem.