Skip to content
This repository was archived by the owner on Jul 19, 2024. It is now read-only.

A. Custom Bot

Iván Bravo Bravo edited this page Aug 25, 2017 · 2 revisions

SourceBots allows you to create custom Bots that fit the needs of your mod, the code is made to make this process as easy as possible.

You can choose to create an A.I. that inherits from the base code or create your own system from scratch using the available interfaces.

Interfaces

They are located in the folder "interfaces" and are the "guides" of everything that your customized A.I. requires.

IBot

It is the entrance to the system, this is where the magic happens, where the Bot thinks, the components are processed and injected the necessary commands to simulate being a human player. The CBot class uses this interface and contains everything necessary to get the Bot working, but if you are brave you can create your own system using this interface.

IBotComponent

A component that you can add (or not) to add more functionality. To give you an idea, SourceBots includes a series of basic components: Attack, Locomotion, Vision, Memory, etc. There is a specific function in IBot (SetUpComponents) that serves to customize what components your Bot will have, who knows, you may want to create a Bot to control a "Cat character" that only needs to have Vision and Locomotion.

IBotSchedule

Inherited from IBotComponent but serves to create a schedule, a goal that Bot must fulfill based on tasks. If you have worked creating an NPC then it will be easy to understand what a Schedule is like. SourceBots includes basic Schedules such as: Cover, hunt an enemy, reload, investigate a sound, etc. There is a specific function in IBot (SetUpSchedules) that serves to customize what schedules your Bot will have.

Basic Components

Here are the interfaces to create custom basic components:

IBotAttack

Its main use is to inject the necessary commands to attack.

The CBotAttack class contains everything necessary for the Bot to use firearms and melee weapons.

IBotDecision

This component is mandatory, without this component the bot will do nothing (or the game will crash)

Its main use is to offer all the necessary information of what the Bot is capable, that is, almost anything that requires the question "I can? I should?" is here.

The CBotDecision class contains everything necessary for the Bot to shoot, hide and hunt in a decently intelligent way.

IBotFollow

Its main use is to provide the functionality to follow an entity/character.

The CBotFollow class contains everything necessary for this.

IBotLocomotion

Its main use is to provide the functionality to move around the map using Navigation Mesh.

The CBotLocomotion class contains everything necessary for this.

IBotMemory

Its main use is to provide the functionality to store information about the entities we have seen, classify them into enemies, friends and neutrals and also establish our main enemy.

There is a separate memory called "Data Memory" that is used to store information that can be identified with strings, it provides a simple way to save information without having to create new variables. Here are some examples of how to use it:

GetMemory()->UpdateDataMemory( "NearbyFriends", 10 ); // Saved "NearbyFriends" with value "10" forever
GetMemory()->GetDataMemory("NearbyFriends")->GetInt(); // returns 10

GetMemory()->UpdateDataMemory( "HumanPlayer", UTIL_PlayerByIndex(0), 60.0f ); // Saved player for 60 seconds
CBasePlayer *pPlayer = ToBasePlayer( GetMemory()->GetDataMemory( "HumanPlayer" )->GetEntity() );
pPlayer->GetPlayername(); // returns Kolesias

GetMemory()->ForgetData( "HumanPlayer" ); // Forget
GetMemory()->GetDataMemory( "HumanPlayer" ); // returns NULL
GetMemory()->GetDataMemory( "HumanPlayer" )->GetEntity(); // CRASH! (calling GetEntity() on NULL)

GetMemory()->GetDataMemory( "HumanPlayer", true ); // The second parameter forces to create an empty object even if the memory does not exist, ideal for cases where we require a value. (returns empty CDataMemory)
GetMemory()->GetDataMemory( "HumanPlayer", true )->GetEntity(); // returns NULL

The CBotMemory class contains everything necessary.

IBotVision

Its main use is to provide the functionality so that the bot can aim smoothly to an entity or location.

The CBotVision class contains everything necessary for this.

Work in progress...

Clone this wiki locally