-
Notifications
You must be signed in to change notification settings - Fork 83
Quickchat
An example of a bot using quick chat
One of the cool new additions in RLBot V4 is the ability for bots to use quick chats. 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.
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 (even though in a human match, your opponent would never be this nice, smh).
from rlbot.agents.base_agent import BaseAgent
from rlbot.utils.structures.quick_chats import QuickChats
def get_game_score(values):
score = [0, 0] # Index 0 is team0, index 1 is team1
for car in values.gamecars:
score[car.Team] += car.Score.Goals
return score
class QuickChatExampleAgent(BaseAgent):
def __init__(self, name, team, index):
super().__init__(name, team, index)
self.previous_frame_opponent_score = 0
def get_output(self, packet: GameTickPacket) -> SimpleControllerState:
controller = SimpleControllerState()
current_score = get_game_score(values)
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: super().__init__(name, team, index)
calls the __init__
method from the base class (BaseAgent
), and we want to declare self.previous_frame_opponent_score
after the base class is done doing its own stuff.
That's pretty much it for this tutorial. Hopefully no one makes a ToxicBot with quick chats :P.
Blocks_