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};
public void OnPluginStart() {
HookEvent("player_spawn", OnPlayerSpawn, EventHookMode_Post);
HookEvent("enter_buyzone", OnEnteringBuyZone, EventHookMode_Post);
HookEvent("exit_buyzone", OnExitingBuyZone, 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(!IsFakeClient(client))
{
RequestFrame(RFrame_CheckBuyZoneValue, 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 void RFrame_CheckBuyZoneValue(int client) {
if (!IsClientInGame(client) || !IsPlayerAlive(client)) return;
int m_iAccount = GetEntProp(client, Prop_Send, "m_iAccount");
int team = GetClientTeam(client);
int m_bHasDefuser = GetEntProp(client, Prop_Send, "m_bHasDefuser");
int m_bInBuyZone = GetEntProp(client, Prop_Send, "m_bInBuyZone");
PrintToServer("%N has m_bInBuyZone value of %d", client, m_bInBuyZone);
if(m_bInBuyZone == 0)
{
if((m_iAccount > 1500) && (m_iAccount < 3000))
{
int iWeapon = GetPlayerWeaponSlot(client, CS_SLOT_SECONDARY);
if (iWeapon != -1)
{
RemovePlayerItem(client, iWeapon);
}
int rndpistol = GetRandomInt(1,3);
switch(rndpistol)
{
case 1:
{
GivePlayerItem(client, "weapon_p250");
SetEntProp(client, Prop_Send, "m_iAccount", m_iAccount - 300);
}
case 2:
{
if(team == 3)
{
int ctcz = GetRandomInt(1,2);
switch(ctcz)
{
case 1:
{
GivePlayerItem(client, "weapon_fiveseven");
SetEntProp(client, Prop_Send, "m_iAccount", m_iAccount - 500);
}
case 2:
{
GivePlayerItem(client, "weapon_cz75a");
SetEntProp(client, Prop_Send, "m_iAccount", m_iAccount - 500);
}
}
}
else if(team == 2)
{
int tcz = GetRandomInt(1,2);
switch(tcz)
{
case 1:
{
GivePlayerItem(client, "weapon_tec9");
SetEntProp(client, Prop_Send, "m_iAccount", m_iAccount - 500);
}
case 2:
{
GivePlayerItem(client, "weapon_cz75a");
SetEntProp(client, Prop_Send, "m_iAccount", m_iAccount - 500);
}
}
}
}
case 3:
{
GivePlayerItem(client, "weapon_deagle");
SetEntProp(client, Prop_Send, "m_iAccount", m_iAccount - 700);
}
}
}
else if(m_iAccount > 3000)
{
RemoveNades(client);
int rndnades = GetRandomInt(1,4);
switch(rndnades)
{
case 1:
{
GivePlayerItem(client, "weapon_flashbang");
}
case 2:
{
GivePlayerItem(client, "weapon_smokegrenade");
}
case 3:
{
GivePlayerItem(client, "weapon_hegrenade");
}
case 4:
{
if(team == 3)
{
GivePlayerItem(client, "weapon_incgrenade");
}
if(team == 2)
{
GivePlayerItem(client, "weapon_molotov");
}
}
}
if(team == 3)
{
if(m_bHasDefuser != 0)
{
GivePlayerItem(client, "item_defuser");
}
}
}
}
}
public void OnEnteringBuyZone(Event event, const char[] name, bool dontBroadcast) {
int userid = event.GetInt("userid");
int client = GetClientOfUserId(userid);
if (!client) return;
}
public void OnExitingBuyZone(Event event, const char[] name, bool dontBroadcast) {
int userid = event.GetInt("userid");
int client = GetClientOfUserId(userid);
if (!client) return;
}
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;
}
this return the correct value for me. Just let you know Ive changed team and m_bInBuyZone to local variables instead of global variable and also !IsFakeClient(client) just to test it on myself in a local server