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.
- 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
- namestring|nilThe search term. STEAM_-prefixed values are delegated to cityrp.player.getid.
Returns
- 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
- 1stringThe comma-separated column names.
- 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
_TimePlayedcheck. Saves a reduced column set on build/event servers or when saving is disabled.Parameters
- playerPlayerThe player to build the update query for.
Returns
- stringThe full UPDATE ... WHERE SQL statement.
- Servercityrp.player.getid(steamid) → boolean|PlayerSource ☍
-
Finds a player by exact SteamID.
Parameters
- steamidstringA STEAM_-prefixed SteamID.
Returns
- boolean|PlayerThe matched player, or false if none matched or
steamidwas 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
- Servercityrp.player.getplate(plate) → boolean|PlayerSource ☍
-
Finds a player by their stored vehicle plate.
Parameters
- platestringThe plate to search for.
Returns
- 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
- 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
- 1booleanWhether the text is a valid in-game name.
- 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
- 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
- textstringThe message to print.
- accessstringThe access flag to require (see cityrp.access.hasAccess).
- 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
silentis true. Prefer this over hand-rollingcityrp.player.geterror handling in commands.Parameters
- callerPlayerThe player requesting the lookup.
- argstringSearch term.
- silentboolean?If true, do not notify on failure.
Returns
- Servercityrp.player.sanitizeIgname(text) → stringSource ☍
-
Strip characters that must not appear in stored in-game names.
Parameters
- textstringThe text to sanitize.
Returns
- stringThe text with semicolons and line breaks removed, or "" if
textwas 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
- 1booleanWhether the name was successfully assigned.
- 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
valueis 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._clgdatathat 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
- booleanWhether every key in tab1 has an equal value in tab2.