CityRP Documentation Repository

cityrp.player

Server-side player library: name validation, player lookup/resolution, networked player-data replication, database save queries, and the per-tick player update loop.

Functions

Servercityrp.player.get(name) → boolean|Player, boolean|table<number, Player>Source ☍

Finds a player by exact UserID, a STEAM_ SteamID, an exact name, or a case-insensitive partial name match. An exact name wins outright: "Josh" resolves to Josh even while Joshua, whose name contains it, is connected.

Parameters

Returns

  1. 1boolean|PlayerThe single matched player, or false if none or more than one matched.
  2. 2boolean|table<number, Player>The list of matched players, or false if none matched.
Servercityrp.player.getDataKeyValues(player) → string, stringSource ☍

Builds a MySQL-escaped, comma-separated column list and matching value list for a player's saved fields. Intended for building an INSERT statement (see cityrp.player.getDataUpdateQuery for UPDATE).

Parameters

  • playerPlayerThe player to build the key/value lists for.

Returns

  1. 1stringThe comma-separated column names.
  2. 2stringThe comma-separated, quoted and escaped values, in the same order as keys.
Servercityrp.player.getDataUpdateQuery(player) → stringSource ☍

Builds an UPDATE query saving a player's data, guarded by an optimistic _TimePlayed check. Saves a reduced column set on build/event servers or when saving is disabled.

Parameters

  • playerPlayerThe player to build the update query for.

Returns

  1. stringThe full UPDATE ... WHERE SQL statement.
Servercityrp.player.getid(steamid) → boolean|PlayerSource ☍

Finds a player by exact SteamID.

Parameters

  • steamidstringA STEAM_-prefixed SteamID.

Returns

  1. boolean|PlayerThe matched player, or false if none matched or steamid was not STEAM_-prefixed.
Servercityrp.player.getig(name) → boolean|Player, boolean|table<number, Player>Source ☍

Finds a human player by exact UserID, exact RP name, or a case-insensitive partial in-game name match.

Parameters

  • namestring|nilThe search term.

Returns

  1. 1boolean|PlayerThe single matched player, or false if none or more than one matched.
  2. 2boolean|table<number, Player>The list of matched players, or false if none matched.
Servercityrp.player.getplate(plate) → boolean|PlayerSource ☍

Finds a player by their stored vehicle plate.

Parameters

  • platestringThe plate to search for.

Returns

  1. boolean|PlayerThe matched player, or false if none matched.
Servercityrp.player.getuniqueid(uid) → boolean|PlayerSource ☍

Finds a player by exact UniqueID.

Parameters

  • uidstringThe player's UniqueID.

Returns

  1. boolean|PlayerThe matched player, or false if none matched.
Servercityrp.player.isValidIgname(text) → boolean, string|nilSource ☍

Returns whether text may be used as an in-game name.

Parameters

  • textstringThe text to validate.

Returns

  1. 1booleanWhether the text is a valid in-game name.
  2. 2string|nilPlayer-facing rejection reason.
Servercityrp.player.notifyAll(message, class)Source ☍

Notifies every player using Garry's hint messages, and echoes the message to console.

Parameters

  • messagestringThe message to notify.
  • classnumber|nilThe notification class/type passed to ply:Notify.
Servercityrp.player.playerstostring(players) → stringSource ☍

Formats a list of players as a comma-separated "Name(UserID)" string.

Parameters

  • playerstable<number, Player>The players to format.

Returns

  1. stringThe formatted, comma-separated list.
Servercityrp.player.printConsoleAccess(text, access)Source ☍

Prints a message to the console of every player holding the given access flag.

Parameters

Servercityrp.player.printMessageAll(message)Source ☍

Prints a message to every player's chat area and console, and echoes it to server console.

Parameters

  • messagestringThe message to print.
Servercityrp.player.printMessageInRadius(message, position, radius)Source ☍

Prints a message to the chat area and console of every player within a radius of a position.

Parameters

  • messagestringThe message to print.
  • positionVectorThe centre position to measure distance from.
  • radiusnumberThe radius, in units, within which players receive the message.
Servercityrp.player.resolveTarget(caller, arg, silent) → Player|nil, Player[]|nilSource ☍

Resolve a player from a search term (name, UserID, or SteamID). Notifies the caller on failure unless silent is true. Prefer this over hand-rolling cityrp.player.get error handling in commands.

Parameters

  • callerPlayerThe player requesting the lookup.
  • argstringSearch term.
  • silentboolean?If true, do not notify on failure.

Returns

  1. 1Player|nilThe resolved player, or nil.
  2. 2Player[]|nilWhen silent and ambiguous: the list of matches.
Servercityrp.player.sanitizeIgname(text) → stringSource ☍

Strip characters that must not appear in stored in-game names.

Parameters

  • textstringThe text to sanitize.

Returns

  1. stringThe text with semicolons and line breaks removed, or "" if text was not a string.
Servercityrp.player.saveDataAll()Source ☍

Bulk-saves every initialized player's data with a single multi-row INSERT ... ON DUPLICATE KEY UPDATE query. Saves a reduced column set on build/event servers or when saving is disabled.

Servercityrp.player.sendGlobalPlayerData(ply)Source ☍

Broadcasts a player's global player-data table to every client.

Parameters

  • plyPlayerThe player whose data to send.
Servercityrp.player.sendLocalPlayerTable(ply, data)Source ☍

Sends a player's local player-data table to that client in a single net message.

Parameters

  • plyPlayerThe player to send to.
  • datatableThe local player-data table to send.
Servercityrp.player.setIgname(player, text) → boolean, string|nilSource ☍

Assign a player's in-game name after validation.

Parameters

  • playerPlayerThe player to assign the name to.
  • textstringThe in-game name to assign.

Returns

  1. 1booleanWhether the name was successfully assigned.
  2. 2string|nilPlayer-facing rejection reason.
Servercityrp.player.setLocalPlayerVariable(player, class, key, value)Source ☍

Sets a player's local player variable and, if it changed, networks it to that client only.

Parameters

  • playerPlayerThe player to set the variable on and send to.
  • classintegerThe CLASS_* network type constant (see sh_enumerations.lua) determining how value is encoded.
  • keystringThe variable's name.
  • valueanyThe value to set. Coerced to the type's default ("", 0, false, etc) if nil.
Servercityrp.player.UpdateGlobalPlayerData(ply, varname)Source ☍

Broadcasts a single global player-data variable, or the whole table if it hasn't been sent recently.

Parameters

  • plyPlayerThe player whose data changed.
  • varnamestringThe key within ply._clgdata that changed.
Servercityrp.player.updateindividualplayer(v)Source ☍

Runs a player's per-second update: salary, NSVars, fake-identity spoofing for hidden staff, tax, and networked local player variables.

Parameters

  • vPlayerThe player to update.
Servercityrp.player.updateplayers()Source ☍

Think-hooked driver that runs cityrp.player.updateindividualplayer for every player once per second, and fires PlayerTenthSecond every tick.

Serverfl_tablesEqual(tab1, tab2) → booleanSource ☍

Shallow-compares two tables by value, keyed off tab1's entries. For some reason the tables weren't equal when they clearly were

Parameters

  • tab1tableThe table to iterate.
  • tab2tableThe table to compare against.

Returns

  1. booleanWhether every key in tab1 has an equal value in tab2.

Tables

Servercityrp.playerSource ☍
Servercityrp.playerpreloadSource ☍

Fields

Servercityrp.player.lastDisconnectSource ☍

Wall-clock time of each SteamID's most recent disconnect from THIS server. Used to gate the preload against fast-reconnect stale reads (see PlayerAuthed below).

Servercityrp.player.nextSecondSource ☍
ServerdSource ☍