One more thing GivePlayerItem defuser doesn't seem to work you can just set m_bHasDefuser to 1.
Also I've cleaned the code a little more, you just have to do the same for the weapons and etc..
PHP Code:
#pragma semicolon 1
#include <sourcemod>
#include <clientprefs>
#include <sdkhooks>
#include <sdktools>
#include <cstrike>
#pragma newdecls required
public Plugin myinfo =
{
name = "m_bInBuyZone",
author = "A guy in Canada",
description = "",
version = "13.3.7",
url = "https://forums.alliedmods.net/showthread.php?t=314996"
};
int g_iaGrenadeOffsets[] = {15, 17, 16, 14, 18, 17};
char g_sTRngGrenadesList[][] = {
"weapon_flashbang",
"weapon_smokegrenade",
"weapon_hegrenade",
"weapon_molotov"
};
char g_sCTRngGrenadesList[][] = {
"weapon_flashbang",
"weapon_smokegrenade",
"weapon_hegrenade",
"weapon_incgrenade"
};
public void OnPluginStart() {
HookEvent("player_spawn", OnPlayerSpawn, EventHookMode_Post);
}
public void OnPlayerSpawn(Event event, const char[] name, bool dontBroadcast) {
int userid = event.GetInt("userid");
int client = GetClientOfUserId(userid);
int team = GetClientTeam(client);
if (!client) return;
if(IsClientInGame(client))
{
CreateTimer(0.1, RFrame_CheckBuyZoneValue, GetClientSerial(client));
if(GetRandomInt(1,10) == 1)
{
if(team == 3)
{
char usp[32];
GetClientWeapon(client, usp, sizeof(usp));
if(StrEqual(usp, "weapon_usp_silencer"))
{
int uspslot = GetPlayerWeaponSlot(client, CS_SLOT_SECONDARY);
if (uspslot != -1)
{
RemovePlayerItem(client, uspslot);
}
GivePlayerItem(client, "weapon_hkp2000");
}
}
}
}
}
public Action RFrame_CheckBuyZoneValue(Handle timer, int serial) {
int client = GetClientFromSerial(serial);
if (!client || !IsClientInGame(client) || !IsPlayerAlive(client)) return Plugin_Stop;
int team = GetClientTeam(client);
if (team < 2) return Plugin_Stop;
int m_iAccount = GetEntProp(client, Prop_Send, "m_iAccount");
bool m_bInBuyZone = view_as<bool>(GetEntProp(client, Prop_Send, "m_bInBuyZone"));
// not in buyzone let just return
if(!m_bInBuyZone) return Plugin_Stop;
if(m_iAccount > 3000)
{
RemoveNades(client);
if (team == 2) {
GivePlayerItem(client, g_sTRngGrenadesList[GetRandomInt(0, sizeof(g_sTRngGrenadesList) - 1)]);
} else {
GivePlayerItem(client, g_sCTRngGrenadesList[GetRandomInt(0, sizeof(g_sTRngGrenadesList) - 1)]);
SetEntProp(client, Prop_Send, "m_bHasDefuser", 1);
}
}
return Plugin_Stop;
}
stock void RemoveNades(int client)
{
while(RemoveWeaponBySlot(client, 3)){}
for(int i = 0; i < 6; i++)
SetEntProp(client, Prop_Send, "m_iAmmo", 0, _, g_iaGrenadeOffsets[i]);
}
stock bool RemoveWeaponBySlot(int client, int iSlot)
{
int iEntity = GetPlayerWeaponSlot(client, iSlot);
if(IsValidEdict(iEntity)) {
RemovePlayerItem(client, iEntity);
AcceptEntityInput(iEntity, "Kill");
return true;
}
return false;
}