I'm trying to remove all weapons on player spawn except for the knife. I'm struggling to understand why the below code is removing all weapons.
PHP Code:
public void Event_PlayerSpawn(Event event, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(GetEventInt(event, "userid"));
if (IsValidClient)
{
int weapon = -1;
for (new i = 0; i <= 5; i++)
{
if ((weapon = GetPlayerWeaponSlot(client,i)) != -1)
{
char weaponName[33];
GetEntityClassname(weapon, weaponName, sizeof(weaponName));
if (StrContains(weaponName, "knife") == -1 || StrContains(weaponName, "bayonet") == -1)
{
RemovePlayerItem(client, weapon);
AcceptEntityInput(weapon, "Kill");
}
}
}
}
}
To my understanding, StrContains() will return -1 if the string is not found. I tested this by adding some PrintToChat() messages to print out the StrContains() values and confirmed that it's producing a -1 value for weapons that are not a knife but still goes ahead and strips everything.