Text chat
GAMPEON ships a chat resource that works like the one in FiveM. Players press T in the game, type and press Enter. Text goes to everyone on the server, and text that starts with / runs a command.
ensure chatset chat_maxLength 256 # optional, 1 to 512 charactersIn the game
Section titled “In the game”- T opens the chat, Enter sends, Escape closes.
- New lines appear at the top left and fade out after 10 seconds.
- When you type
/, the chat shows matching commands with their help text. - Colour codes like
^1and HTML from FiveM templates are removed, because the chat shows plain text.
How a message travels
Section titled “How a message travels”- The game sends what the player typed to the server as
_chat:messageEntered. - The server trims the text to
chat_maxLengthand allows 5 messages per player in 10 seconds. - It fires the local server event
chatMessagewithsource, the player’s name and the text. - If no handler called
CancelEvent(), it sends the line to every player and prints it in the server console.
The name always comes from the player’s GAMPEON account. Players cannot send messages under another name.
Server scripts can filter or replace messages:
AddEventHandler('chatMessage', function(source, name, message) if message:lower():find('free gampeons') then CancelEvent() TriggerClientEvent('chat:addMessage', source, { color = { 255, 140, 0 }, args = { 'Server', 'Please do not post scams.' }, }) endend)Commands in chat
Section titled “Commands in chat”/name arguments runs the command name:
- Commands that client scripts registered with
RegisterCommandrun first, in the player’s game. - Any other command goes to the server and runs there as the player, with the player’s permissions. A restricted command the player may not use does nothing, and the game log shows
Access denied for command 'name'.
When a player joins, the chat lists the server’s commands that this player may use as suggestions. Add help text or client commands with chat:addSuggestion.
On servers whose client scripts the game blocks (see Which servers may send client scripts), only /commands work.
Events
Section titled “Events”Send these to players from server scripts with TriggerClientEvent, or fire them in client scripts with TriggerEvent.
| Event | Arguments | Effect |
|---|---|---|
chat:addMessage |
{ args = { author, text }, color = { r, g, b } } |
Adds a line. A plain string works too. |
chat:addMessage |
{ template = '{0} paid {1}', args = { 'Ann', '20' } } |
Adds a line built from the template. |
chatMessage |
author, { r, g, b }, text |
Adds a line, the older FiveM form. |
chat:addSuggestion |
'/name', 'help' |
Shows the command with help text while typing /. |
chat:addSuggestions |
{ { name = '/a', help = '…' }, … } |
Several suggestions at once. |
chat:removeSuggestion |
'/name' |
Removes a suggestion. |
chat:clear |
Clears the chat. |
RegisterCommand('announce', function(source, args) TriggerClientEvent('chat:addMessage', -1, { color = { 255, 200, 0 }, args = { 'Announcement', table.concat(args, ' ') }, })end, true)chat:addTemplate exists so FiveM resources do not fail, but it does nothing: the chat has no web interface.
Your own chat window
Section titled “Your own chat window”Games built on GAMPEON can draw their own chat instead of the built-in window. The chat resource stays the same; only the window changes.
- Turn the built-in window off with
BuiltInChat=Falseunder[GampeonScripting]inDefaultGame.ini. UGampeonClientScriptinghasOnChatMessage,OnChatClearedandOnChatSuggestionfor Blueprints and C++, andSubmitChatto send what the player typed.
Client scripts can also write to the chat window directly with Gampeon.ChatAddMessage and the other chat functions. Most resources should use the events above instead, so they also work with other chat resources.
Test without the game
Section titled “Test without the game”gp_fakeplayer say <id> <text> in gampeon-server types into the chat of a fake player that joined with gp_fakeplayer client. Chat lines that reach the player are printed as [client <id>/chatbox].
Compared to FiveM
Section titled “Compared to FiveM”- Same events and the same
chatMessagewithCancelEvent(). - The chat shows plain text: no HTML, no colour codes inside a line, no templates with styling.
- Suggestions list the command and its help text, without the parameter list.