> Agent-readable docs index: /llms.txt. Download /docs.zip to grep all markdown files locally.

---
title: Protocol Buffers
icon: code
---

# <ApiPageIcon icon="code" />Protocol Buffers

<ApiExposes data="[{&#x22;k&#x22;:&#x22;OBJECT&#x22;,&#x22;c&#x22;:&#x22;method&#x22;,&#x22;s&#x22;:&#x22;protobuf.MessageWrapper&#x22;,&#x22;h&#x22;:&#x22;#protobufmessagewrapper&#x22;},{&#x22;k&#x22;:&#x22;NAMESPACE&#x22;,&#x22;c&#x22;:&#x22;fn&#x22;,&#x22;s&#x22;:&#x22;protobuf&#x22;,&#x22;h&#x22;:&#x22;#protobuf&#x22;}]" />

## protobuf.MessageWrapper<ApiTag label="object type" />

A protobuf message, such as the message that a `usermsg_*` event passes. Read its fields by
name. A field that the message does not declare reads as **nil**. A repeated field reads as a
table, and a field that holds a message reads as another `protobuf.MessageWrapper`.

`pairs` goes over every field that the message declares. `tostring` returns
`protobuf.Message<Name>`, where `Name` is the name of the message type.

## protobuf<ApiTag label="global table" />

Shows the game's own user messages on the local client. The messages are not sent to the
server or to other players.

<ApiMembers>
  <ApiMember kind="fn" name="protobuf.TextMsg" summary="Shows a `TextMsg` message on the local client, in the same way as the game shows its own status messages." args="dest, msg, param1?, param2?, param3?, param4?" sig="[{&#x22;s&#x22;:&#x22;protobuf.TextMsg&#x22;},{&#x22;s&#x22;:&#x22;(&#x22;},{&#x22;s&#x22;:&#x22;dest&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;protobuf.HudPrintDest&#x22;,&#x22;k&#x22;:&#x22;class&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/networking/protobuf#protobuf-HudPrintDest&#x22;},{&#x22;s&#x22;:&#x22;, &#x22;},{&#x22;s&#x22;:&#x22;msg&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;},{&#x22;s&#x22;:&#x22;[, &#x22;},{&#x22;s&#x22;:&#x22;param1&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;},{&#x22;s&#x22;:&#x22;, &#x22;},{&#x22;s&#x22;:&#x22;param2&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;},{&#x22;s&#x22;:&#x22;, &#x22;},{&#x22;s&#x22;:&#x22;param3&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;},{&#x22;s&#x22;:&#x22;, &#x22;},{&#x22;s&#x22;:&#x22;param4&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;},{&#x22;s&#x22;:&#x22;]&#x22;},{&#x22;s&#x22;:&#x22;)&#x22;}]" params="[{&#x22;n&#x22;:&#x22;dest&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;protobuf.HudPrintDest&#x22;,&#x22;k&#x22;:&#x22;class&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/networking/protobuf#protobuf-HudPrintDest&#x22;}],&#x22;d&#x22;:&#x22;The place where the message is shown. Any other value throws an error.&#x22;},{&#x22;n&#x22;:&#x22;msg&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;}],&#x22;d&#x22;:&#x22;The text to show, or a localization token that starts with `#`.&#x22;},{&#x22;n&#x22;:&#x22;param1&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;}],&#x22;d&#x22;:&#x22;The first parameter.&#x22;,&#x22;o&#x22;:true},{&#x22;n&#x22;:&#x22;param2&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;}],&#x22;d&#x22;:&#x22;The second parameter.&#x22;,&#x22;o&#x22;:true},{&#x22;n&#x22;:&#x22;param3&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;}],&#x22;d&#x22;:&#x22;The third parameter.&#x22;,&#x22;o&#x22;:true},{&#x22;n&#x22;:&#x22;param4&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;}],&#x22;d&#x22;:&#x22;The fourth parameter.&#x22;,&#x22;o&#x22;:true}]">
    <ApiNotes>
      `msg` is plain text or a localization token that starts with `#`. The token can contain the
      placeholders `%s1`, `%s2`, `%s3` and `%s4`. They are replaced by `param1`, `param2`, `param3`
      and `param4`. Parameters that are **nil** are skipped, so the parameters after them move up by
      one place.
    </ApiNotes>
  </ApiMember>

  <ApiMember kind="fn" name="protobuf.SayText" summary="Shows a `SayText` chat line on the local client, as if the given player sent it." args="chat, entity?, text" sig="[{&#x22;s&#x22;:&#x22;protobuf.SayText&#x22;},{&#x22;s&#x22;:&#x22;(&#x22;},{&#x22;s&#x22;:&#x22;chat&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;boolean&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#boolean&#x22;},{&#x22;s&#x22;:&#x22;[, &#x22;},{&#x22;s&#x22;:&#x22;entity&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;Entity&#x22;,&#x22;k&#x22;:&#x22;class&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/engine/entity#entity-1&#x22;},{&#x22;s&#x22;:&#x22;]&#x22;},{&#x22;s&#x22;:&#x22;, &#x22;},{&#x22;s&#x22;:&#x22;text&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;},{&#x22;s&#x22;:&#x22;)&#x22;}]" params="[{&#x22;n&#x22;:&#x22;chat&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;boolean&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#boolean&#x22;}],&#x22;d&#x22;:&#x22;Pass `true` to show the line in the chat. Pass `false` to show it only in the console.&#x22;},{&#x22;n&#x22;:&#x22;entity&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;Entity&#x22;,&#x22;k&#x22;:&#x22;class&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/engine/entity#entity-1&#x22;}],&#x22;d&#x22;:&#x22;The player who sent the line. Pass **nil** for a message without a sender.&#x22;,&#x22;o&#x22;:true},{&#x22;n&#x22;:&#x22;text&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;}],&#x22;d&#x22;:&#x22;The line to show.&#x22;}]" />

  <ApiMember kind="fn" name="protobuf.SayText2" summary="Shows a `SayText2` chat line on the local client. This is the localized and formatted form of a chat message." args="chat, entity, messagename, param1?, param2?, param3?, param4?" sig="[{&#x22;s&#x22;:&#x22;protobuf.SayText2&#x22;},{&#x22;s&#x22;:&#x22;(&#x22;},{&#x22;s&#x22;:&#x22;chat&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;boolean&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#boolean&#x22;},{&#x22;s&#x22;:&#x22;, &#x22;},{&#x22;s&#x22;:&#x22;entity&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;Entity&#x22;,&#x22;k&#x22;:&#x22;class&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/engine/entity#entity-1&#x22;},{&#x22;s&#x22;:&#x22;, &#x22;},{&#x22;s&#x22;:&#x22;messagename&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;},{&#x22;s&#x22;:&#x22;[, &#x22;},{&#x22;s&#x22;:&#x22;param1&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;},{&#x22;s&#x22;:&#x22;, &#x22;},{&#x22;s&#x22;:&#x22;param2&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;},{&#x22;s&#x22;:&#x22;, &#x22;},{&#x22;s&#x22;:&#x22;param3&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;},{&#x22;s&#x22;:&#x22;, &#x22;},{&#x22;s&#x22;:&#x22;param4&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;},{&#x22;s&#x22;:&#x22;]&#x22;},{&#x22;s&#x22;:&#x22;)&#x22;}]" params="[{&#x22;n&#x22;:&#x22;chat&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;boolean&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#boolean&#x22;}],&#x22;d&#x22;:&#x22;Pass `true` to show the line in the chat. Pass `false` to show it only in the console.&#x22;},{&#x22;n&#x22;:&#x22;entity&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;Entity&#x22;,&#x22;k&#x22;:&#x22;class&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/engine/entity#entity-1&#x22;}],&#x22;d&#x22;:&#x22;The player controller who sent the line.&#x22;},{&#x22;n&#x22;:&#x22;messagename&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;}],&#x22;d&#x22;:&#x22;The localization token for the format of the chat line.&#x22;},{&#x22;n&#x22;:&#x22;param1&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;}],&#x22;d&#x22;:&#x22;The first parameter. It is usually the name of the player.&#x22;,&#x22;o&#x22;:true},{&#x22;n&#x22;:&#x22;param2&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;}],&#x22;d&#x22;:&#x22;The second parameter. It is usually the text of the message.&#x22;,&#x22;o&#x22;:true},{&#x22;n&#x22;:&#x22;param3&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;}],&#x22;d&#x22;:&#x22;The third parameter.&#x22;,&#x22;o&#x22;:true},{&#x22;n&#x22;:&#x22;param4&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;}],&#x22;d&#x22;:&#x22;The fourth parameter.&#x22;,&#x22;o&#x22;:true}]">
    <ApiNotes>
      `messagename` is a localization token, for example `Cstrike_Chat_All`. The placeholders `%s1`,
      `%s2`, `%s3` and `%s4` in the token are replaced by `param1`, `param2`, `param3` and `param4`.
    </ApiNotes>
  </ApiMember>

  <ApiMember kind="type" name="protobuf.HudPrintDest" summary="The place where `protobuf.TextMsg` shows a message. The values are the game's own `HUD_PRINT*` constants." ret="[[{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}]]">
    <ApiEnum name="protobuf.HudPrintDest" values="[[&#x22;HUD_PRINTCONSOLE&#x22;,&#x22;1&#x22;,&#x22;The console.&#x22;],[&#x22;HUD_PRINTCONSOLE2&#x22;,&#x22;2&#x22;,&#x22;The console. It looks the same as `HUD_PRINTCONSOLE`.&#x22;],[&#x22;HUD_PRINTTALK&#x22;,&#x22;3&#x22;,&#x22;The chat.&#x22;],[&#x22;HUD_PRINTTALK2&#x22;,&#x22;5&#x22;,&#x22;The chat. It looks the same as `HUD_PRINTTALK`.&#x22;],[&#x22;HUD_PRINTHINT&#x22;,&#x22;4&#x22;,&#x22;A hint with low priority, in the team colour.&#x22;],[&#x22;HUD_PRINTHINTERROR&#x22;,&#x22;6&#x22;,&#x22;A hint with high priority, in red.&#x22;]]" />
  </ApiMember>
</ApiMembers>
