Events Overview

Socket Events are called whenever a specific action / event happens. There are currently 4 possible types of event that you could listen for:

  • Chat Event

  • Entity Event

  • Team Event

  • Protobuf Event

These will be called by the socket when the respective events occur. Here are some example usages:

listeners.py
from rustplus import EntityEventPayload, TeamEventPayload, ChatEventPayload, ProtobufEvent, ChatEvent, EntityEvent, TeamEvent


@EntityEvent(server_details, 25743493)
async def alarm(event: EntityEventPayload):
    value = "On" if event.value else "Off"
    print(f"Entity has been turned {value}")


@TeamEvent(server_details)
async def team(event: TeamEventPayload):
    print(f"The team leader's steamId is: {event.team_info.leader_steam_id}")


@ChatEvent(server_details)
async def chat(event: ChatEventPayload):
    print(f"{event.message.name}: {event.message.message}")


@ProtobufEvent(server_details)
async def proto(data: bytes):
    print(data)

Entity Event

The entity_event decorator takes an extra parameter of the entity id that you are listening for changes to. The EntityEvent object holds information on the entity:

Name
Description

entity_id

The Entity Id

value

The value of the entity, boolean

capacity

The capacity of the entity

has_protection

Whether the entity is protected by TC

protection_expiry

When the protection by TC will expire

items

The items that the entity contains

Team Event

This event is typically called when the team changes, e.g. a player leaves or joins. The team_event decorator will pass a TeamEvent object as a parameter with the following information:

Name
Description

player_info

The player_id of the changed information

team_info

Chat Event

This event is called when a message is sent to the team chat. It will give you a ChatEvent object when called with this information:

Name
Description

message

Protobuf Event

This event is called when protobuf is received over the websocket connection. This is for monitoring only. You are given the raw bytes of the message as a parameter.

Removing

To remove any listener see:

Last updated

Was this helpful?