View Single Post
manicogaming
AlliedModders Donor
Join Date: Aug 2014
Old 03-16-2019 , 18:40   Re: [CS:GO] Detect if a player spawned in a buyzone
Reply With Quote #16

Quote:
Originally Posted by Mathias. View Post
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[] = {151716141817};

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"OnPlayerSpawnEventHookMode_Post);
}

public 
void OnPlayerSpawn(Event event, const char[] namebool dontBroadcast) {
    
int userid event.GetInt("userid");
    
int client GetClientOfUserId(userid);

    
int team GetClientTeam(client);

    if (!
client) return;

    if(
IsClientInGame(client))
    {
        
CreateTimer(0.1RFrame_CheckBuyZoneValueGetClientSerial(client)); 
        
        if(
GetRandomInt(1,10) == 1)
        {
            if(
team == 3)
            {
                
char usp[32];
                
                
GetClientWeapon(clientuspsizeof(usp));
                
                if(
StrEqual(usp"weapon_usp_silencer"))
                {
                    
int uspslot GetPlayerWeaponSlot(clientCS_SLOT_SECONDARY);
                    
                    if (
uspslot != -1)
                    {
                        
RemovePlayerItem(clientuspslot);
                    }
                    
GivePlayerItem(client"weapon_hkp2000");
                }
            }
        }
    }
}

public 
Action RFrame_CheckBuyZoneValue(Handle timerint 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(clientProp_Send"m_iAccount");
    
    
    
bool m_bInBuyZone view_as<bool>(GetEntProp(clientProp_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(clientg_sTRngGrenadesList[GetRandomInt(0sizeof(g_sTRngGrenadesList) - 1)]);
        } else {
            
GivePlayerItem(clientg_sCTRngGrenadesList[GetRandomInt(0sizeof(g_sTRngGrenadesList) - 1)]);
            
SetEntProp(clientProp_Send"m_bHasDefuser"1);
        }
    }

    return 
Plugin_Stop;
}

stock void RemoveNades(int client)
{
    while(
RemoveWeaponBySlot(client3)){}
    for(
int i 06i++)
        
SetEntProp(clientProp_Send"m_iAmmo"0_g_iaGrenadeOffsets[i]);
}

stock bool RemoveWeaponBySlot(int clientint iSlot)
{
    
int iEntity GetPlayerWeaponSlot(clientiSlot);
    if(
IsValidEdict(iEntity)) {
        
RemovePlayerItem(clientiEntity);
        
AcceptEntityInput(iEntity"Kill");
        return 
true;
    }
    return 
false;

The thing about m_bHasDefuser I already knew about but for the rest thank you again
manicogaming is offline