Skip to content

feat(server): add SET_PLAYER_NAME native and onPlayerNameChanged event - #4127

Open
xalva98 wants to merge 1 commit into
citizenfx:masterfrom
xalva98:backport-setplayername-legacy
Open

feat(server): add SET_PLAYER_NAME native and onPlayerNameChanged event#4127
xalva98 wants to merge 1 commit into
citizenfx:masterfrom
xalva98:backport-setplayername-legacy

Conversation

@xalva98

@xalva98 xalva98 commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Goal of this PR

Make the enhanced SET_PLAYER_NAME native and the onPlayerNameChanged event available on
legacy GTA5 and RedM.

How is this PR achieving the goal

The native sets the name on fx::Client, so GET_PLAYER_NAME and everything built on it change
immediately. Names are normalized exactly like connection-time names are (200 byte limit, invalid
UTF-8 replaced), factored out of initConnect into fx::NormalizePlayerName and shared by both
paths.

Clients keep their own netId-to-name map that the game's name lookup is hooked into, so the rename
is broadcast as onPlayerNameChanged and citizen-playernames-five / -rdr3 update just that
name. Re-sending onPlayerJoining would also recreate the physical player, hence the separate
event.

Server-side scripts get onPlayerNameChanged(source, oldName, newName, resourceName). Native name,
event name and arguments match the enhanced API.

This PR applies to the following area(s)

FiveM, RedM, Natives, FxServer

Successfully tested on

Game builds: 3258 (FiveM), 1491 (RedM), FxServer
Platforms: Windows

Tested thoroughly on both games, client and server, with the test resource attached below: renaming
during playerConnecting and after joining, all return values, the length limit, invalid UTF-8, the
event arguments, and the client-side name matching the server in the player list and overhead tags.
No issues found.

setplayername_test.zip

Checklist

  • Code compiles and has been tested successfully.
  • Code is properly formatted and follows the existing style.
  • Commit message is clear and follows the project conventions.
  • This PR introduces no new compilation warnings.

Adds a server native to change a player's name at runtime, usable during
playerConnecting and afterwards. The name is normalized the same way
connection-time names are (200 byte limit, invalid UTF-8 replaced), which is
factored out into fx::NormalizePlayerName.

The rename is replicated to clients using an onPlayerNameChanged event that only
updates the netId-to-name map, instead of re-sending onPlayerJoining which would
also re-create the physical player down the stack.
@github-actions github-actions Bot added RedM Issues/PRs related to RedM invalid Requires changes before it's considered valid and can be (re)triaged labels Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

invalid Requires changes before it's considered valid and can be (re)triaged RedM Issues/PRs related to RedM

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant