Raised This Month: $51 Target: $400
 12% 

Solved [CS:GO] Detect if a player spawned in a buyzone


Post New Thread Reply   
 
Thread Tools Display Modes
manicogaming
AlliedModders Donor
Join Date: Aug 2014
Old 03-16-2019 , 16:48   Re: [CS:GO] Detect if a player spawned in a buyzone
Reply With Quote #11

Quote:
Originally Posted by Mathias. View Post
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);
    
HookEvent("enter_buyzone"OnEnteringBuyZoneEventHookMode_Post);
    
HookEvent("exit_buyzone"OnExitingBuyZoneEventHookMode_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(!
IsFakeClient(client))
    {
        
RequestFrame(RFrame_CheckBuyZoneValueclient);
        
        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 
void RFrame_CheckBuyZoneValue(int client) {
    if (!
IsClientInGame(client) || !IsPlayerAlive(client)) return;

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

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

    if (!
client) return;
}

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

    if (!
client) return;
}  

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;

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
I tried that exact code and when a BOT spawns in a BuyZone it returns 0 but when they spawn outside a BuyZone it also returns 0 for some reason.
manicogaming is offline
Mathias.
Veteran Member
Join Date: Aug 2010
Location: Canada is my city
Old 03-16-2019 , 16:52   Re: [CS:GO] Detect if a player spawned in a buyzone
Reply With Quote #12

Quote:
Originally Posted by manicogmaing View Post
I tried that exact code and when a BOT spawns in a BuyZone it returns 0 but when they spawn outside a BuyZone it also returns 0 for some reason.
Your are indeed correct, it only work on players, I guess the value is change later for bots for some reasons. I will setup a working example with bots just give me a few minutes.
Mathias. is offline
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
manicogaming
AlliedModders Donor
Join Date: Aug 2014
Old 03-16-2019 , 17:15   Re: [CS:GO] Detect if a player spawned in a buyzone
Reply With Quote #14

Alright everything works fine now, Thank You very much for you help and your time.
manicogaming is offline
Mathias.
Veteran Member
Join Date: Aug 2010
Location: Canada is my city
Old 03-16-2019 , 17:20   Re: [CS:GO] Detect if a player spawned in a buyzone
Reply With Quote #15

Quote:
Originally Posted by manicogmaing View Post
Alright everything works fine now, Thank You very much for you help and your time.
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;


Last edited by Mathias.; 03-16-2019 at 17:23. Reason: Double check team if it hasn't changed
Mathias. is offline
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
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 16:14.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode