View Single Post
Mathias.
Veteran Member
Join Date: Aug 2010
Location: Canada is my city
Old 03-16-2019 , 17:02   Re: [CS:GO] Detect if a player spawned in a buyzone
Reply With Quote #13

I've setup a timer instead of frame request. I haven't had issue this time.

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};

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 m_iAccount GetEntProp(clientProp_Send"m_iAccount");
    
int team GetClientTeam(client);
    
    
int m_bHasDefuser GetEntProp(clientProp_Send"m_bHasDefuser");
    
int m_bInBuyZone GetEntProp(clientProp_Send"m_bInBuyZone");

    
PrintToServer("%N has m_bInBuyZone value of %d"clientm_bInBuyZone);
    
    if(
m_bInBuyZone == 0)
    {
        if((
m_iAccount 1500) && (m_iAccount 3000))
        {
            
int iWeapon GetPlayerWeaponSlot(clientCS_SLOT_SECONDARY);
            
            if (
iWeapon != -1)
            {
                
RemovePlayerItem(clientiWeapon);
            }
            
            
int rndpistol GetRandomInt(1,3);
            
            switch(
rndpistol)
            {
                case 
1:
                {
                    
GivePlayerItem(client"weapon_p250");
                    
SetEntProp(clientProp_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(clientProp_Send"m_iAccount"m_iAccount 500);
                            }
                            case 
2:
                            {
                                
GivePlayerItem(client"weapon_cz75a");
                                
SetEntProp(clientProp_Send"m_iAccount"m_iAccount 500);
                            }
                        }
                    }
                    else if(
team == 2)
                    {
                        
int tcz GetRandomInt(1,2);
                        
                        switch(
tcz)
                        {
                            case 
1:
                            {
                                
GivePlayerItem(client"weapon_tec9");
                                
SetEntProp(clientProp_Send"m_iAccount"m_iAccount 500);
                            }
                            case 
2:
                            {
                                
GivePlayerItem(client"weapon_cz75a");
                                
SetEntProp(clientProp_Send"m_iAccount"m_iAccount 500);
                            }
                        }
                    }
                }
                case 
3:
                {
                    
GivePlayerItem(client"weapon_deagle");
                    
SetEntProp(clientProp_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");
                }
            }
        }
    }

    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;

Mathias. is offline