Raised This Month: $32 Target: $400
 8% 

Solved [CS:GO] Force +attack and -attack on bots


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
manicogaming
AlliedModders Donor
Join Date: Aug 2014
Old 03-19-2019 , 14:04   [CS:GO] Force +attack and -attack on bots
Reply With Quote #1

Hi, I've been trying to force the bots to throw their grenades but I can't seem to get it right. Any help?

PHP Code:
public Action OnPlayerRunCmd(client, &buttons, &impulseFloat:vel[3], Float:angles[3], &weapon, &subtype, &cmdnum, &tickcount, &seedmouse[2]) 

    if (
IsClientInGame(client) && IsFakeClient(client))
    {
        
int ActiveWeapon GetEntPropEnt(clientProp_Send"m_hActiveWeapon");
        if (
ActiveWeapon != -1)
        {
            
int index GetEntProp(ActiveWeaponProp_Send"m_iItemDefinitionIndex"); 
         
            if((
index  == 43) || (index == 44) || (index == 45) || (index == 46) || (index == 48)) 
            {
                
buttons &= IN_ATTACK;
                
buttons &= ~IN_ATTACK;
            } 
        }
    }


Last edited by manicogaming; 01-19-2020 at 16:02. Reason: Solved
manicogaming is offline
impossible_cc
Senior Member
Join Date: Sep 2018
Location: Ukraine
Old 03-19-2019 , 15:01   Re: [CS:GO] Force +attack and -attack on bots
Reply With Quote #2

[I'm not sure]
I think it is too fast. I mean this is not even one frame, game doesnt even realise that you can throw a grenade, but button is removed already. Try to work with timers
impossible_cc is offline
Zeisen
Member
Join Date: Nov 2016
Location: Republic of Korea
Old 03-19-2019 , 15:26   Re: [CS:GO] Force +attack and -attack on bots
Reply With Quote #3

Try this one. But I didn't test.

Code:
public Action OnPlayerRunCmd(client, &buttons, &impulse, Float:vel[3], Float:angles[3], &weapon, &subtype, &cmdnum, &tickcount, &seed, mouse[2])  
{  
    if (IsFakeClient(client)) 
    { 
        int ActiveWeapon = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon"); 
        if (ActiveWeapon != -1) 
        { 
            int index = GetEntProp(ActiveWeapon, Prop_Send, "m_iItemDefinitionIndex");  
		  
            if (index == 43 || index == 44 || index == 45 || index == 46 || index == 48)
            { 
                if (buttons & IN_ATTACK)
                    buttons &= ~IN_ATTACK; 
                else
                    buttons |= IN_ATTACK; 
            }
        }
    }

    return Plugin_Continue;
}
Zeisen is offline
manicogaming
AlliedModders Donor
Join Date: Aug 2014
Old 03-19-2019 , 15:44   Re: [CS:GO] Force +attack and -attack on bots
Reply With Quote #4

Quote:
Originally Posted by Zeisen View Post
Try this one. But I didn't test.

Code:
public Action OnPlayerRunCmd(client, &buttons, &impulse, Float:vel[3], Float:angles[3], &weapon, &subtype, &cmdnum, &tickcount, &seed, mouse[2])  
{  
    if (IsFakeClient(client)) 
    { 
        int ActiveWeapon = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon"); 
        if (ActiveWeapon != -1) 
        { 
            int index = GetEntProp(ActiveWeapon, Prop_Send, "m_iItemDefinitionIndex");  
		  
            if (index == 43 || index == 44 || index == 45 || index == 46 || index == 48)
            { 
                if (buttons & IN_ATTACK)
                    buttons &= ~IN_ATTACK; 
                else
                    buttons |= IN_ATTACK; 
            }
        }
    }

    return Plugin_Continue;
}
Sadly I don't think that's working.

EDIT: I tested it on my self and it just spammed +attack and it only would throw the grenade if I pressed MOUSE1.

Last edited by manicogaming; 03-19-2019 at 16:52.
manicogaming is offline
CliptonHeist
Senior Member
Join Date: Feb 2016
Old 03-19-2019 , 18:07   Re: [CS:GO] Force +attack and -attack on bots
Reply With Quote #5

Quote:
Originally Posted by manicogmaing View Post
Sadly I don't think that's working.

EDIT: I tested it on my self and it just spammed +attack and it only would throw the grenade if I pressed MOUSE1.
I would assume that's because you need to hold mouse1 for a short time while priming the grenade, I would suggest trying what impossible_cc said and use a short timer instead
CliptonHeist is offline
manicogaming
AlliedModders Donor
Join Date: Aug 2014
Old 03-19-2019 , 18:19   Re: [CS:GO] Force +attack and -attack on bots
Reply With Quote #6

Quote:
Originally Posted by CliptonHeist View Post
I would assume that's because you need to hold mouse1 for a short time while priming the grenade, I would suggest trying what impossible_cc said and use a short timer instead
And how would I use OnPlayerUseCmd with a Timer?
manicogaming is offline
Mathias.
Veteran Member
Join Date: Aug 2010
Location: Canada is my city
Old 03-19-2019 , 18:49   Re: [CS:GO] Force +attack and -attack on bots
Reply With Quote #7

this is just a small example of what they meant by using timer with OnPlayerUseCmd
you will have to clear your timers when client leave or join, on round start etc...

this is untested and I have no clue if it will even work.
PHP Code:
#pragma semicolon 1

#include <sourcemod>
#include <sdktools>

#pragma newdecls required

bool g_bShouldAttack[MAXPLAYERS 1];
Handle g_hShouldAttackTimer[MAXPLAYERS 1];

public 
Action OnPlayerRunCmd(int clientintbuttonsintimpulsefloat vel[3], float angles[3], intweaponintsubtypeintcmdnuminttickcountintseedint mouse[2])
{  
    if (!
IsFakeClient(client)) return Plugin_Continue;

    
int ActiveWeapon GetEntPropEnt(clientProp_Send"m_hActiveWeapon"); 
    if (
ActiveWeapon == -1)  return Plugin_Continue;

    
int index GetEntProp(ActiveWeaponProp_Send"m_iItemDefinitionIndex");  
    
    if (
index == 43 || index == 44 || index == 45 || index == 46 || index == 48)
    {
        if (
buttons IN_ATTACK && g_bShouldAttack[client]) {
            
// release attack
            
buttons &= ~IN_ATTACK
            
g_bShouldAttack[client] = false;
        }
        else {
            
buttons |= IN_ATTACK

            if (
g_hShouldAttackTimer[client] == null) {
                
CreateTimer(3.0Timer_ShouldAttackGetClientSerial(client));
            }
        }

        return 
Plugin_Changed;
    } else if (
g_hShouldAttackTimer[client] != null) {
        
// kill timer since the client has switch weapon and it's pointless to continue
        
KillTimer(g_hShouldAttackTimer[client], false);
        
g_hShouldAttackTimer[client] = null;
        return 
Plugin_Continue;
    }

    return 
Plugin_Continue;
}

public 
Action Timer_ShouldAttack(Handle timerint serial) {
    
int client GetClientFromSerial(serial);

    
// check if client is the same has the one before when the timer started
    
if (client != 0) {
        
// set variable so next frame knows that client need to release attack
        
g_bShouldAttack[client] = true;
    }

    
g_hShouldAttackTimer[client] = null;
    return 
Plugin_Handled;


Last edited by Mathias.; 03-19-2019 at 18:52.
Mathias. is offline
manicogaming
AlliedModders Donor
Join Date: Aug 2014
Old 03-19-2019 , 19:47   Re: [CS:GO] Force +attack and -attack on bots
Reply With Quote #8

Quote:
Originally Posted by Mathias. View Post
this is just a small example of what they meant by using timer with OnPlayerUseCmd
you will have to clear your timers when client leave or join, on round start etc...

this is untested and I have no clue if it will even work.
PHP Code:
#pragma semicolon 1

#include <sourcemod>
#include <sdktools>

#pragma newdecls required

bool g_bShouldAttack[MAXPLAYERS 1];
Handle g_hShouldAttackTimer[MAXPLAYERS 1];

public 
Action OnPlayerRunCmd(int clientintbuttonsintimpulsefloat vel[3], float angles[3], intweaponintsubtypeintcmdnuminttickcountintseedint mouse[2])
{  
    if (!
IsFakeClient(client)) return Plugin_Continue;

    
int ActiveWeapon GetEntPropEnt(clientProp_Send"m_hActiveWeapon"); 
    if (
ActiveWeapon == -1)  return Plugin_Continue;

    
int index GetEntProp(ActiveWeaponProp_Send"m_iItemDefinitionIndex");  
    
    if (
index == 43 || index == 44 || index == 45 || index == 46 || index == 48)
    {
        if (
buttons IN_ATTACK && g_bShouldAttack[client]) {
            
// release attack
            
buttons &= ~IN_ATTACK
            
g_bShouldAttack[client] = false;
        }
        else {
            
buttons |= IN_ATTACK

            if (
g_hShouldAttackTimer[client] == null) {
                
CreateTimer(3.0Timer_ShouldAttackGetClientSerial(client));
            }
        }

        return 
Plugin_Changed;
    } else if (
g_hShouldAttackTimer[client] != null) {
        
// kill timer since the client has switch weapon and it's pointless to continue
        
KillTimer(g_hShouldAttackTimer[client], false);
        
g_hShouldAttackTimer[client] = null;
        return 
Plugin_Continue;
    }

    return 
Plugin_Continue;
}

public 
Action Timer_ShouldAttack(Handle timerint serial) {
    
int client GetClientFromSerial(serial);

    
// check if client is the same has the one before when the timer started
    
if (client != 0) {
        
// set variable so next frame knows that client need to release attack
        
g_bShouldAttack[client] = true;
    }

    
g_hShouldAttackTimer[client] = null;
    return 
Plugin_Handled;

It works! Once again, Thank you very much!
manicogaming is offline
Mathias.
Veteran Member
Join Date: Aug 2010
Location: Canada is my city
Old 03-19-2019 , 21:08   Re: [CS:GO] Force +attack and -attack on bots
Reply With Quote #9

Quote:
Originally Posted by manicogmaing View Post
It works! Once again, Thank you very much!
Glad I could help, don't forget to clear timers on round start if they aren't
Mathias. is offline
manicogaming
AlliedModders Donor
Join Date: Aug 2014
Old 12-23-2019 , 21:59   Re: [CS:GO] Force +attack and -attack on bots
Reply With Quote #10

Quote:
Originally Posted by Mathias. View Post
Glad I could help, don't forget to clear timers on round start if they aren't
Sorry for reviving such an old thread but I'd like to know how can I make it so that the timer is random for each bot, in other words do I stop all the bots from throwing the nades at the same time?
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 21:13.


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