Shared part of the cw.player library: registration of networked player and character data types, player net vars and faction rank checks.

cw.player:AddPlayerData and cw.player:AddCharacterData declare data that is networked when it changes, player.Find finds a player by name or Steam ID, and cw.player:CanPromote and cw.player:CanDemote compare faction ranks. This file creates the library, which cl_player.lua and sv_player.lua extend.

Summary

Methods

Registers a character data type that is networked when it changes.
Registers a player data type that is networked when it changes.
Returns whether the player has at least an amount of cash.
Returns whether a player's rank allows them to demote a target.
Returns whether a player can hear another player.
Returns whether the local player's inventory can take some more space.
Returns whether the local player's inventory can take some more weight.
Returns whether a player's rank allows them to promote a target.
Returns whether the player can see an entity.
Returns whether a player can see an NPC.
Returns whether two players can see each other.
Returns whether the player can see a position.
Adds a character to the player's character selection screen.
Shows cinematic text with black bars to the player.
Shows cinematic text to every player who has initialized.
Makes every player forget the player's character.
Makes the player forget the characters they recognise.
Calls back after a delay, as long as a condition stays true the whole time.
Decodes a JSON data string.
Decodes the JSON and numeric fields of a character loaded from the database, in place.
Decodes a saved list of recognised character keys.
Decodes a JSON data string.
Returns a copy of a database row with its column names converted to camel case.
Validates a character creation request and creates the character.
Attaches an item's model to the player as a cw_gear entity.
Deletes one of the player's characters if they are allowed to.
Clears the owner of the player's property while keeping it registered to them.
Returns whether a player recognises another player's character.
Returns whether the player the local player is looking at recognises them.
Starts a timer that makes the ragdoll decay once its player has left.
Drops the player's item weapons as item entities, such as when they die.
Calls back after a delay, as long as the player keeps looking at an entity within range.
Deletes one of the player's characters without asking any hooks first.
Replaces each %s in a text with the name a player knows each given player by.
Returns the accessories the local player is wearing.
Returns the player's current action.
Returns every entity owned as property, removing entries that are no longer valid.
Returns the player's reserve ammo of every item ammo type, without their spawn ammo.
GetCash()client
Returns the local player's cash.
Returns the player's current character.
Returns a character's saved ammo merged with the player's current ammo.
Returns the definition of a registered character data type.
Returns a copy of a character's data, adjusted by the PlayerSaveCharacterData hook.
Returns every character data type registered with cw.player:AddCharacterData.
Returns the slot of the player's current character.
Returns a copy of a character's inventory with the items added by PlayerAddToSavedInventory.
Returns the key of a player's character, used to identify it in recognition data.
Returns the character keys a character recognises at the RECOGNISE_SAVE level, as JSON.
Loads the player's characters for the current schema from the database.
Returns the icon shown next to a player's name in the chat box.
Returns the local player's clothes data as sent by the server.
Returns the clothes item the local player is wearing.
Returns the player's death code.
Returns the player's default model from the GetPlayerDefaultModel hook.
Returns the player's default skin from the GetPlayerDefaultSkin hook.
Returns how many doors the player's current character owns, not counting child doors.
Returns how drunk the player is.
Returns the total item space of the player's equipped weapons.
Returns the total item weight of the player's equipped weapons.
Returns a player's rank within their faction.
Returns the faction table of the player's current faction.
Returns one of the player's gear entities.
Returns the class of an item weapon the player carries but is not holding.
Returns how many characters the player may have.
Returns the maximum space the local player can carry.
Returns the maximum weight the local player can carry.
Returns the name a player knows another player by.
Returns a networked variable of a player.
Returns the player's physical description.
Returns the definition of a registered player data type.
Returns every player data type registered with cw.player:AddPlayerData.
Returns the player's player-wide flags.
Returns how many entities the player's current character owns.
Returns the property of the player's current character.
Returns the player's ragdoll entity.
Returns the player's ragdoll state.
Returns the table with the player's state from before they were ragdolled.
Returns a trace of what the player is looking at, seeing through vehicles and non-solid entities.
Returns free spots on a grid around a position, sorted from nearest to farthest.
Returns the ammo the player was given on spawn.
Returns whether a weapon was given to the player on spawn.
Returns when the player gets up.
Returns what players who do not recognise the player see instead of their name.
Returns the player's wages from the Wages net var.
Returns what the player's wages are called, from their class or the wages_name config.
Returns the class of the player's active weapon.
Returns whether the player's weapon is raised.
Returns a list of the player's weapons that cw.player:SetWeapons can give back, and strips them.
Gives the player ammo from a table of amounts.
Gives cash to the player's character, or takes it with a negative amount.
Gives the player a new random death code and sends it to their client.
Gives a door, and its parent and children, to the player.
Gives the player's current character access to a door.
Gives flags to the player's current character.
Gives the player the weapon of a weapon item.
Gives flags to the player across all of their characters.
Makes an entity the property of the player's current character.
Makes an entity the property of a character, whether or not its player is online.
Gives the player ammo and records it as spawn ammo.
Gives the player the weapon of a weapon item and records it as a spawn weapon.
Gives the player a weapon and records it as a spawn weapon.
Returns whether the local player is wearing an accessory of an item type.
Returns whether the player's character has at least one of the given flags.
Returns whether the server has finished sending the local player's data.
Returns whether the player has access to a door.
Returns whether the player's character has the given flags.
Puts all of the player's item weapons back into their inventory and selects their hands.
Runs an inventory action, such as using or dropping an item, as if the player had requested it.
Returns whether the player has the o (operator) flag.
Returns whether the player is noclipping outside a vehicle.
Returns whether a player is the server owner and protected from admin actions.
Returns whether the player is ragdolled.
Returns whether the local player is wearing a specific accessory item.
Returns whether the local player is wearing a clothes item.
Returns whether an item is the clothes item the local player is wearing.
Returns whether the player is whitelisted for a faction.
Respawns the player in place, keeping their position, health, armor, model and look.
Loads one of the player's characters, or creates a new one in a slot.
Loads the player's player data from the database, creating a row for new players.
Notifies a player in chat or with a notification popup.
Sends a chat notification to admins of a given rank.
Sends a chat notification to every player.
Notifies every player who has initialized within a radius of a position.
Pauses the countdown until the player gets up.
Plays a sound on the player's client.
Returns a field of the player's current character table.
Removes the gear entity in one of the player's gear slots.
Networks a character's loaded data and fills in defaults for missing keys.
Networks a player's loaded player data and fills in defaults for missing keys.
Re-sends a saved recognition of a player, or forgets it if PlayerCanRestoreRecognisedName refuses.
Clears the player's recognised names on their client and restores the saved ones in both directions.
Gives the player back the property of their current character that is still registered to them.
Runs a Catwork command as if the player had typed it.
Saves a character to the database.
Saves the player's player data to the database.
Broadcasts what a player says over the radio.
Starts a timed action on the player, shown as a progress bar.
Sets the player's ammo from a table of amounts.
Bans or unbans the player's current character and saves it.
Networks the flags, model, name, key, faction and gender of the player's current character.
Opens the character menu for a player who has initialized.
Sends a character menu state to the player's client.
Tells the player's client that character creation failed.
Sets the player's model to the one returned by cw.player:GetDefaultModel.
Sets the player's skin to the one returned by cw.player:GetDefaultSkin.
Adds a drink to the player, or sobers them up.
Sets the rank of the player's character within their faction.
Replaces all flags of the player's current character.
Sets whether the player has initialized, through the Initialized net var.
Opens or closes the main menu on the player's client.
Changes the name of the player's current character.
Sets a networked variable on a player.
Replaces all of the player's player-wide flags.
Sets how long the player's ragdoll is immune to damage.
Knocks the player over into a ragdoll or gets them back up.
Sets how well a player recognises another player's character and tells their client.
Moves the player to a position, nudging them to a nearby free spot if they would be stuck.
Sets when the player gets up, shown as the unragdoll action.
Starts the removal timers of the player's property that has a remove delay.
Raises or lowers the player's weapon.
Gives the player back a list of weapons made by cw.player:GetWeapons.
Adds the player to a faction's whitelist or removes them from it.
Starts playing a sound on the player's client under an identifier.
Resumes a countdown paused with cw.player:PauseUnragdollTime.
Removes the ammo a weapon came with when it was given.
Removes all of the player's gear entities.
Removes the player's death code.
Takes a door from the player and refunds half the door_cost config.
Removes the player's current character from a door's access list.
Takes flags from the player's current character.
Takes flags from the player's player-wide flags.
Removes an entity from the player's property.
Removes an entity from a character's property, whether or not its player is online.
Takes ammo that was given on spawn from the player.
Strips a spawn weapon from the player.
Raises the player's weapon if it is lowered, and lowers it otherwise.
Stores the player's current inventory, ammo and data in their character table.
Networks a character data value registered with cw.player:AddCharacterData.
Networks a player data value registered with cw.player:AddPlayerData.
Switches the player to one of their characters if they are allowed to.
Uses up the player's death code after they act while knocked out.

Methods

cw.player:AddCharacterData(name, nwType, default, playerOnly, callback)

shared gamemodes/catwork/gamemode/core/libraries/sh_player.lua:146

Registers a character data type that is networked when it changes.

cw.player:AddCharacterData('radlevel', NWTYPE_NUMBER, 0, true)

Parameters

  • name String Name of the data
  • nwType Number Type of the value, one of the NWTYPE_* enums
  • default Any Default value
  • playerOnly Boolean optional, defaults to nil Whether the data is meant to be networked to its player only
  • callback Function optional, defaults to nil Called as callback(player, value) before networking; returns the value to send

See also

cw.player:AddPlayerData(name, nwType, default, playerOnly, callback)

shared gamemodes/catwork/gamemode/core/libraries/sh_player.lua:164

Registers a player data type that is networked when it changes.

Parameters

  • name String Name of the data
  • nwType Number Type of the value, one of the NWTYPE_* enums
  • default Any Default value
  • playerOnly Boolean optional, defaults to nil Whether the data is meant to be networked to its player only
  • callback Function optional, defaults to nil Called as callback(player, value) before networking; returns the value to send

See also

cw.player:CanAfford(player, amount)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:2663

Returns whether the player has at least an amount of cash.

Always true when cash is disabled.

Parameters

  • player Player The player
  • amount Number The amount

Returns

  • Boolean Whether the player can afford it

cw.player:CanDemote(player, target)

shared gamemodes/catwork/gamemode/core/libraries/sh_player.lua:246

Returns whether a player's rank allows them to demote a target.

The player's rank must have a canDemote position, which must be less than or equal to the target's rank position, and the target must not already hold the lowest rank.

Parameters

  • player Player The player doing the demotion
  • target Player The player who would be demoted

Returns

  • Boolean Whether the demotion is allowed, or nil when the player cannot demote

See also

cw.player:CanHearPlayer(player, target, iAllowance)

shared gamemodes/catwork/gamemode/core/libraries/sv_player.lua:628

On the server

Returns whether a player can hear another player.

Always true unless the messages_must_see_player config is on, in which case the player must be able to see the target.

Parameters

  • player Player The listening player
  • target Player The speaking player
  • iAllowance Number optional, defaults to 0.5 Trace fraction that counts as visible, see cw.player:CanSeePosition

Returns

  • Boolean Whether the player can hear the target

On the client

Returns whether a player can hear another player.

Always true unless the messages_must_see_player config is on, in which case cw.player:CanSeePlayer decides, ignoring every entity in the way.

Parameters

  • player Player The listener
  • target Player The speaker
  • allowance Number optional, defaults to 0.5 Fraction of the line of sight that must be clear

Returns

  • Boolean Whether player can hear target

Defined in

cw.player:CanHoldSpace(space)

client gamemodes/catwork/gamemode/core/libraries/cl_player.lua:36

Returns whether the local player's inventory can take some more space.

Parameters

  • space Number Space to add

Returns

See also

cw.player:CanHoldWeight(weight)

client gamemodes/catwork/gamemode/core/libraries/cl_player.lua:20

Returns whether the local player's inventory can take some more weight.

Parameters

  • weight Number Weight to add

Returns

See also

cw.player:CanPromote(player, target)

shared gamemodes/catwork/gamemode/core/libraries/sh_player.lua:224

Returns whether a player's rank allows them to promote a target.

The player's rank must have a canPromote position, which must be less than or equal to the target's rank position, and the target must not already hold the highest rank.

Parameters

  • player Player The player doing the promotion
  • target Player The player who would be promoted

Returns

  • Boolean Whether the promotion is allowed, or nil when the player cannot promote

See also

cw.player:CanSeeEntity(player, target, iAllowance, tIgnoreEnts)

shared gamemodes/catwork/gamemode/core/libraries/sv_player.lua:785

On the server

Returns whether the player can see an entity.

The entity is visible when the player is looking straight at it, or when cw.player:CanSeePosition succeeds for its center.

Parameters

  • player Player The player
  • target Entity The entity to check
  • iAllowance Number optional, defaults to 0.75 Trace fraction that counts as visible
  • tIgnoreEnts List<Entity> optional, defaults to nil Entities the trace ignores, or true to ignore every entity

Returns

  • Boolean true if the entity is visible, otherwise nil

Aliases

  • cw.player.CanSeePlayer
  • cw.player.CanSeeNPC

On the client

Returns whether a player can see an entity.

true straight away if the player is looking at it; otherwise traces from their shoot position to the entity's center.

Parameters

  • player Player The player looking
  • target Entity The entity
  • allowance Number optional, defaults to 0.75 Fraction of the trace that must be clear
  • ignoreEnts List<Entity> optional, defaults to nil Entities the trace ignores; any other true value ignores every entity

Returns

  • Boolean true if the entity can be seen, nil otherwise

Defined in

cw.player:CanSeeNPC(player, target, allowance, ignoreEnts)

client gamemodes/catwork/gamemode/core/libraries/cl_player.lua:348

Returns whether a player can see an NPC.

true straight away if the player is looking at it; otherwise traces between their shoot positions.

Parameters

  • player Player The player looking
  • target NPC The NPC
  • allowance Number optional, defaults to 0.75 Fraction of the trace that must be clear
  • ignoreEnts List<Entity> optional, defaults to nil Entities the trace ignores; any other true value ignores every entity

Returns

  • Boolean true if the NPC can be seen, nil otherwise

cw.player:CanSeePlayer(player, target, allowance, ignoreEnts)

client gamemodes/catwork/gamemode/core/libraries/cl_player.lua:384

Returns whether two players can see each other.

true straight away if either is looking at the other; otherwise traces between their shoot positions.

Parameters

  • player Player The player looking
  • target Player The other player
  • allowance Number optional, defaults to 0.75 Fraction of the trace that must be clear
  • ignoreEnts List<Entity> optional, defaults to nil Entities the trace ignores; any other true value ignores every entity

Returns

  • Boolean true if the player can be seen, nil otherwise

cw.player:CanSeePosition(player, position, iAllowance, tIgnoreEnts, targetEnt)

shared gamemodes/catwork/gamemode/core/libraries/sv_player.lua:809

On the server

Returns whether the player can see a position.

Traces from the player's shoot position and succeeds when the trace gets at least iAllowance of the way there.

Parameters

  • player Player The player
  • position Vector The position to check
  • iAllowance Number optional, defaults to 0.75 Trace fraction that counts as visible
  • tIgnoreEnts List<Entity> optional, defaults to nil Entities the trace ignores, or true to ignore every entity
  • targetEnt Entity optional, defaults to nil An entity the trace also ignores, usually the one being looked for

Returns

  • Boolean true if the position is visible, otherwise nil

On the client

Returns whether a player has a clear line of sight to a position.

Parameters

  • player Player The player looking
  • position Vector The position
  • allowance Number optional, defaults to 0.75 Fraction of the trace that must be clear
  • ignoreEnts List<Entity> optional, defaults to nil Entities the trace ignores; any other true value ignores every entity

Returns

  • Boolean true if the position can be seen, nil otherwise

Defined in

cw.player:CharacterScreenAdd(player, character)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:3613

Adds a character to the player's character selection screen.

PlayerAdjustCharacterScreenInfo(player, character, info) can change what is shown.

Parameters

  • player Player The player
  • character Character The character

cw.player:CinematicText(player, text, color, barLength, hangTime)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:2740

Shows cinematic text with black bars to the player.

Parameters

  • player Player The player, a list of players, or nil for everyone
  • text String The text
  • color Color optional, defaults to nil The text color; defaults to white
  • barLength Number optional, defaults to nil Length of the black bars, as used by cw.core:AddCinematicText
  • hangTime Number optional, defaults to nil Seconds the text stays on screen; defaults to 3

cw.player:CinematicTextAll(text, color, hangTime)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:2753

Shows cinematic text to every player who has initialized.

Parameters

  • text String The text
  • color Color optional, defaults to nil The text color; defaults to white
  • hangTime Number optional, defaults to nil Seconds the text stays on screen; defaults to 3

cw.player:ClearName(player, status, isAccurate)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:2473

Makes every player forget the player's character.

Fires PlayerNameCleared.

Parameters

  • player Player The player to be forgotten
  • status Number optional, defaults to nil Only affect players who recognise them at this RECOGNISE_* level
  • isAccurate Boolean optional, defaults to nil Match status exactly instead of at least

See also

cw.player:ClearRecognisedNames(player, status, isAccurate)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:2444

Makes the player forget the characters they recognise.

Fires PlayerRecognisedNamesCleared.

Parameters

  • player Player The player
  • status Number optional, defaults to nil Only forget players recognised at this RECOGNISE_* level; nil forgets everyone
  • isAccurate Boolean optional, defaults to nil Match status exactly instead of at least

See also

cw.player:ConditionTimer(player, delay, Condition, Callback)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1235

Calls back after a delay, as long as a condition stays true the whole time.

The condition is checked every tick. If it fails or the player leaves, the callback is called with false. Starting a new condition timer cancels the previous one the same way.

local position = player:GetPos()

cw.player:ConditionTimer(player, 5, function()
  return player:Alive() and player:GetPos() == position
end, function(bSuccess)
  if bSuccess then
    player:SetHealth(player:GetMaxHealth())
  end
end)

Parameters

  • player Player The player the timer belongs to
  • delay Number Seconds the condition must hold
  • Condition Function Called without arguments; return true while the timer should go on
  • Callback Function Called as Callback(bSuccess)

See also

cw.player:ConvertCharacterDataString(data)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:3898

Decodes a JSON data string.

Parameters

  • data String The JSON string

Returns

  • Map The decoded table, or an empty table if it cannot be decoded

cw.player:ConvertCharacterMySQL(baseTable)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:3642

Decodes the JSON and numeric fields of a character loaded from the database, in place.

Cash that is not a finite number becomes 0.

Parameters

  • baseTable Character The camel case character table

cw.player:ConvertCharacterRecognisedNamesString(data)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:3879

Decodes a saved list of recognised character keys.

Parameters

  • data String A JSON list of character keys

Returns

  • Map RECOGNISE_SAVE keyed by character key, or an empty table if it cannot be decoded

cw.player:ConvertDataString(player, data)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1610

Decodes a JSON data string.

Parameters

  • player Player Unused
  • data String The JSON string

Returns

  • Map The decoded table, or an empty table if it cannot be decoded

cw.player:ConvertToCamelCase(baseTable)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:3562

Returns a copy of a database row with its column names converted to camel case.

Underscores are removed, so _SteamName becomes steamName.

Parameters

  • baseTable Map The row

Returns

  • Map The converted copy

cw.player:CreateCharacterFromData(player, data)

server internal gamemodes/catwork/gamemode/core/libraries/sv_player.lua:147

Internal

This function is internal. It is not part of the public API and may change without notice.

Called by the CreateCharacter Cable receiver.

Validates a character creation request and creates the character.

Checks the faction, class, attributes, name, physical description, model, gender, whitelist, faction limit and free character slots, and calls the faction's GetName, GetModel and OnCreation and the PlayerAdjustCharacterCreationInfo hook (returning false or a string there rejects the character). The name must also be unused in the database. Any failure is sent to the client with cw.player:SetCreateFault. On success the character is created with cw.player:LoadCharacter and used right away if it is the player's only one. A request that arrives while an earlier one is still being saved is ignored.

Of the client's plugin table, only the custom choices that the GetPersuasionChoices hook returns on the server become character data, and only with a value the choice allows.

Parameters

  • player Player The player creating the character
  • data Map The creation request from the client: faction, gender, model, class, attributes, forename and surname or fullName, physDesc and plugin (values of the custom choices)

Returns

  • Nil Nothing; the result is sent to the client

cw.player:CreateGear(player, gearClass, itemTable, bMustHave)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:559

Attaches an item's model to the player as a cw_gear entity.

Replaces any gear in the same slot. Does nothing unless the item has isAttachment set. Uses the item's attachmentModel (or model), attachmentMaterial and attachmentColor.

Parameters

  • player Player The player to attach the gear to
  • gearClass String The gear slot, usually the item's unique ID
  • itemTable Item The item the gear represents
  • bMustHave Boolean optional, defaults to nil Remove the gear when the player no longer has the item

See also

cw.player:DeleteCharacter(player, characterID)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:2173

Deletes one of the player's characters if they are allowed to.

The active character cannot be deleted. PlayerCanDeleteCharacter may return false or a reason string to block it.

Parameters

  • player Player The player
  • characterID Number The character slot

Returns

  • Boolean Whether the character was deleted
  • String The reason if it was not

See also

cw.player:DisableProperty(player, bCharacterOnly)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:886

Clears the owner of the player's property while keeping it registered to them.

The entities lose their owner entity and owned state, but keep the owner's unique ID and character key, so cw.player:ReturnProperty can give them back.

Parameters

  • player Player The player whose property is disabled
  • bCharacterOnly Boolean optional, defaults to nil Only disable property of the player's current character

cw.player:DoesRecognise(player, target, status, isAccurate)

shared gamemodes/catwork/gamemode/core/libraries/sv_player.lua:2090

On the server

Returns whether a player recognises another player's character.

Always true when the recognise_system config is off. Otherwise the result of the PlayerDoesRecognisePlayer hook, which receives the stored status.

Parameters

  • player Player The player who would recognise
  • target Player The player to be recognised
  • status Number optional, defaults to RECOGNISE_PARTIAL The minimum RECOGNISE_* level
  • isAccurate Boolean optional, defaults to nil Require exactly status instead of at least it

Returns

  • Boolean Whether the player recognises the target

See also

On the client

Returns whether the local player recognises another player.

Always true when the recognise_system config is off, and for the local player's own character. The PlayerDoesRecognisePlayer hook receives the computed value and returns the result.

Parameters

  • player Player The player to check
  • status Number optional, defaults to RECOGNISE_PARTIAL Lowest RECOGNISE_* level that counts
  • isAccurate Boolean optional, defaults to nil Whether the level must equal status instead of reaching it

Returns

  • Boolean Whether the player is recognised

Defined in

cw.player:DoesTargetRecognise()

client gamemodes/catwork/gamemode/core/libraries/cl_player.lua:207

Returns whether the player the local player is looking at recognises them.

Always true when the recognise_system config is off.

Returns

  • Boolean Whether the target recognises the local player, from the TargetKnows network variable

cw.player:DoRagdollDecayCheck(player, ragdoll)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:3157

Starts a timer that makes the ragdoll decay once its player has left.

Checked every 60 seconds; the ragdoll decays over the body_decay_time config if PlayerCanRagdollDecay returns true.

Parameters

  • player Player The player
  • ragdoll Entity The player's ragdoll

Drops the player's item weapons as item entities, such as when they die.

Uses the ragdoll's stored weapons if the player is ragdolled. Each weapon must pass PlayerCanDropWeapon and PlayerAdjustDropWeaponInfo; PlayerDropWeapon fires for each one dropped.

Parameters

  • player Player The player

cw.player:EntityConditionTimer(player, target, entity, delay, distance, Condition, Callback)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1284

Calls back after a delay, as long as the player keeps looking at an entity within range.

Fails like cw.player:ConditionTimer if the player looks away, moves out of range, the target or entity becomes invalid, or the condition fails.

Parameters

  • player Player The player the timer belongs to
  • target Entity The target, which must stay valid
  • entity Entity optional, defaults to nil The entity the player must look at; defaults to target
  • delay Number Seconds the condition must hold
  • distance Number Maximum distance from the player's shoot position to the entity
  • Condition Function Called without arguments; return true while the timer should go on
  • Callback Function Called as Callback(bSuccess)

cw.player:ForceDeleteCharacter(player, characterID)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:2143

Deletes one of the player's characters without asking any hooks first.

Deletes the row from the characters table, removes the character from the player's list and their client, and fires PlayerDeleteCharacter, which can return true to skip the log message.

Parameters

  • player Player The player
  • characterID Number The character slot

See also

cw.player:FormatRecognisedText(player, text, ...)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:2311

Replaces each %s in a text with the name a player knows each given player by.

local text = cw.player:FormatRecognisedText(listener, '%s hands %s a crowbar.', giver, receiver)

Parameters

  • player Player The player who reads the text
  • text String The text with one %s per player
  • ... Player The players to name, in order

Returns

  • String The formatted text

Returns the accessories the local player is wearing.

Returns

  • Map<String> Item unique IDs keyed by item ID

cw.player:GetAction(player, percentage)

shared gamemodes/catwork/gamemode/core/libraries/sv_player.lua:736

On the server

Returns the player's current action.

Without percentage, returns the action name, its duration in seconds and the CurTime it started at. With percentage, returns the action name and how far it has progressed, from 0 to 100. Returns '', 0, 0 when no action is running.

Parameters

  • player Player The player
  • percentage Boolean optional, defaults to nil Return the progress instead of the duration and start time

Returns

  • String The action, or '' if there is none
  • Number The duration, or the progress with percentage
  • Number The start time; not returned with percentage

See also

On the client

Returns a player's current action. Returns the action with how far it has progressed.

Variants

  • GetAction(player)
    • player Player The player
    Returns
    • String The action, or '' if there is none
    • Number Its duration in seconds
    • Number The CurTime it started at
  • GetAction(player, percentage)

    Returns the action with its duration and start time.

    • player Player The player
    • percentage Boolean true
    Returns
    • String The action, or '' if there is none
    • Number Progress from 0 to 100

Defined in

Returns every entity owned as property, removing entries that are no longer valid.

Returns

  • Map<Entity> Owned entities keyed by entity index

cw.player:GetAmmo(player, bDoStrip)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:2930

Returns the player's reserve ammo of every item ammo type, without their spawn ammo.

The ammo types are the ammoClass of every item, adjusted by the AdjustAmmoTypes hook.

Parameters

  • player Player The player
  • bDoStrip Boolean optional, defaults to nil Also remove all of the player's ammo

Returns

  • Map Amounts keyed by ammo type

Returns the local player's cash.

Returns

  • Number The Cash network variable, or 0

cw.player:GetCharacter(player)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:2269

Returns the player's current character.

Parameters

  • player Player The player

Returns

  • Character The character table, or nil if they have none loaded

cw.player:GetCharacterAmmoString(player, character, bRawTable)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:3810

Returns a character's saved ammo merged with the player's current ammo.

Parameters

  • player Player The player
  • character Character The character
  • bRawTable Boolean optional, defaults to nil Return the table instead of JSON

Returns

  • String The ammo as JSON, or a Map with bRawTable

cw.player:GetCharacterData(key)

shared gamemodes/catwork/gamemode/core/libraries/sh_player.lua:61

Returns the definition of a registered character data type.

This is the registration, not a character's value; use Player:GetCharacterData for that.

Parameters

  • key String Name of the data type

Returns

  • Map The definition with default, nwType, callback and playerOnly keys, or nil if it is not registered

cw.player:GetCharacterDataString(player, character, bRawTable)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:3831

Returns a copy of a character's data, adjusted by the PlayerSaveCharacterData hook.

Parameters

  • player Player The player
  • character Character The character
  • bRawTable Boolean optional, defaults to nil Return the table instead of JSON

Returns

  • String The data as JSON, or a Map with bRawTable

cw.player:GetCharacterDataTable()

shared gamemodes/catwork/gamemode/core/libraries/sh_player.lua:41

Returns every character data type registered with cw.player:AddCharacterData.

Returns

  • Map<Map> Data type definitions keyed by name, each with default, nwType, callback and playerOnly keys

cw.player:GetCharacterID(player)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:3664

Returns the slot of the player's current character.

Parameters

  • player Player The player

Returns

  • Number The character slot, or nil if they have no character loaded

cw.player:GetCharacterInventoryString(player, character, bRawTable)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:3863

Returns a copy of a character's inventory with the items added by PlayerAddToSavedInventory.

Parameters

  • player Player The player
  • character Character The character
  • bRawTable Boolean optional, defaults to nil Return the inventory instead of JSON

Returns

  • String The saveable inventory as JSON, or an Inventory with bRawTable

cw.player:GetCharacterKey(player)

client gamemodes/catwork/gamemode/core/libraries/cl_player.lua:538

Returns the key of a player's character, used to identify it in recognition data.

Parameters

  • player Player The player

Returns

  • Number The Key network variable, or nil if the player is not valid

cw.player:GetCharacterRecognisedNamesString(player, character)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:3846

Returns the character keys a character recognises at the RECOGNISE_SAVE level, as JSON.

Parameters

  • player Player The player
  • character Character The character

Returns

  • String A JSON list of character keys

cw.player:GetCharacters(player, Callback)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:3580

Loads the player's characters for the current schema from the database.

Parameters

  • player Player The player
  • Callback Function Called as Callback(characters) with a list of camel case character tables, or with nil if the player has none

Returns the icon shown next to a player's name in the chat box.

Uses the icons registered with cw.icon:Add, preferring player icons. Without one, whitelisted factions get icon16/add.png and everyone else icon16/user.png.

Parameters

  • player Player The player

Returns

  • String Path of the icon material; icon16/user_delete.png if the player is not valid

Returns the local player's clothes data as sent by the server.

Returns

  • Map The clothes item's uniqueID and itemID, both nil when no clothes are worn

Returns the clothes item the local player is wearing.

Returns

  • Item The clothes item from the inventory, or nil if none is worn

cw.player:GetDeathCode(player, authenticated)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1861

Returns the player's death code.

Parameters

  • player Player The player
  • authenticated Boolean optional, defaults to nil Only return the code if the player has authenticated it

Returns

  • Number The code, or nil if there is none

cw.player:GetDefaultModel(player)

shared gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1093

On the server

Returns the player's default model from the GetPlayerDefaultModel hook.

Parameters

  • player Player The player

Returns

  • String The model path

On the client

Returns the model a player's class gives them.

Parameters

  • player Player The player

Returns

Defined in

cw.player:GetDefaultSkin(player)

shared gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1080

On the server

Returns the player's default skin from the GetPlayerDefaultSkin hook.

Parameters

  • player Player The player

Returns

  • Number The skin index

On the client

Returns the skin of the model a player's class gives them.

Parameters

  • player Player The player

Returns

Defined in

cw.player:GetDoorCount(player)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:2583

Returns how many doors the player's current character owns, not counting child doors.

Parameters

  • player Player The player

Returns

  • Number The number of doors

On the server

Returns how drunk the player is.

Parameters

  • player Player The player

Returns

  • Number The number of drinks still in effect, or nil if the player is sober

On the client

Returns how drunk the local player is.

Parameters

  • player

Returns

  • Number The IsDrunk network variable, or nil if the player is sober

Defined in

cw.player:GetEquippedSpace(player)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:3019

Returns the total item space of the player's equipped weapons.

Parameters

  • player Player The player

Returns

  • Number The space

cw.player:GetEquippedWeight(player)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:3002

Returns the total item weight of the player's equipped weapons.

Parameters

  • player Player The player

Returns

  • Number The weight

cw.player:GetFactionRank(player, character)

shared gamemodes/catwork/gamemode/core/libraries/sh_player.lua:181

Returns a player's rank within their faction.

Reads the factionrank character data, from character when one is given.

Parameters

  • player Player The player whose rank is read; ignored when character is given
  • character Character optional, defaults to nil A character table to read the rank from instead

Returns

  • String The rank's name, or nothing if the faction has no ranks
  • Map The rank table from the faction's ranks, or nil if the rank does not exist

cw.player:GetFactionTable(player)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:2009

Returns the faction table of the player's current faction.

Parameters

  • player Player The player

Returns

  • Faction The faction, or nil if it does not exist

cw.player:GetGear(player, gearClass)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:120

Returns one of the player's gear entities.

Parameters

Returns

  • Entity The cw_gear entity, or nil if there is none in that slot

cw.player:GetHolsteredWeapon(player)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:3036

Returns the class of an item weapon the player carries but is not holding.

Parameters

  • player Player The player

Returns

  • String The weapon class, or nil if there is none

cw.player:GetMaximumCharacters(player)

shared gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1477

On the server

Returns how many characters the player may have.

One per faction that is not whitelisted or that the player is whitelisted for, plus the additional_characters config.

Parameters

  • player Player The player

Returns

  • Number The maximum number of characters

On the client

Returns how many characters the local player may have.

The additional_characters config plus one for every faction that is not whitelisted or that the player is whitelisted for.

Parameters

  • player

Returns

  • Number Maximum number of characters

Defined in

Returns the maximum space the local player can carry.

Starts from the InvSpace network variable, or the default_inv_space config, and adds the addInvVolume of every item in the inventory.

Returns

  • Number Maximum inventory space

Returns the maximum weight the local player can carry.

Starts from the InvWeight network variable, or the default_inv_weight config, and adds the addInvSpace of every item in the inventory.

Returns

  • Number Maximum inventory weight

cw.player:GetName(player, target)

shared gamemodes/catwork/gamemode/core/libraries/sv_player.lua:2116

On the server

Returns the name a player knows another player by.

Parameters

  • player Player The player looking
  • target Player The player being named

Returns

  • String The target's name if recognised, otherwise their unrecognised name

On the client

Returns a player's name as the local player knows it.

Parameters

  • target Player The player

Returns

Defined in

cw.player:GetNetVar(player, key)

shared gamemodes/catwork/gamemode/core/libraries/sh_player.lua:89

Returns a networked variable of a player.

Parameters

  • player Player The player to read the variable from
  • key String Name of the variable

Returns

  • Any The value, or nil for invalid players or unset variables

Aliases

  • cw.player.GetSharedVar

See also

On the server

Returns the player's physical description.

Falls back to the class's defaultPhysDesc, then the default_physdesc config, then the English #PhysDesc_MatchesModel phrase. GetPlayerPhysDescOverride may replace the result.

Parameters

  • player Player The player

Returns

  • String The physical description

On the client

Returns a player's physical description.

Falls back to the class's defaultPhysDesc, then the default_physdesc config, then the #PhysDesc_MatchesModel phrase. The GetPlayerPhysDescOverride hook can return a replacement.

Parameters

  • player Player optional, defaults to cw.client The player

Returns

  • String The physical description

Defined in

Returns the definition of a registered player data type.

Parameters

  • key String Name of the data type

Returns

  • Map The definition with default, nwType, callback and playerOnly keys, or nil if it is not registered

cw.player:GetPlayerDataTable()

shared gamemodes/catwork/gamemode/core/libraries/sh_player.lua:33

Returns every player data type registered with cw.player:AddPlayerData.

Returns

  • Map<Map> Data type definitions keyed by name, each with default, nwType, callback and playerOnly keys

cw.player:GetPlayerFlags(player)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:4217

Returns the player's player-wide flags.

Parameters

  • player Player The player

Returns

  • String The flags, or ''

cw.player:GetPropertyCount(player, class)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:2562

Returns how many entities the player's current character owns.

Parameters

  • player Player The player
  • class String optional, defaults to nil Only count entities of this class

Returns

  • Number The number of entities

cw.player:GetPropertyEntities(player, class)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:2540

Returns the property of the player's current character.

Parameters

  • player Player The player
  • class String optional, defaults to nil Only return entities of this class

Returns

  • List<Entity> The owned entities

cw.player:GetRagdollEntity(player)

shared gamemodes/catwork/gamemode/core/libraries/sv_player.lua:3136

On the server

Returns the player's ragdoll entity.

Parameters

  • player Player The player

Returns

  • Entity The ragdoll, or nil if there is none

On the client

Returns a player's ragdoll entity.

Parameters

  • player Player The player

Returns

  • Entity The ragdoll, or nil if the player is not ragdolled

Defined in

cw.player:GetRagdollState(player)

shared gamemodes/catwork/gamemode/core/libraries/sv_player.lua:3129

On the server

Returns the player's ragdoll state.

Parameters

  • player Player The player

Returns

  • Number A RAGDOLL_* value

On the client

Returns a player's ragdoll state.

Parameters

  • player Player The player

Returns

  • Number The RAGDOLL_* state, or false if it is unset

Defined in

cw.player:GetRagdollTable(player)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:3147

Returns the table with the player's state from before they were ragdolled.

Parameters

  • player Player The player

Returns

  • Map The ragdoll table (entity, health, armor, weapons, immunity and so on), or nil

cw.player:GetRealTrace(player, useFilterTrace)

shared gamemodes/catwork/gamemode/core/libraries/sv_player.lua:2060

On the server

Returns a trace of what the player is looking at, seeing through vehicles and non-solid entities.

Uses a 4096 unit trace with a solid and hitbox mask when it hits an entity that the normal eye trace misses or hits a vehicle instead.

Parameters

  • player Player The player
  • useFilterTrace Boolean optional, defaults to nil Always use the masked trace

Returns

  • Map The trace result

On the client

Returns a trace along a player's aim that can hit players and NPCs by their hitboxes.

Traces 4096 units from the player's eyes. A second trace with a hitbox mask is used when it hits an entity the plain trace missed, or the plain trace hit a vehicle.

Parameters

  • player Player The player whose aim to trace
  • useFilterTrace Boolean optional, defaults to nil Whether to always use the hitbox trace

Returns

  • Map The TraceResult, or nil if the player is not valid

Defined in

cw.player:GetSafePosition(player, position, filter, margin)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1560

Returns free spots on a grid around a position, sorted from nearest to farthest.

A spot is free if traces through a player-sized box there and from position to it hit nothing.

Parameters

  • player Player The player, ignored by the traces unless filter is given
  • position Vector The center position
  • filter Any optional, defaults to nil Trace filter; defaults to the player
  • margin Number optional, defaults to 3 Grid radius in steps; the step size is margin * 10 units

Returns

  • List<Vector> The free positions

cw.player:GetSpawnAmmo(player, ammo)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1329

Returns the ammo the player was given on spawn.

Parameters

  • player Player The player
  • ammo String optional, defaults to nil An ammo type; nil returns the whole table

Returns

  • Number The amount of that ammo type, or a Map of amounts by ammo type when ammo is nil

cw.player:GetSpawnWeapon(player, weapon)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1341

Returns whether a weapon was given to the player on spawn.

Parameters

  • player Player The player
  • weapon String The weapon class

Returns

  • Boolean true if it is a spawn weapon, otherwise nil

cw.player:GetUnragdollTime(player)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:3116

Returns when the player gets up.

Parameters

  • player Player The player

Returns

  • Number The CurTime the player gets up at, or 0 if no countdown is running

cw.player:GetUnrecognisedName(player, bFormatted)

shared gamemodes/catwork/gamemode/core/libraries/sv_player.lua:2280

On the server

Returns what players who do not recognise the player see instead of their name.

This is the player's physical description, or the unrecognised_name config if it is empty.

Parameters

  • player Player The player
  • bFormatted Boolean optional, defaults to nil Shorten it to 24 characters and wrap it in square brackets

Returns

  • String The unrecognised name
  • Boolean Whether the physical description was used

On the client

Returns the name shown for a player the local player does not recognise.

Parameters

  • player Player The player

Returns

  • String The player's physical description, or the unrecognised_name config if there is none
  • Boolean true if the physical description was used

Defined in

On the server

Returns the player's wages from the Wages net var.

Parameters

  • player Player The player

Returns

  • Number The wages

On the client

Returns the local player's wages.

Parameters

  • player

Returns

  • Number The Wages network variable

Defined in

cw.player:GetWagesName(player)

shared gamemodes/catwork/gamemode/core/libraries/sv_player.lua:770

On the server

Returns what the player's wages are called, from their class or the wages_name config.

Parameters

  • player Player The player

Returns

  • String The wages name

On the client

Returns what wages are called for a player's class.

Parameters

  • player Player The player

Returns

  • String The class's wagesName, or the wages_name config

Defined in

cw.player:GetWeaponClass(player, safe)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:4147

Returns the class of the player's active weapon.

Parameters

  • player Player The player
  • safe Any optional, defaults to nil Value to return if the player has no active weapon

Returns

  • String The weapon class, or safe

cw.player:GetWeaponRaised(player, bIsCached)

shared gamemodes/catwork/gamemode/core/libraries/sv_player.lua:839

On the server

Returns whether the player's weapon is raised.

Parameters

  • player Player The player
  • bIsCached Boolean optional, defaults to nil Unused

Returns

  • Boolean Whether the weapon is raised

See also

On the client

Returns whether a player's weapon is raised.

Parameters

  • player Player The player

Returns

Defined in

cw.player:GetWeapons(player, bDoKeep)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:2971

Returns a list of the player's weapons that cw.player:SetWeapons can give back, and strips them.

Parameters

  • player Player The player
  • bDoKeep Boolean optional, defaults to nil Do not strip the weapons

Returns

  • List<Map> One entry per weapon with weaponData (class and itemTable) and teamIndex (only for spawn weapons)

cw.player:GiveAmmo(player, ammo)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:2912

Gives the player ammo from a table of amounts.

Parameters

  • player Player The player
  • ammo Map Amounts keyed by ammo type

cw.player:GiveCash(player, amount, reason, bNoMsg)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:2686

Gives cash to the player's character, or takes it with a negative amount.

The amount is rounded and the balance cannot drop below zero. Shows a hint with the change and fires PlayerCashUpdated. Does nothing when cash is disabled or the amount is not a finite number.

cw.player:GiveCash(player, -50, 'buying a crowbar')

Parameters

  • player Player The player
  • amount Number Cash to give; negative takes it
  • reason String optional, defaults to nil Shown in the hint after the amount
  • bNoMsg Boolean optional, defaults to nil Do not show a hint

See also

cw.player:GiveDeathCode(player)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1878

Gives the player a new random death code and sends it to their client.

Called when the player is knocked out.

Parameters

  • player Player The player

cw.player:GiveDoor(player, door, name, unsellable, override)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:2024

Gives a door, and its parent and children, to the player.

Resets the door's access list, sets its text, makes it networked property of the player and fires PlayerDoorGiven. The door is unlocked if PlayerCanUnlockEntity allows it. Does nothing if the entity is not a door.

Parameters

  • player Player The new owner
  • door Entity The door
  • name String optional, defaults to nil Text to show on the door
  • unsellable Boolean optional, defaults to nil Prevent the player from selling the door
  • override Boolean optional, defaults to nil Give this door directly instead of going through its parent

See also

cw.player:GiveDoorAccess(player, door, access)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:2615

Gives the player's current character access to a door.

Parameters

  • player Player The player
  • door Entity The door
  • access Number DOOR_ACCESS_BASIC or DOOR_ACCESS_COMPLETE

See also

cw.player:GiveFlags(player, flags)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1433

Gives flags to the player's current character.

Fires PlayerFlagsGiven for each flag the character did not have.

Parameters

  • player Player The player
  • flags String The flags, one character each

See also

cw.player:GiveItemWeapon(player, itemTable)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1406

Gives the player the weapon of a weapon item.

Parameters

  • player Player The player
  • itemTable Item The weapon item

Returns

  • Boolean true if the item is a weapon, otherwise nil

cw.player:GivePlayerFlags(player, flags)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1452

Gives flags to the player across all of their characters.

Stored in the player's Flags data. Fires PlayerFlagsGiven for each flag the player did not have.

Parameters

  • player Player The player
  • flags String The flags, one character each

See also

cw.player:GiveProperty(player, entity, networked, removeDelay)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:921

Makes an entity the property of the player's current character.

Clears any previous ownership and cancels a pending remove delay. Fires PlayerPropertyGiven.

Parameters

  • player Player The new owner
  • entity Entity The entity
  • networked Boolean optional, defaults to nil Also set the Owner networked entity for clients
  • removeDelay Number optional, defaults to nil Seconds after the owner leaves before the entity is removed

See also

cw.player:GivePropertyOffline(key, uniqueID, entity, networked, removeDelay)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:964

Makes an entity the property of a character, whether or not its player is online.

If the player is online with that character, this calls cw.player:GiveProperty. Otherwise the entity is registered to the key and unique ID and PlayerPropertyGivenOffline fires. Does nothing without a key and unique ID.

Parameters

  • key Number The character key
  • uniqueID String The owner's Player:UniqueID
  • entity Entity The entity
  • networked Boolean optional, defaults to nil Also set the Owner networked entity for clients
  • removeDelay Number optional, defaults to nil Seconds after the owner leaves before the entity is removed

cw.player:GiveSpawnAmmo(player, ammo, amount)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1374

Gives the player ammo and records it as spawn ammo.

Spawn ammo is not saved with the character.

Parameters

  • player Player The player
  • ammo String The ammo type
  • amount Number How much to give

cw.player:GiveSpawnItemWeapon(player, itemTable)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1417

Gives the player the weapon of a weapon item and records it as a spawn weapon.

Parameters

  • player Player The player
  • itemTable Item The weapon item

Returns

  • Boolean true if the item is a weapon, otherwise nil

cw.player:GiveSpawnWeapon(player, class)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1397

Gives the player a weapon and records it as a spawn weapon.

Spawn weapons are not saved with the character.

Parameters

  • player Player The player
  • class String The weapon class

cw.player:HasAccessory(uniqueID)

client gamemodes/catwork/gamemode/core/libraries/cl_player.lua:127

Returns whether the local player is wearing an accessory of an item type.

Parameters

  • uniqueID String Unique ID of the item type, compared case-insensitively

Returns

  • Boolean Whether such an accessory is worn

cw.player:HasAnyFlags(player, flags, bByDefault)

shared gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1703

On the server

Returns whether the player's character has at least one of the given flags.

The s, a and o flags are granted by the superadmin, admin and operator user groups. Unless bByDefault is set, the player's class flags and the PlayerDoesHaveFlag hook also count; the hook returning false denies a flag.

Parameters

  • player Player The player
  • flags String The flags, one character each
  • bByDefault Boolean optional, defaults to nil Only check the character's own flags and user group

Returns

  • Boolean true if the player has any of the flags, otherwise nil

See also

On the client

Returns whether a player has at least one of some flags.

The flags of the player's class count, and the PlayerDoesHaveFlag hook can grant or deny a flag. s, a and o are also granted by the superadmin, admin and operator user groups.

Parameters

  • player Player The player
  • flags String The flags, such as 'pet'
  • bByDefault Boolean optional, defaults to nil Whether to ignore the class flags and the hook

Returns

  • Boolean true if the player has one of the flags, nil otherwise or if they have no flags

See also

Defined in

Returns whether the server has finished sending the local player's data.

Returns

  • Boolean Whether the data has streamed

cw.player:HasDoorAccess(player, door, access, isAccurate)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:2637

Returns whether the player has access to a door.

Players with the D flag always do. Otherwise the result comes from the PlayerDoesHaveDoorAccess hook, asked about the parent door if the door shares its parent's access and has no entry of its own.

Parameters

  • player Player The player
  • door Entity The door
  • access Number optional, defaults to DOOR_ACCESS_BASIC The access level required
  • isAccurate Boolean optional, defaults to nil Require exactly that level

Returns

  • Boolean Whether the player has access

cw.player:HasFlags(player, flags, bByDefault, bIsStrict)

shared gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1763

On the server

Returns whether the player's character has the given flags.

The s, a and o flags are granted by the superadmin, admin and operator user groups. Unless bByDefault is set, the player's class flags and the PlayerDoesHaveFlag hook also count. Without bIsStrict, having any one of the flags is enough; with it, all of them are required and the hook returning false denies a flag.

Parameters

  • player Player The player
  • flags String The flags, one character each
  • bByDefault Boolean optional, defaults to nil Only check the character's own flags and user group
  • bIsStrict Boolean optional, defaults to nil Require every flag

Returns

  • Boolean true if the check passes, otherwise nil

See also

On the client

Returns whether a player has some flags.

Without bIsStrict any one of the flags is enough; with it every flag is needed. The flags of the player's class count, and the PlayerDoesHaveFlag hook can grant or deny a flag. s, a and o are also granted by the superadmin, admin and operator user groups.

if cw.player:HasFlags(cw.client, cmdTable.access) then
  -- show the command
end

Parameters

  • player Player The player
  • flags String The flags, such as 'pet'
  • bByDefault Boolean optional, defaults to nil Whether to ignore the class flags and the hook
  • bIsStrict Boolean optional, defaults to nil Whether every flag is needed

Returns

  • Boolean Whether the player has the flags; nil if they have no flags at all

See also

Defined in

Puts all of the player's item weapons back into their inventory and selects their hands.

Each weapon must pass PlayerCanHolsterWeapon; PlayerHolsterWeapon fires for each.

Parameters

  • player Player The player

cw.player:InventoryAction(player, itemTable, action)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:112

Runs an inventory action, such as using or dropping an item, as if the player had requested it.

Runs the InvAction command on behalf of the player.

Parameters

  • player Player The player performing the action
  • itemTable Item The item instance to act on
  • action String Name of the action, such as 'use' or 'drop'

Returns

On the server

Returns whether the player has the o (operator) flag.

Parameters

  • player Player The player

Returns

  • Boolean true if they have the flag, otherwise nil

See also

On the client

Returns whether a player has the operator flag (o).

Parameters

  • player Player The player

Returns

  • Boolean true if they have it, nil otherwise

See also

Defined in

cw.player:IsNoClipping(player)

shared gamemodes/catwork/gamemode/core/libraries/sv_player.lua:603

On the server

Returns whether the player is noclipping outside a vehicle.

Parameters

  • player Player The player

Returns

  • Boolean true if noclipping, otherwise nil

On the client

Returns whether a player is noclipping outside a vehicle.

Parameters

  • player Player The player

Returns

  • Boolean true if they are noclipping, nil otherwise

Defined in

cw.player:IsProtected(identifier)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:2768

Returns whether a player is the server owner and protected from admin actions.

The owner is set by the owner_steamid config, which may hold several comma-separated Steam IDs. Developers recognised by the developer plugin count as protected.

Parameters

  • identifier Player The player, or a name or Steam ID passed to player.Find

Returns

  • Boolean Whether the player is protected

cw.player:IsRagdolled(player, exception, bNoEntity)

shared gamemodes/catwork/gamemode/core/libraries/sv_player.lua:3054

On the server

Returns whether the player is ragdolled.

Parameters

  • player Player The player
  • exception Number optional, defaults to nil A RAGDOLL_* state that does not count as ragdolled
  • bNoEntity Boolean optional, defaults to nil Check the ragdoll state even if the player has no ragdoll entity

Returns

  • Boolean Whether the player is ragdolled; nil if they have no ragdoll entity

On the client

Returns whether a player is ragdolled.

Parameters

  • player Player The player
  • exception Number optional, defaults to nil A RAGDOLL_* state that does not count as ragdolled
  • entityless Boolean optional, defaults to nil Whether to check the state even when the player has no ragdoll entity

Returns

  • Boolean Whether the player is ragdolled, or nil if they have no ragdoll entity and entityless is not set

Defined in

cw.player:IsWearingAccessory(itemTable)

client gamemodes/catwork/gamemode/core/libraries/cl_player.lua:142

Returns whether the local player is wearing a specific accessory item.

Parameters

  • itemTable Item The item instance

Returns

  • Boolean Whether the item is worn

Returns whether the local player is wearing a clothes item.

Returns

  • Boolean Whether clothes are worn

cw.player:IsWearingItem(itemTable)

client gamemodes/catwork/gamemode/core/libraries/cl_player.lua:156

Returns whether an item is the clothes item the local player is wearing.

Parameters

  • itemTable Item The item instance

Returns

  • Boolean Whether the item is worn, or nil if no clothes are worn

cw.player:IsWhitelisted(player, faction)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1174

Returns whether the player is whitelisted for a faction.

Parameters

  • player Player The player
  • faction String Name of the faction

Returns

  • Boolean Whether the player is whitelisted

cw.player:LightSpawn(player, weapons, ammo, bForceReturn)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:3486

Respawns the player in place, keeping their position, health, armor, model and look.

Gets the player up first if they are ragdolled, unless bForceReturn is set. Fires PostPlayerLightSpawn once the spawn is done.

Parameters

  • player Player The player
  • weapons List<Map> optional, defaults to nil Weapons to give back; true keeps the current ones
  • ammo Map optional, defaults to nil Ammo to give back; true keeps the current ammo
  • bForceReturn Boolean optional, defaults to nil Do not get the player up, and passed on to cw.player:SetWeapons

cw.player:LoadCharacter(player, characterID, tMergeCreate, Callback, bForce)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:3693

Loads one of the player's characters, or creates a new one in a slot.

With tMergeCreate, a new character with default values is merged with it, given its default inventory through GetPlayerDefaultInventory, checked with PlayerCanCreateCharacter (unless bForce), inserted into the database and added to the character screen; PlayerCharacterCreated fires. Nothing happens if the slot is taken.

Without it, the current character is saved and unloaded (PlayerCharacterUnloaded), the character in the slot becomes current, the player is killed silently to respawn as it, and PlayerCharacterLoaded fires.

Parameters

  • player Player The player
  • characterID Number The character slot
  • tMergeCreate Map optional, defaults to nil Fields of a new character to create
  • Callback Function optional, defaults to nil Called without arguments once a new character is saved
  • bForce Boolean optional, defaults to nil Skip PlayerCanCreateCharacter

cw.player:LoadData(player, Callback)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:3916

Loads the player's player data from the database, creating a row for new players.

Sets the player's join time, last played time, user group and data, makes protected players and developers superadmins, and fires PlayerRestoreData. Retries every 2 seconds until the data has loaded.

Parameters

  • player Player The player
  • Callback Function optional, defaults to nil Called as Callback(player) once the data has loaded

See also

cw.player:Notify(player, text, class, icon)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:2866

Notifies a player in chat or with a notification popup.

With class set to true or nil the text goes to chat through chatbox.AddText. Otherwise it is a popup of that NOTIFY_* class.

Parameters

  • player Player The player, a list of players, or nil for everyone
  • text String The text
  • class Any optional, defaults to nil true or nil for chat, or a NOTIFY_* number for a popup
  • icon String optional, defaults to nil Path of the chat icon; not used for lists of players

See also

cw.player:NotifyAdmins(adminLevel, text, icon)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:2839

Sends a chat notification to admins of a given rank.

'operator' or 'o' notifies all admins, 'admin' or 'a' notifies admins who are not operators, and 'superadmin' or 's' notifies superadmins.

Parameters

  • adminLevel String The rank to notify
  • text String The text
  • icon String optional, defaults to nil Path of the icon shown next to the message

cw.player:NotifyAll(text, icon)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:2827

Sends a chat notification to every player.

Parameters

  • text String The text
  • icon String optional, defaults to nil Path of the icon shown next to the message

cw.player:NotifyInRadius(text, class, position, radius)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:2810

Notifies every player who has initialized within a radius of a position.

Parameters

  • text String The text
  • class Any The notification class, see cw.player:Notify
  • position Vector The center position
  • radius Number The radius

cw.player:PauseUnragdollTime(player)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:3087

Pauses the countdown until the player gets up.

Parameters

  • player Player The player

See also

cw.player:PlaySound(player, sound)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1467

Plays a sound on the player's client.

Parameters

  • player Player The player, a list of players, or nil for everyone
  • sound String Path of the sound file

cw.player:Query(player, key, default)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1497

Returns a field of the player's current character table.

The key is converted to camel case, so 'Name' and 'name' both read character.name.

Parameters

  • player Player The player
  • key String The field, such as 'Name', 'Cash' or 'Faction'
  • default Any optional, defaults to nil Value to return if there is no character or the field is nil

Returns

  • Any The value, or default

cw.player:RemoveGear(player, gearClass)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:530

Removes the gear entity in one of the player's gear slots.

Parameters

  • player Player The player
  • gearClass String The gear slot

cw.player:RestoreCharacterData(player, data)

server internal gamemodes/catwork/gamemode/core/libraries/sv_player.lua:46

Internal

This function is internal. It is not part of the public API and may change without notice.

Called by GM:PlayerRestoreCharacterData.

Networks a character's loaded data and fills in defaults for missing keys.

Every key in data is sent through cw.player:UpdateCharacterData; keys registered with cw.player:AddCharacterData that are missing from data are set to their default with Player:SetCharacterData.

Parameters

  • player Player The player whose character was loaded
  • data Map The character's data, keyed by name

cw.player:RestoreData(player, data)

server internal gamemodes/catwork/gamemode/core/libraries/sv_player.lua:26

Internal

This function is internal. It is not part of the public API and may change without notice.

Called by GM:PlayerRestoreData.

Networks a player's loaded player data and fills in defaults for missing keys.

Every key in data is sent through cw.player:UpdatePlayerData; keys registered with cw.player:AddPlayerData that are missing from data are set to their default with Player:SetData.

Parameters

  • player Player The player whose data was loaded
  • data Map The player's data, keyed by name

cw.player:RestoreRecognisedName(player, target)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:2334

Re-sends a saved recognition of a player, or forgets it if PlayerCanRestoreRecognisedName refuses.

Parameters

  • player Player The player who recognises
  • target Player The player who is recognised

cw.player:RestoreRecognisedNames(player)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:2351

Clears the player's recognised names on their client and restores the saved ones in both directions.

Restoring only happens when the save_recognised_names config is on.

Parameters

  • player Player The player

cw.player:ReturnProperty(player)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1625

Gives the player back the property of their current character that is still registered to them.

Fires PlayerReturnProperty.

Parameters

  • player Player The player

See also

cw.player:RunClockworkCommand(player, command, ...)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:763

Runs a Catwork command as if the player had typed it.

cw.player:RunClockworkCommand(player, 'CharFallOver')

Parameters

  • player Player The player running the command
  • command String Name of the command
  • ... Any The command's arguments

Returns

cw.player:SaveCharacter(player, bCreate, character, Callback)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:4059

Saves a character to the database.

Without bCreate, the character's row is updated (only for players who have initialized) and the player data is saved too. With bCreate, every field of the character is inserted as a new row.

Parameters

  • player Player The player
  • bCreate Boolean optional, defaults to nil Insert the character as a new row
  • character Character optional, defaults to nil The character to save; defaults to the current one
  • Callback Function optional, defaults to nil With bCreate, called as Callback(key) with the new row's key

cw.player:SaveData(player, bCreate)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:4000

Saves the player's player data to the database.

PlayerSaveData(player, data) can change a copy of the data before it is saved.

Parameters

  • player Player The player
  • bCreate Boolean optional, defaults to nil Insert a new row for the player instead of updating theirs

Returns

  • Map An empty table when bCreate is set, otherwise nothing

cw.player:SayRadio(player, text, check, noEavesdrop)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1945

Broadcasts what a player says over the radio.

PlayerAdjustRadioInfo(player, info) fills info.listeners with the players who receive it (as values or keys). Unless noEavesdrop is set, other players within the talk_radius config hear it too. With check, PlayerCanRadio must return true. Fires PlayerRadioUsed once sent.

Parameters

  • player Player The speaking player
  • text String What the player says
  • check Boolean optional, defaults to nil Ask PlayerCanRadio first
  • noEavesdrop Boolean optional, defaults to nil Do not let nearby players hear it

cw.player:SetAction(player, action, duration, priority, Callback)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:671

Starts a timed action on the player, shown as a progress bar.

An action only replaces a running one with a priority if its own priority is higher, or if it has the same name. Passing an empty or non-string action clears the current action; passing a duration of false or 0 clears it only if action is the current one. The action is networked through the StartActTime, ActDuration and ActName net vars.

cw.player:SetAction(player, 'lockpick', 5, 3, function()
  if IsValid(door) then
    door:Fire('unlock', '', 0)
  end
end)

Parameters

  • player Player The player
  • action String Name of the action, or a non-string to clear it
  • duration Number Duration in seconds; false or 0 stops action if it is running
  • priority Number optional, defaults to nil Priority of the action against other actions
  • Callback Function optional, defaults to nil Called without arguments when the duration has passed

Returns

  • Boolean false if asked to stop an action that is not running, otherwise nil

See also

cw.player:SetAmmo(player, ammo)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:2919

Sets the player's ammo from a table of amounts.

Parameters

  • player Player The player
  • ammo Map Amounts keyed by ammo type

cw.player:SetBanned(player, banned)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:2508

Bans or unbans the player's current character and saves it.

Parameters

  • player Player The player
  • banned Boolean Whether the character is banned

cw.player:SetBasicSharedVars(player)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:3783

Networks the flags, model, name, key, faction and gender of the player's current character.

Parameters

  • player Player The player

Returns

  • Boolean Always true

cw.player:SetCharacterMenuOpen(player, bReset)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:475

Opens the character menu for a player who has initialized.

Parameters

  • player Player The player
  • bReset Boolean optional, defaults to false Also kill the player silently and mark the menu as reset, so they respawn when they pick a character

cw.player:SetCharacterMenuState(player, state)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:721

Sends a character menu state to the player's client.

Parameters

  • player Player The player
  • state Number One of the CHARACTER_MENU_* values

cw.player:SetCreateFault(player, fault)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:2127

Tells the player's client that character creation failed.

Parameters

  • player Player The player
  • fault String optional, defaults to nil The reason; defaults to the CharFault_Unknown phrase

cw.player:SetDefaultModel(player)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1086

Sets the player's model to the one returned by cw.player:GetDefaultModel.

Parameters

  • player Player The player

cw.player:SetDefaultSkin(player)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1073

Sets the player's skin to the one returned by cw.player:GetDefaultSkin.

Parameters

  • player Player The player

cw.player:SetDrunk(player, expire)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1110

Adds a drink to the player, or sobers them up.

The level is networked through the IsDrunk net var.

Parameters

  • player Player The player
  • expire Number Seconds until the new drink wears off, or false to clear all drinks

See also

cw.player:SetFactionRank(player, rank)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:4184

Sets the rank of the player's character within their faction.

Also applies the rank's class, model and weapons (given as spawn weapons). Does nothing if the faction has no rank by that name.

Parameters

  • player Player The player
  • rank String Name of the rank

cw.player:SetFlags(player, flags)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:4165

Replaces all flags of the player's current character.

Parameters

  • player Player The player
  • flags String The new flags, one character each

cw.player:SetInitialized(player, initialized)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1688

Sets whether the player has initialized, through the Initialized net var.

Parameters

  • player Player The player
  • initialized Boolean Whether the player has initialized

cw.player:SetMenuOpen(player, isOpen)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1681

Opens or closes the main menu on the player's client.

Parameters

  • player Player The player
  • isOpen Boolean Whether the menu should be open

cw.player:SetName(player, name, saveless)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:2520

Changes the name of the player's current character.

Fires PlayerNameChanged unless this happens during the first spawn.

Parameters

  • player Player The player
  • name String The new name
  • saveless Boolean optional, defaults to nil Do not save the character afterwards

cw.player:SetNetVar(player, key, value)

shared gamemodes/catwork/gamemode/core/libraries/sh_player.lua:74

Sets a networked variable on a player.

Does nothing on the client or for invalid players.

Parameters

  • player Player The player to set the variable on
  • key String Name of the variable
  • value Any New value

Aliases

  • cw.player.SetSharedVar

See also

cw.player:SetPlayerFlags(player, flags)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:4173

Replaces all of the player's player-wide flags.

Parameters

  • player Player The player
  • flags String The new flags, one character each

cw.player:SetRagdollImmunity(player, delay)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:3183

Sets how long the player's ragdoll is immune to damage.

Parameters

  • player Player A ragdolled player
  • delay Number Seconds of immunity, or nil to remove it

cw.player:SetRagdollState(player, state, delay, decay, force, multiplier, velocityCallback)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:3213

Knocks the player over into a ragdoll or gets them back up.

RAGDOLL_KNOCKEDOUT and RAGDOLL_FALLENOVER create a ragdoll (or change the state of an existing one) if PlayerCanRagdoll returns true, store the player's weapons, health and armor, and make the player spectate it. Being knocked out gives the player a death code. RAGDOLL_NONE gets the player up where the ragdoll lies and restores them, and RAGDOLL_RESET only removes the ragdoll, if PlayerCanUnragdoll returns true. Fires PlayerRagdolled or PlayerUnragdolled.

cw.player:SetRagdollState(player, RAGDOLL_KNOCKEDOUT, 30)

Parameters

  • player Player The player
  • state Number A RAGDOLL_* value
  • delay Number optional, defaults to nil Seconds until the player gets up on their own
  • decay Number optional, defaults to nil Seconds the ragdoll takes to decay when the player gets up; nil removes it
  • force Vector optional, defaults to nil Force applied to the ragdoll's bones
  • multiplier Number optional, defaults to nil Unused
  • velocityCallback Function optional, defaults to nil Called as velocityCallback(physObj, boneIndex, ragdoll, velocity, force) for each bone instead of applying the velocity and force

cw.player:SetRecognises(player, target, status, bForce)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:2375

Sets how well a player recognises another player's character and tells their client.

RECOGNISE_SAVE is only kept if the save_recognised_names config is on and PlayerCanSaveRecognisedName returns true; it becomes RECOGNISE_TOTAL otherwise. Does nothing if the player already recognises the target at that level, unless bForce is set.

Parameters

  • player Player The player who recognises
  • target Player The player who is recognised
  • status Number A RECOGNISE_* level, or false to forget the target
  • bForce Boolean optional, defaults to nil Set it even if the player already recognises the target at that level

See also

cw.player:SetSafePosition(player, position, filter)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1516

Moves the player to a position, nudging them to a nearby free spot if they would be stuck.

Parameters

  • player Player The player
  • position Vector The position
  • filter Entity optional, defaults to nil An entity, list of entities or trace filter function that does not count as blocking

See also

cw.player:SetUnragdollTime(player, delay)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:3070

Sets when the player gets up, shown as the unragdoll action.

Parameters

  • player Player The player
  • delay Number Seconds until the player gets up, or false to cancel getting up

See also

cw.player:SetupRemovePropertyDelays(player, bAllCharacters)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:860

Starts the removal timers of the player's property that has a remove delay.

Parameters

  • player Player The player whose property should be removed
  • bAllCharacters Boolean optional, defaults to nil Include property of all the player's characters, not just the current one

cw.player:SetWeaponRaised(player, bIsRaised)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:853

Raises or lowers the player's weapon.

Parameters

  • player Player The player
  • bIsRaised Boolean Whether the weapon should be raised

Returns

cw.player:SetWeapons(player, weapons, bForceReturn)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:2897

Gives the player back a list of weapons made by cw.player:GetWeapons.

Skips weapons the player already has, and spawn weapons that belonged to a different team.

Parameters

  • player Player The player
  • weapons List<Map> The weapons, as returned by cw.player:GetWeapons
  • bForceReturn Boolean optional, defaults to nil Passed on to Player:Give

cw.player:SetWhitelisted(player, faction, isWhitelisted)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1185

Adds the player to a faction's whitelist or removes them from it.

Changes the player's Whitelisted data, which is saved with the player, and tells their client.

Parameters

  • player Player The player
  • faction String Name of the faction
  • isWhitelisted Boolean Whether the player should be whitelisted

cw.player:StartSound(player, uniqueID, sound, fVolume)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:494

Starts playing a sound on the player's client under an identifier.

Does nothing if the same sound is already playing under that identifier.

Parameters

  • player Player The player
  • uniqueID String Identifier used to stop the sound later
  • sound String Path of the sound file
  • fVolume Number optional, defaults to 0.75 Volume from 0 to 1

See also

cw.player:StartUnragdollTime(player)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:3103

Resumes a countdown paused with cw.player:PauseUnragdollTime.

Parameters

  • player Player The player

cw.player:StopSound(player, uniqueID, iFadeOut)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:513

Stops a sound started with cw.player:StartSound.

Parameters

  • player Player The player
  • uniqueID String Identifier the sound was started under
  • iFadeOut Number optional, defaults to 0 Fade-out time in seconds

cw.player:StripDefaultAmmo(player, weapon, itemTable)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1131

Removes the ammo a weapon came with when it was given.

Empties the weapon's clips and takes the item's primaryDefaultAmmo and secondaryDefaultAmmo amounts from the player's reserve ammo.

Parameters

  • player Player The player holding the weapon
  • weapon Weapon The weapon
  • itemTable Item optional, defaults to nil The weapon's item; looked up from the weapon if not given

Removes all of the player's gear entities.

Parameters

  • player Player The player

cw.player:TakeDeathCode(player)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1869

Removes the player's death code.

Parameters

  • player Player The player

cw.player:TakeDoor(player, door, bForce, bThisDoorOnly, bChildrenOnly)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1897

Takes a door from the player and refunds half the door_cost config.

Parent and child doors are taken with it unless bThisDoorOnly is set. The door is unlocked if PlayerCanUnlockEntity allows it, its text is cleared, and PlayerDoorTaken fires. Non-map prop_dynamic doors are removed.

Parameters

  • player Player The owner
  • door Entity The door
  • bForce Boolean optional, defaults to nil Do not refund the door
  • bThisDoorOnly Boolean optional, defaults to nil Do not take the door's parent or children
  • bChildrenOnly Boolean optional, defaults to nil Take the children even if the door has a parent, instead of going through the parent

See also

cw.player:TakeDoorAccess(player, door)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:2604

Removes the player's current character from a door's access list.

Parameters

  • player Player The player
  • door Entity The door

cw.player:TakeFlags(player, flags)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1648

Takes flags from the player's current character.

Fires PlayerFlagsTaken for each flag the character had.

Parameters

  • player Player The player
  • flags String The flags, one character each

See also

cw.player:TakePlayerFlags(player, flags)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1666

Takes flags from the player's player-wide flags.

Fires PlayerFlagsTaken for each flag the player had.

Parameters

  • player Player The player
  • flags String The flags, one character each

See also

cw.player:TakeProperty(player, entity)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1051

Removes an entity from the player's property.

Does nothing unless the player owns the entity. Fires PlayerPropertyTaken.

Parameters

  • player Player The owner
  • entity Entity The entity

See also

cw.player:TakePropertyOffline(key, uniqueID, entity, bAnyCharacter)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1016

Removes an entity from a character's property, whether or not its player is online.

If the player is online with that character, this calls cw.player:TakeProperty. Otherwise ownership is only cleared if the entity belongs to that key and unique ID, and PlayerPropertyTakenOffline fires.

Parameters

  • key Number The character key
  • uniqueID String The owner's Player:UniqueID
  • entity Entity The entity
  • bAnyCharacter Boolean optional, defaults to nil Unused

cw.player:TakeSpawnAmmo(player, ammo, amount)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1354

Takes ammo that was given on spawn from the player.

Does nothing if the player has no spawn ammo of that type, and takes at most the spawn amount.

Parameters

  • player Player The player
  • ammo String The ammo type
  • amount Number How much to take

cw.player:TakeSpawnWeapon(player, class)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1387

Strips a spawn weapon from the player.

Parameters

  • player Player The player
  • class String The weapon class

cw.player:ToggleWeaponRaised(player)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:845

Raises the player's weapon if it is lowered, and lowers it otherwise.

Parameters

  • player Player The player

cw.player:UpdateCharacter(player)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:4044

Stores the player's current inventory, ammo and data in their character table.

Parameters

  • player Player The player

cw.player:UpdateCharacterData(player, key, value)

server internal gamemodes/catwork/gamemode/core/libraries/sv_player.lua:67

Internal

This function is internal. It is not part of the public API and may change without notice.

Called by Player:SetCharacterData.

Networks a character data value registered with cw.player:AddCharacterData.

The value is passed through the registered callback first. PhysDesc is sent as a DT string; every other key becomes a net var on the player. Keys that are not registered are not networked.

Parameters

  • player Player The player the data belongs to
  • key String Name of the character data
  • value Any The new value

cw.player:UpdatePlayerData(player, key, value)

server internal gamemodes/catwork/gamemode/core/libraries/sv_player.lua:93

Internal

This function is internal. It is not part of the public API and may change without notice.

Called by Player:SetData.

Networks a player data value registered with cw.player:AddPlayerData.

The value is passed through the registered callback first and set as a net var on the player. Keys that are not registered are not networked.

Parameters

  • player Player The player the data belongs to
  • key String Name of the player data
  • value Any The new value

cw.player:UseCharacter(player, characterID)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:2206

Switches the player to one of their characters if they are allowed to.

Checks PlayerCanUseCharacter, the faction limit (unless PlayerCanBypassFactionLimit returns true) and PlayerCanSwitchCharacter, then loads the character with cw.player:LoadCharacter. If the character menu was reset, the current character is respawned instead.

Parameters

  • player Player The player
  • characterID Number The character slot

Returns

  • Boolean Whether the character is being used
  • String The reason if it is not

cw.player:UseDeathCode(player, commandTable, arguments)

server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1851

Uses up the player's death code after they act while knocked out.

Fires PlayerDeathCodeUsed and takes the code.

Parameters

  • player Player The player
  • commandTable Command optional, defaults to nil The command the code was used for, or nil for chat
  • arguments List<String> The command arguments or the chat text

See also

Defined in