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

Solved [TF2] Prevent Bots from Moving or Attacking


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
PC Gamer
Veteran Member
Join Date: Mar 2014
Old 08-12-2020 , 22:18   [TF2] Prevent Bots from Moving or Attacking
Reply With Quote #1

What is the best method of making all TF2 Bots stop moving and attacking?

I tried the server command of 'nb_blind 1'. I tried adding condition 87. I tried adding the no attack attribute to Bot weapons. I tried the Freeze command. These either didn't work or only partially worked.

I ended up making the script below. It prevents the Bots from moving and it removes their weapons so they can't attack. It just seems like a hacky way of doing it.

Is there a better way of preventing Bots from moving and attacking that allows them to keep their weapons?

Code:
PHP Code:
#include <sourcemod>
#include <tf2_stocks> 

#pragma semicolon 1
#pragma newdecls required

#define PLUGIN_VERSION "1.0"

public Plugin myinfo 
{
    
name "Bots Chill/Attack",
    
author "PC Gamer",
    
description "Prevents Bots from moving or attacking",
    
version PLUGIN_VERSION,
    
url "https://www.alliedmods.net"
}

public 
void OnPluginStart() 
{    
    
RegAdminCmd("sm_botschill"Command_BotsChillADMFLAG_SLAY"Make Bots Chill");
    
RegAdminCmd("sm_botsattack"Command_BotsAttackADMFLAG_SLAY"Make Bots Attack");    
}

public 
Action Command_BotsChill(int clientint args)
{
    
ReplyToCommand(client"Bots are now Chill and won't move or attack.");
    
ReplyToCommand(client"Use sm_botsattack to make them move/attack again");    
    
PrintToChatAll("Bots have been forced to Chill. They no longer move or attack");
    
    
int i;
    for (
1<= MaxClientsi++)
    {
        if(
IsClientInGame(i) && IsFakeClient(i))
        {
            
SetEntityMoveType(iMOVETYPE_NONE);
            
TF2_RemoveWeaponSlot(i0);
            
TF2_RemoveWeaponSlot(i1);            
            
TF2_RemoveWeaponSlot(i2);    
            
SetEntPropEnt(iProp_Send"m_hActiveWeapon", -1);
        }
    }

    return 
Plugin_Handled;
}

public 
Action Command_BotsAttack(int clientint args)
{
    
ReplyToCommand(client"Bots are now moving and attacking.");
    
ReplyToCommand(client"Use sm_botschill to make them stop attacking again");
    
PrintToChatAll("Bots are no longer Chill.  They will now move and attack");

    
int i;
    for (
1<= MaxClientsi++)
    {
        if(
IsClientInGame(i) && IsFakeClient(i))
        {
            
SetEntityMoveType(iMOVETYPE_WALK);
            
TF2_RegeneratePlayer(i);            
        }
    }

    return 
Plugin_Handled;


Last edited by PC Gamer; 02-02-2021 at 23:18.
PC Gamer is offline
FroGeX
Senior Member
Join Date: Aug 2020
Old 01-23-2021 , 03:01   Re: [TF2] Prevent Bots from Moving or Attacking
Reply With Quote #2

bot_stop 1 not work in TF2?
FroGeX is offline
PC Gamer
Veteran Member
Join Date: Mar 2014
Old 01-23-2021 , 17:21   Re: [TF2] Prevent Bots from Moving or Attacking
Reply With Quote #3

Quote:
Originally Posted by FroGeX View Post
bot_stop 1 not work in TF2?
bot_stop is an unknown command in TF2
PC Gamer is offline
ThatKidWhoGames
Veteran Member
Join Date: Jun 2013
Location: IsValidClient()
Old 02-02-2021 , 21:04   Re: [TF2] Prevent Bots from Moving or Attacking
Reply With Quote #4

You might be able to do something along the lines of hooking button presses for bots with OnPlayerRunCmd and blocking them (completely untested though).

Last edited by ThatKidWhoGames; 02-02-2021 at 21:04.
ThatKidWhoGames is offline
nosoop
Veteran Member
Join Date: Aug 2014
Old 02-02-2021 , 22:31   Re: [TF2] Prevent Bots from Moving or Attacking
Reply With Quote #5

Quote:
Originally Posted by PC Gamer View Post
bot_stop is an unknown command in TF2
It should be nb_stop for TF.

The leaked source suggests that you can also apply the FL_FROZEN entity flag, or you can prevent the bot from being flagged for updates (getting the member variable for that is an exercise left to you, since it's inlined), or you can supercede NextBotManager::ShouldUpdate() entirely.

Setting the next think time might also work since it's controlled by the think system, but I've tested exactly zero of these.
__________________
I do TF2, TF2 servers, and TF2 plugins.
I don't do DMs over Discord -- PM me on the forums regarding inquiries.
AlliedModders Releases / Github / TF2 Server / Donate (BTC / BCH / coffee)

Last edited by nosoop; 02-02-2021 at 22:39.
nosoop is offline
PC Gamer
Veteran Member
Join Date: Mar 2014
Old 02-02-2021 , 23:18   Re: [TF2] Prevent Bots from Moving or Attacking
Reply With Quote #6

Thanks ThatKidWhoGames! I generally avoid using OnPlayerRunCmd because of the resource drain but in this case I think it is probably the best option.

Thanks nosoop! As usual, great answer. I just tested the nb_stop command. I can confirm that it mostly works but I didn't like the results. When enabled the Bots still move until they reach a map barrier or wall. I was hoping for an immediate stop. I also noticed a Pyro continuing to use his flamethrower and a Demoman with shield continued to charge, even after hitting a wall. I previously tested FL_FROZEN and found that it worked as desired as far as the player not moving or firing. However, made the targets turn blue.

I developed and tested a solution using the recommendation from ThatKidWhoGames and it works well. The Bots stop moving immediately. They keep their weapons. They don't attack. Here's the working solution for anyone that is interested:
PHP Code:
#include <sourcemod>
#include <tf2_stocks> 

#pragma semicolon 1
#pragma newdecls required

bool g_bBotsAreChill false;

#define PLUGIN_VERSION "1.1"

public Plugin myinfo 
{
    
name "Bots Chill/Attack",
    
author "PC Gamer",
    
description "Prevents Bots from moving or attacking",
    
version PLUGIN_VERSION,
    
url "https://www.alliedmods.net"
}

public 
void OnPluginStart() 
{    
    
RegAdminCmd("sm_botschill"Command_BotsChillADMFLAG_SLAY"Make Bots Chill");
    
RegAdminCmd("sm_botsattack"Command_BotsAttackADMFLAG_SLAY"Make Bots Attack");    
}

public 
Action Command_BotsChill(int clientint args)
{
    
ReplyToCommand(client"Bots are now Chill and won't move or attack.");
    
ReplyToCommand(client"Use sm_botsattack to make them move/attack again");    
    
PrintToChatAll("Bots have been forced to Chill. They no longer move or attack");

    
g_bBotsAreChill true;
    
    
int i;
    for (
1<= MaxClientsi++)
    {
        if(
IsClientInGame(i) && IsFakeClient(i))
        {
            
SetEntityMoveType(iMOVETYPE_NONE);
        }
    }

    return 
Plugin_Handled;
}

public 
Action Command_BotsAttack(int clientint args)
{
    
ReplyToCommand(client"Bots are now moving and attacking.");
    
ReplyToCommand(client"Use sm_botschill to make them stop attacking again");
    
PrintToChatAll("Bots are no longer Chill.  They will now move and attack");
    
    
g_bBotsAreChill false;
    
    
int i;
    for (
1<= MaxClientsi++)
    {
        if(
IsClientInGame(i) && IsFakeClient(i))
        {
            
SetEntityMoveType(iMOVETYPE_WALK);
            
TF2_RegeneratePlayer(i);            
        }
    }

    return 
Plugin_Handled;
}

public 
Action OnPlayerRunCmd(int clientint &buttonsint &impulsefloat vel[3], float angles[3], int &weapon

    if (
g_bBotsAreChill == true && IsFakeClient(client)) 
    { 
        if(
buttons IN_ATTACK || buttons IN_ATTACK2 || buttons IN_ATTACK3)         
        { 
            return 
Plugin_Handled;
        }
    }
    
    return 
Plugin_Continue;    

PC Gamer is offline
Pelipoika
Veteran Member
Join Date: May 2012
Location: Inside
Old 02-03-2021 , 03:47   Re: [TF2] Prevent Bots from Moving or Attacking
Reply With Quote #7

nb_player_move 0
tf_bot_fire_weapon_allowed 0
nb_blind 1 ?
__________________

Last edited by Pelipoika; 02-03-2021 at 03:47.
Pelipoika is offline
Reply


Thread Tools
Display Modes

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 03:21.


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