Skip to main content

Multiplayer Chat

The Multiplayer Chat scaleform provides a customisable chat interface similar to the GTA Online multiplayer chat. It supports different chat scopes, player colours, and message history scrolling.


Enums

ChatScope

Defines the scope or channel of a chat message.

  • C#: ScaleformUI.Scaleforms.ChatScope
  • Lua: ChatScope
ValueNameDescription
0GlobalGlobal chat channel visible to all players.
1TeamTeam-only chat channel.
2AllAlternative channel for all players.
3ClanCrew or clan chat channel.

ChatVisibility / ChatVisible

Defines the visibility state of the chat interface.

  • C#: ScaleformUI.Scaleforms.ChatVisibility
  • Lua: ChatVisible
ValueNameDescription
0HiddenThe chat interface is completely hidden.
1DefaultThe chat interface is visible but not active for typing.
2TypingThe chat interface is active and accepting text input.

MultiplayerChatHandler (C#)

The handler class for managing the multiplayer chat scaleform in C#.

Methods

Load

public async Task Load()

Loads the MULTIPLAYER_CHAT scaleform. This method is awaitable.

SetFocus

public void SetFocus(ChatVisibility visibility, ChatScope scope = ChatScope.Global, string scopeText = "All", string playerName = "", HudColor color = HudColor.HUD_COLOUR_PURE_WHITE)

Sets the visibility state and focus parameters of the chat.

AddMessage

public void AddMessage(string playerName, string message, ChatScope scope, bool teamOnly, HudColor color)

Adds a message to the chat history.

Close

public void Close()

Closes the chat interface and resets the typing state.

Show

public void Show()

Shows the chat interface in the default visibility state.

StartTyping

public void StartTyping()

Activates the chat interface for typing.

Hide

public void Hide()

Hides the chat interface.

Reset

public void Reset()

Clears all messages and resets the chat scaleform.

PageUp

public void PageUp()

Scrolls the chat history up. Only works when typing.

PageDown

public void PageDown()

Scrolls the chat history down. Only works when typing.

DeleteText

public void DeleteText()

Deletes the last character in the input field. Only works when typing.

AddText

public void AddText(string text)

Appends text to the input field. Only works when typing.

CompleteText

public void CompleteText()

Completes the text input and adds the message locally. Only works when typing.

AbortText

public void AbortText()

Aborts the current text input. Only works when typing.

IsTyping

public bool IsTyping()

Returns whether the player is currently typing in the chat.

SetDuration

public void SetDuration(int duration)

Sets the duration in milliseconds that the chat remains visible after a message is received.

Update

public void Update()

Renders the chat scaleform and handles the visibility timeout. Call this in a tick loop.


MultiplayerChat (Lua)

The class for managing the multiplayer chat scaleform in Lua.

Constructor

MultiplayerChat.New

MultiplayerChat.New()

Creates a new multiplayer chat instance.

Methods

Load

MultiplayerChat:Load()

Loads the MULTIPLAYER_CHAT scaleform. Returns a promise.

SetFocus

MultiplayerChat:SetFocus(visibleState, scopeType, scopeText, playerName, colour)

Sets the visibility state and focus parameters of the chat.

Show

MultiplayerChat:Show()

Shows the chat interface in the default visibility state.

StartTyping

MultiplayerChat:StartTyping(scopeType, scopeText)

Activates the chat interface for typing.

PageUp

MultiplayerChat:PageUp()

Scrolls the chat history up.

PageDown

MultiplayerChat:PageDown()

Scrolls the chat history down.

DeleteText

MultiplayerChat:DeleteText()

Deletes the last character in the input field.

SetTypingDone

MultiplayerChat:SetTypingDone()

Resets the typing state.

AddMessage

MultiplayerChat:AddMessage(playerName, message, scope, teamOnly, playerColour)

Adds a message to the chat history.

AddText

MultiplayerChat:AddText(text)

Appends text to the input field. You can pass "ENTER", "BACKSPACE", or "ESCAPE" to trigger corresponding actions.

Close

MultiplayerChat:Close()

Closes the chat interface.

CompleteText

MultiplayerChat:CompleteText()

Completes the text input and adds the message locally.

AbortText

MultiplayerChat:AbortText()

Aborts the current text input.

Reset

MultiplayerChat:Reset()

Clears all messages and resets the chat scaleform.

IsEnabled

MultiplayerChat:IsEnabled()

Returns whether the chat interface is currently active or visible.

IsTyping

MultiplayerChat:IsTyping()

Returns whether the player is currently typing in the chat.

Update

MultiplayerChat:Update()

Renders the chat scaleform and handles the visibility timeout. Call this in a thread loop.

Dispose

MultiplayerChat:Dispose()

Disposes the chat scaleform.


Examples

C# Example

This example demonstrates how to load the multiplayer chat, add messages, and handle input to toggle typing mode.

using System;
using System.Threading.Tasks;
using CitizenFX.Core;
using CitizenFX.Core.Native;
using ScaleformUI.Scaleforms;

public class ChatTest : BaseScript
{
private MultiplayerChatHandler _chat;

public ChatTest()
{
_chat = new MultiplayerChatHandler();
Tick += OnTick;
}

private async Task OnTick()
{
if (_chat == null) return;

// Load the scaleform if it's not loaded yet
await _chat.Load();

// Render the chat scaleform every frame
_chat.Update();

// Press T to start typing
if (API.IsControlJustPressed(0, 245)) // INPUT_MP_TEXT_CHAT_ALL
{
if (!_chat.IsTyping())
{
_chat.StartTyping();
_chat.SetFocus(ChatVisibility.Typing, ChatScope.Global, "All", Game.Player.Name, HudColor.HUD_COLOUR_BLUE);
}
}

// Press ESC to close chat if typing
if (_chat.IsTyping() && API.IsControlJustPressed(0, 200)) // INPUT_FRONTEND_PAUSE_ALTERNATE
{
_chat.AbortText();
_chat.Close();
}

// Example command to add a test message
if (API.IsControlJustPressed(0, 38)) // INPUT_CONTEXT
{
_chat.AddMessage("System", "Welcome to the server!", ChatScope.Global, false, HudColor.HUD_COLOUR_GOLD);
}
}
}

Lua Example

This example demonstrates how to load the multiplayer chat, add messages, and handle input to toggle typing mode in Lua.

local chat = MultiplayerChat.New()

Citizen.CreateThread(function()
-- Load the scaleform
chat:Load()

while true do
Citizen.Wait(0)

-- Render the chat scaleform every frame
chat:Update()

-- Press T to start typing
if IsControlJustPressed(0, 245) then -- INPUT_MP_TEXT_CHAT_ALL
if not chat:IsTyping() then
chat:StartTyping(ChatScope.Global, "All")
end
end

-- Press ESC to close chat if typing
if chat:IsTyping() and IsControlJustPressed(0, 200) then -- INPUT_FRONTEND_PAUSE_ALTERNATE
chat:AbortText()
chat:Close()
end

-- Example key press (E) to add a test message
if IsControlJustPressed(0, 38) then -- INPUT_CONTEXT
chat:AddMessage("System", "Welcome to the server!", ChatScope.Global, false, HudColours.HUD_COLOUR_GOLD)
end
end
end)