Raised This Month: $208 Target: $400
 52% 

[TF2] View/Change Bot Difficulty Level


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
PC Gamer
Senior Member
Join Date: Mar 2014
Old 11-21-2019 , 23:09   [TF2] View/Change Bot Difficulty Level
Reply With Quote #1

How would I view and edit a Bot's current difficulty level without removing the bot in Team Fortress 2?

I know you can use something like Dr. McKay's Bot Manager Random Difficulty (link: https://forums.alliedmods.net/showthread.php?p=1983621 )to create random difficulty bots. However, I want to be able to view a Bots difficulty level and change it if desired AFTER a bot is already spawned.

Any ideas?
PC Gamer is offline
nosoop
Veteran Member
Join Date: Aug 2014
Old 11-21-2019 , 23:43   Re: [TF2] View/Change Bot Difficulty Level
Reply With Quote #2

You can read a TFBot's difficulty with the m_nBotSkill netprop.

Setting the difficulty is a bit more... difficult, as that property actually doesn't control the skill level internally. For that you'll have to write to the CTFBot::m_skill property. Offset for that can be found after the CTFPlayer::HandleCommand_JoinTeam() call in the tf_bot_add command or in a few other functions. You'll probably want to modify both that value and the previously mentioned netprop.

This is the gamedata I use:
Code:
"Addresses"
{
	"CTFBot::m_iSkill"
	{
		"linux"
		{
			"signature"		"CTFBotVision::GetMinRecognizeTime()"
			"offset"	"43"	// 0x2B
		}
		"windows"
		{
			// untested since I only run this on linux
			"signature"		"tf_bot_add(CCommand)"
			"offset"	"943"	// 0x3AF
		}
	}
}
And corresponding code:
Code:
Address pSkillOffset = GameConfGetAddress(hGameConf, "CTFBot::m_iSkill");
int offs_CTFBot_iSkill = LoadFromAddress(pSkillOffset, NumberType_Int32);

// make sure the function hasn't changed drastically
if (offs_CTFBot_iSkill & 0xFFFF != offs_CTFBot_iSkill) {
	LogError("Offset read for CTFBot::m_iSkill outside expected range (was %d).  "
			... "Bots will be stuck at normal difficulty.", offs_CTFBot_iSkill);
	offs_CTFBot_iSkill = 0;
}

// ...
SetEntData(bot, offs_CTFBot_iSkill, difficulty);
At the time of writing the Linux / Windows member offsets are 0x25B0 and 0x25B4 respectively.
__________________
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; 11-22-2019 at 00:03.
nosoop is online now
PC Gamer
Senior Member
Join Date: Mar 2014
Old 11-22-2019 , 03:43   Re: [TF2] View/Change Bot Difficulty Level
Reply With Quote #3

Thanks for the help nosoop!

This seems to work well for viewing the Bot skill level:
Code:
int ibotlvl = GetEntProp(target_list[i], Prop_Send, "m_nBotSkill");
ReplyToCommand(client, "Bot %N skill level is: %i", target_list[i], ibotlvl);
And this seems to temporarily work for setting the Bot skill level:
Code:
SetEntProp(target_list[i], Prop_Send, "m_nBotSkill", ibotlvl);
ReplyToCommand(client, "Bot %N skill level is now: %i", target_list[i], ibotlvl);
Unfortunately, the newly set skill level is only temporary. When the round ends or the Bot respawns the skill level will revert back to the orginal unset skill.

I then added the gamedata but that didn't seem to work. I either coded it wrong or the address is bad.
Code:
Spoiler

Last edited by PC Gamer; 11-22-2019 at 03:43.
PC Gamer is offline
nosoop
Veteran Member
Join Date: Aug 2014
Old 11-22-2019 , 17:24   Re: [TF2] View/Change Bot Difficulty Level
Reply With Quote #4

Quote:
Originally Posted by PC Gamer View Post
Unfortunately, the newly set skill level is only temporary. When the round ends or the Bot respawns the skill level will revert back to the orginal unset skill.

I then added the gamedata but that didn't seem to work. I either coded it wrong or the address is bad.
Haven't tested it at runtime myself. No reason why it shouldn't work, though -- I use it in an internal bot manager replacement.

Of course, you'll need the signature corresponding to the given function(s). I omitted them as an exercise for you to find out; I'm not planning on maintaining it across platforms in the event that they do change, but here they are.

Code:
"CTFBotVision::GetMinRecognizeTime()"
{
	"library"		"server"
	"linux"		"@_ZNK12CTFBotVision19GetMinRecognizeTimeEv"
}
"tf_bot_add(CCommand)"
{
	"library"		"server"
	"windows"		"\x55\x8B\xEC\x81\xEC\x24\x01\x00\x00\xE8\x2A\x2A\x2A\x2A"
}
__________________
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)
nosoop is online now
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 07:35.


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