diff --git a/src/zr/infect.inc b/src/zr/infect.inc index b4db2f4..10b56d5 100644 --- a/src/zr/infect.inc +++ b/src/zr/infect.inc @@ -609,39 +609,8 @@ InfectHumanToZombie(client, attacker = -1, bool:motherinfect = false, bool:respa new bool:weaponsdrop = GetConVarBool(g_hCvarsList[CVAR_INFECT_WEAPONS_DROP]); // This must be after the event forwarding because it fixes a problem caused by changing models in ClassOnClientInfected. - // Loop through array slots and force drop. - // x = weapon slot. - for (new x = 0; x < WEAPONS_SLOTS_MAX; x++) - { - // If weapon is invalid, then stop. - if (weapons[x] == -1) - { - continue; - } - - if (weaponsdrop) - { - // If this is the knife slot, then stop. - if (WeaponsSlot:x == Slot_Melee) - { - // Strip knife. - RemovePlayerItem(client, weapons[x]); - - continue; - } - - // Force client to drop weapon. - WeaponsForceClientDrop(client, weapons[x]); - } - else - { - // Strip weapon. - RemovePlayerItem(client, weapons[x]); - } - } - - // Give zombie a new knife. (If you leave the old one there will be glitches with the knife positioning) - GivePlayerItem(client, "weapon_knife"); + // Remove all weapons but knife. + WeaponsRemoveAllClientWeapons(client, weaponsdrop); // Switch the player to terrorists. // TODO: A solution to stop confusing bots? Respawn and teleport? @@ -1191,4 +1160,4 @@ public Action:InfectHumanCommand(client, argc) InfectManualHuman(client, targets, result, respawn, protect); return Plugin_Handled; -} \ No newline at end of file +} diff --git a/src/zr/weapons/weapons.inc b/src/zr/weapons/weapons.inc index 0ce6f97..b251325 100644 --- a/src/zr/weapons/weapons.inc +++ b/src/zr/weapons/weapons.inc @@ -778,3 +778,80 @@ stock WeaponsForceClientDrop(client, weapon) // Force client to drop weapon. SDKCall(g_hToolsCSWeaponDrop, client, weapon, true, false); } + +/** + * Used to explicitly remove projectile weapons from a client. + * + * @param client The client index. + * @param weaponsdrop True to force drop on all weapons, false to strip. + */ +stock WeaponsRemoveClientGrenades(client, bool:weaponsdrop) +{ + // This while-structure is a stupid sloppy annoying workaround to stop the "unintended assignment" warning. I hate those. + // While GetPlayerWeaponSlot returns a valid projectile, remove it and then test again. + new grenade = GetPlayerWeaponSlot(client, _:Slot_Projectile); + while (grenade != -1) + { + // Check if we drop or strip the grenade. + if (weaponsdrop) + { + WeaponsForceClientDrop(client, grenade); + } + else + { + RemovePlayerItem(client, grenade); + } + + // Find next grenade. + grenade = GetPlayerWeaponSlot(client, _:Slot_Projectile); + } +} + +/** + * Remove all weapons, except knife, on a client, with options. + * + * @param client The client index. + * @param weaponsdrop True to force drop on all weapons, false to strip. + */ +stock WeaponsRemoveAllClientWeapons(client, bool:weaponsdrop) +{ + // Get a list of all client's weapon indexes. + new weapons[WeaponsSlot]; + WeaponsGetClientWeapons(client, weapons); + + // Loop through array slots and force drop. + // x = weapon slot. + for (new x = 0; x < WEAPONS_SLOTS_MAX; x++) + { + // If weapon is invalid, then stop. + if (weapons[x] == -1) + { + continue; + } + + // If this is the knife slot, then strip it and stop. + if (WeaponsSlot:x == Slot_Melee) + { + // Strip knife. + RemovePlayerItem(client, weapons[x]); + continue; + } + + if (weaponsdrop) + { + // Force client to drop weapon. + WeaponsForceClientDrop(client, weapons[x]); + } + else + { + // Strip weapon. + RemovePlayerItem(client, weapons[x]); + } + } + + // Remove left-over projectiles. + WeaponsRemoveClientGrenades(client, weaponsdrop); + + // Give zombie a new knife. (If you leave the old one there will be glitches with the knife positioning) + GivePlayerItem(client, "weapon_knife"); +}