Skip to content
Blocks edited this page Dec 18, 2018 · 15 revisions

An example of a bot using quick chat

Basics

Let's take a look at how to implement quick chats.

from rlbot.agents.base_agent import BaseAgent
from rlbot.utils.structures.quick_chats import QuickChats


class QuickChatExampleAgent(BaseAgent):
    def get_output(self, packet: GameTickPacket) -> SimpleControllerState:
        controller = SimpleControllerState()
        self.send_quick_chat(QuickChats.CHAT_EVERYONE, QuickChats.Reactions_Wow)

        return controller

This is just a simple example that spams "Wow!" until chat gets temporarily disabled for the bot.

We must import QuickChats from the rlbot module in order to use quick chats (line 2). The method send_quick_chat (line 7) exists in the BaseAgent class, so our QuickChatExampleAgent automatically inherits this class method when deriving from BaseAgent.

The first parameter of send_quick_chat is the visibility of our chat message we're going to send. This is a bool (True for team-only or False for everyone), but it is recommended to use QuickChat.CHAT_TEAM_ONLY, QuickChat.CHAT_EVERYONE, or QuickChat.CHAT_NONE instead for clarity's sake.

The second parameter of send_quick_chat is the actual message of the chat message. A few examples are Information_IGotIt, Compliments_GreatClear, Reactions_Calculated, Apologies_NoProblem, or PostGame_Gg. You can find the full list here.

Realistic Example

Now that we've covered how to send quick chats, let's take a look at an example that sends "Nice shot!" whenever the other team scores against the bot.

from rlbot.agents.base_agent import BaseAgent
from rlbot.utils.structures.quick_chats import QuickChats


def get_game_score(packet: GameTickPacket):
    score = [0, 0]  # Index 0 is team0, index 1 is team1

    for car in packet.game_cars:
        score[car.team] += car.score_info.goals

    return score


class QuickChatExampleAgent(BaseAgent):
    def initialize_agent():
        self.previous_frame_opponent_score = 0

    def get_output(self, packet: GameTickPacket) -> SimpleControllerState:
        controller = SimpleControllerState()

        current_score = get_game_score(packet)
        if self.previous_frame_opponent_score < current_score[not self.team]:
            self.send_quick_chat(QuickChats.CHAT_EVERYONE, QuickChats.Compliments_NiceShot)

        self.previous_frame_opponent_score = current_score[not self.team]

        return controller

We've implemented the get_game_score function since RLBot doesn't provide a value that shows the team's overall goals, but just individual goals. We use self.previous_frame_opponent_score so that we can see if the other team's score has increased. We send the quick chat message if the opponent's score has increased since last frame.

Note: initialize_agent is called after the bot is ready to start. This is when we want to declare variables like self.previous_frame_opponent_score. It is recommended to use initialize_agent instead of overriding __init__ and calling super, because the bot may not be fully ready (e.g. self.get_field_info will not work) when the bot object is being created.

Clone this wiki locally