cw.player class
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
cw_gear entity.%s in a text with the name a player knows each given player by.PlayerSaveCharacterData hook.cw.player:AddCharacterData.PlayerAddToSavedInventory.RECOGNISE_SAVE level, as JSON.GetPlayerDefaultModel hook.GetPlayerDefaultSkin hook.cw.player:AddPlayerData.Wages net var.wages_name config.cw.player:SetWeapons can give back, and strips them.o (operator) flag.PlayerCanRestoreRecognisedName refuses.cw.player:GetDefaultModel.cw.player:GetDefaultSkin.Initialized net var.unragdoll action.cw.player:GetWeapons.cw.player:PauseUnragdollTime.cw.player:StartSound.door_cost config.cw.player:AddCharacterData.cw.player:AddPlayerData.Methods
cw.player:AddCharacterData(name, nwType, default, playerOnly, callback)
shared gamemodes/catwork/gamemode/core/libraries/sh_player.lua:146Registers 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
nilWhether the data is meant to be networked to its player only - callback Function optional, defaults to
nilCalled ascallback(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:164Registers 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
nilWhether the data is meant to be networked to its player only - callback Function optional, defaults to
nilCalled ascallback(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:2663Returns 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:246Returns 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
nilwhen the player cannot demote
See also
cw.player:CanHearPlayer(player, target, iAllowance)
shared gamemodes/catwork/gamemode/core/libraries/sv_player.lua:628On 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.5Trace fraction that counts as visible, seecw.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.5Fraction of the line of sight that must be clear
Returns
- Boolean Whether
playercan heartarget
Defined in
Returns whether the local player's inventory can take some more space.
Parameters
- space Number Space to add
Returns
- Boolean Whether the total stays within
cw.player:GetMaxSpace
See also
Returns whether the local player's inventory can take some more weight.
Parameters
- weight Number Weight to add
Returns
- Boolean Whether the total stays within
cw.player:GetMaxWeight
See also
cw.player:CanPromote(player, target)
shared gamemodes/catwork/gamemode/core/libraries/sh_player.lua:224Returns 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
nilwhen the player cannot promote
See also
cw.player:CanSeeEntity(player, target, iAllowance, tIgnoreEnts)
shared gamemodes/catwork/gamemode/core/libraries/sv_player.lua:785On 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.75Trace fraction that counts as visible - tIgnoreEnts List<Entity> optional, defaults to
nilEntities the trace ignores, ortrueto ignore every entity
Returns
- Boolean
trueif the entity is visible, otherwisenil
Aliases
cw.player.CanSeePlayercw.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.75Fraction of the trace that must be clear - ignoreEnts List<Entity> optional, defaults to
nilEntities the trace ignores; any other true value ignores every entity
Returns
- Boolean
trueif the entity can be seen,nilotherwise
Defined in
cw.player:CanSeeNPC(player, target, allowance, ignoreEnts)
client gamemodes/catwork/gamemode/core/libraries/cl_player.lua:348Returns 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.75Fraction of the trace that must be clear - ignoreEnts List<Entity> optional, defaults to
nilEntities the trace ignores; any other true value ignores every entity
Returns
- Boolean
trueif the NPC can be seen,nilotherwise
cw.player:CanSeePlayer(player, target, allowance, ignoreEnts)
client gamemodes/catwork/gamemode/core/libraries/cl_player.lua:384Returns 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.75Fraction of the trace that must be clear - ignoreEnts List<Entity> optional, defaults to
nilEntities the trace ignores; any other true value ignores every entity
Returns
- Boolean
trueif the player can be seen,nilotherwise
cw.player:CanSeePosition(player, position, iAllowance, tIgnoreEnts, targetEnt)
shared gamemodes/catwork/gamemode/core/libraries/sv_player.lua:809On 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.75Trace fraction that counts as visible - tIgnoreEnts List<Entity> optional, defaults to
nilEntities the trace ignores, ortrueto ignore every entity - targetEnt Entity optional, defaults to
nilAn entity the trace also ignores, usually the one being looked for
Returns
- Boolean
trueif the position is visible, otherwisenil
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.75Fraction of the trace that must be clear - ignoreEnts List<Entity> optional, defaults to
nilEntities the trace ignores; any other true value ignores every entity
Returns
- Boolean
trueif the position can be seen,nilotherwise
Defined in
cw.player:CharacterScreenAdd(player, character)
server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:3613Adds 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:2740Shows cinematic text with black bars to the player.
Parameters
- player Player The player, a list of players, or
nilfor everyone - text String The text
- color Color optional, defaults to
nilThe text color; defaults to white - barLength Number optional, defaults to
nilLength of the black bars, as used bycw.core:AddCinematicText - hangTime Number optional, defaults to
nilSeconds the text stays on screen; defaults to 3
cw.player:CinematicTextAll(text, color, hangTime)
server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:2753Shows cinematic text to every player who has initialized.
Parameters
- text String The text
- color Color optional, defaults to
nilThe text color; defaults to white - hangTime Number optional, defaults to
nilSeconds the text stays on screen; defaults to 3
cw.player:ClearName(player, status, isAccurate)
server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:2473Makes every player forget the player's character.
Fires PlayerNameCleared.
Parameters
- player Player The player to be forgotten
- status Number optional, defaults to
nilOnly affect players who recognise them at thisRECOGNISE_*level - isAccurate Boolean optional, defaults to
nilMatchstatusexactly instead of at least
See also
cw.player:ClearRecognisedNames(player, status, isAccurate)
server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:2444Makes the player forget the characters they recognise.
Fires PlayerRecognisedNamesCleared.
Parameters
- player Player The player
- status Number optional, defaults to
nilOnly forget players recognised at thisRECOGNISE_*level;nilforgets everyone - isAccurate Boolean optional, defaults to
nilMatchstatusexactly instead of at least
See also
cw.player:ConditionTimer(player, delay, Condition, Callback)
server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1235Calls 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
truewhile 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:3898Decodes 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:3642Decodes 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:3879Decodes a saved list of recognised character keys.
Parameters
- data String A JSON list of character keys
Returns
- Map
RECOGNISE_SAVEkeyed 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:1610Decodes 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:3562Returns 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:147Internal
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,forenameandsurnameorfullName,physDescandplugin(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:559Attaches 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
nilRemove 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:2173Deletes 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:886Clears 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
nilOnly disable property of the player's current character
cw.player:DoesRecognise(player, target, status, isAccurate)
shared gamemodes/catwork/gamemode/core/libraries/sv_player.lua:2090On 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_PARTIALThe minimumRECOGNISE_*level - isAccurate Boolean optional, defaults to
nilRequire exactlystatusinstead 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_PARTIALLowestRECOGNISE_*level that counts - isAccurate Boolean optional, defaults to
nilWhether the level must equalstatusinstead of reaching it
Returns
- Boolean Whether the player is recognised
Defined in
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
TargetKnowsnetwork variable
cw.player:DoRagdollDecayCheck(player, ragdoll)
server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:3157Starts 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:1284Calls 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
nilThe entity the player must look at; defaults totarget - 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
truewhile 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:2143Deletes 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:2311Replaces 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
%sper 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:736On 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
nilReturn 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
CurTimeit 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
0to100
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:2930Returns 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
nilAlso remove all of the player's ammo
Returns
- Map Amounts keyed by ammo type
Returns the local player's cash.
Returns
- Number The
Cashnetwork variable, or0
Returns the player's current character.
Parameters
- player Player The player
Returns
- Character The character table, or
nilif they have none loaded
cw.player:GetCharacterAmmoString(player, character, bRawTable)
server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:3810Returns 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
nilReturn the table instead of JSON
Returns
- String The ammo as JSON, or a
MapwithbRawTable
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,callbackandplayerOnlykeys, ornilif it is not registered
cw.player:GetCharacterDataString(player, character, bRawTable)
server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:3831Returns 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
nilReturn the table instead of JSON
Returns
- String The data as JSON, or a
MapwithbRawTable
Returns every character data type registered with cw.player:AddCharacterData.
Returns
- Map<Map> Data type definitions keyed by name, each with
default,nwType,callbackandplayerOnlykeys
cw.player:GetCharacterID(player)
server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:3664Returns the slot of the player's current character.
Parameters
- player Player The player
Returns
- Number The character slot, or
nilif they have no character loaded
cw.player:GetCharacterInventoryString(player, character, bRawTable)
server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:3863Returns 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
nilReturn the inventory instead of JSON
Returns
- String The saveable inventory as JSON, or an
InventorywithbRawTable
cw.player:GetCharacterKey(player)
client gamemodes/catwork/gamemode/core/libraries/cl_player.lua:538Returns the key of a player's character, used to identify it in recognition data.
Parameters
- player Player The player
Returns
- Number The
Keynetwork variable, ornilif the player is not valid
cw.player:GetCharacterRecognisedNamesString(player, character)
server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:3846Returns 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:3580Loads 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 withnilif 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.pngif the player is not valid
Returns the local player's clothes data as sent by the server.
Returns
- Map The clothes item's
uniqueIDanditemID, bothnilwhen no clothes are worn
Returns the clothes item the local player is wearing.
Returns
- Item The clothes item from the inventory, or
nilif none is worn
cw.player:GetDeathCode(player, authenticated)
server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1861Returns the player's death code.
Parameters
- player Player The player
- authenticated Boolean optional, defaults to
nilOnly return the code if the player has authenticated it
Returns
- Number The code, or
nilif there is none
cw.player:GetDefaultModel(player)
shared gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1093On 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
- String The model path, from
cw.class:GetAppropriateModel
Defined in
cw.player:GetDefaultSkin(player)
shared gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1080On 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
- Number The skin, from
cw.class:GetAppropriateModel
Defined in
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
nilif the player is sober
On the client
Returns how drunk the local player is.
Parameters
- player
Returns
- Number The
IsDrunknetwork variable, ornilif the player is sober
Defined in
cw.player:GetEquippedSpace(player)
server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:3019Returns 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:3002Returns 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:181Returns 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
characteris given - character Character optional, defaults to
nilA 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, ornilif the rank does not exist
cw.player:GetFactionTable(player)
server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:2009Returns the faction table of the player's current faction.
Parameters
- player Player The player
Returns
- Faction The faction, or
nilif it does not exist
cw.player:GetGear(player, gearClass)
server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:120Returns one of the player's gear entities.
Parameters
- player Player The player
- gearClass String The gear slot, as passed to
cw.player:CreateGear
Returns
- Entity The
cw_gearentity, ornilif there is none in that slot
cw.player:GetHolsteredWeapon(player)
server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:3036Returns the class of an item weapon the player carries but is not holding.
Parameters
- player Player The player
Returns
- String The weapon class, or
nilif there is none
cw.player:GetMaximumCharacters(player)
shared gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1477On 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:2116On 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
- String Their character name if the local player recognises them, otherwise
cw.player:GetUnrecognisedName
Defined in
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
nilfor 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.clientThe 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,callbackandplayerOnlykeys, ornilif it is not registered
Returns every player data type registered with cw.player:AddPlayerData.
Returns
- Map<Map> Data type definitions keyed by name, each with
default,nwType,callbackandplayerOnlykeys
cw.player:GetPlayerFlags(player)
server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:4217Returns 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:2562Returns how many entities the player's current character owns.
Parameters
- player Player The player
- class String optional, defaults to
nilOnly 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:2540Returns the property of the player's current character.
Parameters
- player Player The player
- class String optional, defaults to
nilOnly return entities of this class
Returns
- List<Entity> The owned entities
cw.player:GetRagdollEntity(player)
shared gamemodes/catwork/gamemode/core/libraries/sv_player.lua:3136On the server
Returns the player's ragdoll entity.
Parameters
- player Player The player
Returns
- Entity The ragdoll, or
nilif there is none
On the client
Returns a player's ragdoll entity.
Parameters
- player Player The player
Returns
- Entity The ragdoll, or
nilif the player is not ragdolled
Defined in
cw.player:GetRagdollState(player)
shared gamemodes/catwork/gamemode/core/libraries/sv_player.lua:3129On 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, orfalseif it is unset
Defined in
cw.player:GetRagdollTable(player)
server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:3147Returns 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,immunityand so on), ornil
cw.player:GetRealTrace(player, useFilterTrace)
shared gamemodes/catwork/gamemode/core/libraries/sv_player.lua:2060On 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
nilAlways 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
nilWhether to always use the hitbox trace
Returns
- Map The
TraceResult, ornilif the player is not valid
Defined in
cw.player:GetSafePosition(player, position, filter, margin)
server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1560Returns 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
filteris given - position Vector The center position
- filter Any optional, defaults to
nilTrace filter; defaults to the player - margin Number optional, defaults to
3Grid radius in steps; the step size ismargin * 10units
Returns
- List<Vector> The free positions
cw.player:GetSpawnAmmo(player, ammo)
server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1329Returns the ammo the player was given on spawn.
Parameters
- player Player The player
- ammo String optional, defaults to
nilAn ammo type;nilreturns the whole table
Returns
- Number The amount of that ammo type, or a
Mapof amounts by ammo type whenammoisnil
cw.player:GetSpawnWeapon(player, weapon)
server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1341Returns whether a weapon was given to the player on spawn.
Parameters
- player Player The player
- weapon String The weapon class
Returns
- Boolean
trueif it is a spawn weapon, otherwisenil
cw.player:GetUnragdollTime(player)
server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:3116Returns when the player gets up.
Parameters
- player Player The player
Returns
- Number The
CurTimethe player gets up at, or0if no countdown is running
cw.player:GetUnrecognisedName(player, bFormatted)
shared gamemodes/catwork/gamemode/core/libraries/sv_player.lua:2280On 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
nilShorten 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_nameconfig if there is none - Boolean
trueif 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
Wagesnetwork variable
Defined in
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 thewages_nameconfig
Defined in
cw.player:GetWeaponClass(player, safe)
server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:4147Returns the class of the player's active weapon.
Parameters
- player Player The player
- safe Any optional, defaults to
nilValue 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:839On the server
Returns whether the player's weapon is raised.
Parameters
- player Player The player
- bIsCached Boolean optional, defaults to
nilUnused
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
- Boolean Whether the weapon is raised, from
Player:IsWeaponRaised
Defined in
cw.player:GetWeapons(player, bDoKeep)
server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:2971Returns 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
nilDo not strip the weapons
Returns
- List<Map> One entry per weapon with
weaponData(classanditemTable) andteamIndex(only for spawn weapons)
cw.player:GiveAmmo(player, ammo)
server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:2912Gives 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:2686Gives 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
nilShown in the hint after the amount - bNoMsg Boolean optional, defaults to
nilDo not show a hint
See also
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:2024Gives 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
nilText to show on the door - unsellable Boolean optional, defaults to
nilPrevent the player from selling the door - override Boolean optional, defaults to
nilGive 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:2615Gives the player's current character access to a door.
Parameters
- player Player The player
- door Entity The door
- access Number
DOOR_ACCESS_BASICorDOOR_ACCESS_COMPLETE
See also
cw.player:GiveFlags(player, flags)
server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1433Gives 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:1406Gives the player the weapon of a weapon item.
Parameters
- player Player The player
- itemTable Item The weapon item
Returns
- Boolean
trueif the item is a weapon, otherwisenil
cw.player:GivePlayerFlags(player, flags)
server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1452Gives 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:921Makes 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
nilAlso set theOwnernetworked entity for clients - removeDelay Number optional, defaults to
nilSeconds 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:964Makes 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
nilAlso set theOwnernetworked entity for clients - removeDelay Number optional, defaults to
nilSeconds after the owner leaves before the entity is removed
cw.player:GiveSpawnAmmo(player, ammo, amount)
server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1374Gives 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:1417Gives 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
trueif the item is a weapon, otherwisenil
cw.player:GiveSpawnWeapon(player, class)
server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1397Gives 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
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:1703On 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
nilOnly check the character's own flags and user group
Returns
- Boolean
trueif the player has any of the flags, otherwisenil
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
nilWhether to ignore the class flags and the hook
Returns
- Boolean
trueif the player has one of the flags,nilotherwise 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:2637Returns 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_BASICThe access level required - isAccurate Boolean optional, defaults to
nilRequire 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:1763On 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
nilOnly check the character's own flags and user group - bIsStrict Boolean optional, defaults to
nilRequire every flag
Returns
- Boolean
trueif the check passes, otherwisenil
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
nilWhether to ignore the class flags and the hook - bIsStrict Boolean optional, defaults to
nilWhether every flag is needed
Returns
- Boolean Whether the player has the flags;
nilif 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:112Runs 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
- Any The result of
cw.command:ConsoleCommand
On the server
Returns whether the player has the o (operator) flag.
Parameters
- player Player The player
Returns
- Boolean
trueif they have the flag, otherwisenil
See also
On the client
Returns whether a player has the operator flag (o).
Parameters
- player Player The player
Returns
- Boolean
trueif they have it,nilotherwise
See also
Defined in
On the server
Returns whether the player is noclipping outside a vehicle.
Parameters
- player Player The player
Returns
- Boolean
trueif noclipping, otherwisenil
On the client
Returns whether a player is noclipping outside a vehicle.
Parameters
- player Player The player
Returns
- Boolean
trueif they are noclipping,nilotherwise
Defined in
cw.player:IsProtected(identifier)
server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:2768Returns 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:3054On the server
Returns whether the player is ragdolled.
Parameters
- player Player The player
- exception Number optional, defaults to
nilARAGDOLL_*state that does not count as ragdolled - bNoEntity Boolean optional, defaults to
nilCheck the ragdoll state even if the player has no ragdoll entity
Returns
- Boolean Whether the player is ragdolled;
nilif they have no ragdoll entity
On the client
Returns whether a player is ragdolled.
Parameters
- player Player The player
- exception Number optional, defaults to
nilARAGDOLL_*state that does not count as ragdolled - entityless Boolean optional, defaults to
nilWhether to check the state even when the player has no ragdoll entity
Returns
- Boolean Whether the player is ragdolled, or
nilif they have no ragdoll entity andentitylessis not set
Defined in
cw.player:IsWearingAccessory(itemTable)
client gamemodes/catwork/gamemode/core/libraries/cl_player.lua:142Returns 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:156Returns 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
nilif no clothes are worn
cw.player:IsWhitelisted(player, faction)
server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1174Returns 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:3486Respawns 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
nilWeapons to give back;truekeeps the current ones - ammo Map optional, defaults to
nilAmmo to give back;truekeeps the current ammo - bForceReturn Boolean optional, defaults to
nilDo not get the player up, and passed on tocw.player:SetWeapons
cw.player:LoadCharacter(player, characterID, tMergeCreate, Callback, bForce)
server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:3693Loads 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
nilFields of a new character to create - Callback Function optional, defaults to
nilCalled without arguments once a new character is saved - bForce Boolean optional, defaults to
nilSkipPlayerCanCreateCharacter
cw.player:LoadData(player, Callback)
server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:3916Loads 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
nilCalled asCallback(player)once the data has loaded
See also
cw.player:Notify(player, text, class, icon)
server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:2866Notifies 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
nilfor everyone - text String The text
- class Any optional, defaults to
niltrueornilfor chat, or aNOTIFY_*number for a popup - icon String optional, defaults to
nilPath 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:2839Sends 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
nilPath of the icon shown next to the message
Sends a chat notification to every player.
Parameters
- text String The text
- icon String optional, defaults to
nilPath of the icon shown next to the message
cw.player:NotifyInRadius(text, class, position, radius)
server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:2810Notifies 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:3087Pauses 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:1467Plays a sound on the player's client.
Parameters
- player Player The player, a list of players, or
nilfor everyone - sound String Path of the sound file
cw.player:Query(player, key, default)
server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1497Returns 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
nilValue to return if there is no character or the field isnil
Returns
- Any The value, or
default
cw.player:RemoveGear(player, gearClass)
server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:530Removes 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:46Internal
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:26Internal
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:2334Re-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:2351Clears 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:1625Gives 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:763Runs 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
- Any The result of
cw.command:ConsoleCommand
cw.player:SaveCharacter(player, bCreate, character, Callback)
server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:4059Saves 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
nilInsert the character as a new row - character Character optional, defaults to
nilThe character to save; defaults to the current one - Callback Function optional, defaults to
nilWithbCreate, called asCallback(key)with the new row's key
cw.player:SaveData(player, bCreate)
server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:4000Saves 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
nilInsert a new row for the player instead of updating theirs
Returns
- Map An empty table when
bCreateis set, otherwise nothing
cw.player:SayRadio(player, text, check, noEavesdrop)
server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1945Broadcasts 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
nilAskPlayerCanRadiofirst - noEavesdrop Boolean optional, defaults to
nilDo not let nearby players hear it
cw.player:SetAction(player, action, duration, priority, Callback)
server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:671Starts 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;
falseor0stopsactionif it is running - priority Number optional, defaults to
nilPriority of the action against other actions - Callback Function optional, defaults to
nilCalled without arguments when the duration has passed
Returns
- Boolean
falseif asked to stop an action that is not running, otherwisenil
See also
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:2508Bans or unbans the player's current character and saves it.
Parameters
- player Player The player
- banned Boolean Whether the character is banned
cw.player:SetCharacterMenuOpen(player, bReset)
server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:475Opens the character menu for a player who has initialized.
Parameters
- player Player The player
- bReset Boolean optional, defaults to
falseAlso 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:721Sends 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:2127Tells the player's client that character creation failed.
Parameters
- player Player The player
- fault String optional, defaults to
nilThe reason; defaults to theCharFault_Unknownphrase
cw.player:SetDefaultModel(player)
server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1086Sets 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:1073Sets 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:1110Adds 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
falseto clear all drinks
See also
cw.player:SetFactionRank(player, rank)
server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:4184Sets 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:4165Replaces 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:1688Sets 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:1681Opens 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:2520Changes 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
nilDo not save the character afterwards
cw.player:SetNetVar(player, key, value)
shared gamemodes/catwork/gamemode/core/libraries/sh_player.lua:74Sets 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:4173Replaces 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:3183Sets how long the player's ragdoll is immune to damage.
Parameters
- player Player A ragdolled player
- delay Number Seconds of immunity, or
nilto remove it
cw.player:SetRagdollState(player, state, delay, decay, force, multiplier, velocityCallback)
server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:3213Knocks 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
nilSeconds until the player gets up on their own - decay Number optional, defaults to
nilSeconds the ragdoll takes to decay when the player gets up;nilremoves it - force Vector optional, defaults to
nilForce applied to the ragdoll's bones - multiplier Number optional, defaults to
nilUnused - velocityCallback Function optional, defaults to
nilCalled asvelocityCallback(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:2375Sets 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, orfalseto forget the target - bForce Boolean optional, defaults to
nilSet 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:1516Moves 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
nilAn 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:3070Sets when the player gets up, shown as the unragdoll action.
Parameters
- player Player The player
- delay Number Seconds until the player gets up, or
falseto cancel getting up
See also
cw.player:SetupRemovePropertyDelays(player, bAllCharacters)
server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:860Starts 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
nilInclude 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:853Raises or lowers the player's weapon.
Parameters
- player Player The player
- bIsRaised Boolean Whether the weapon should be raised
Returns
- Any The result of
Player:SetWeaponRaised
cw.player:SetWeapons(player, weapons, bForceReturn)
server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:2897Gives 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
nilPassed on toPlayer:Give
cw.player:SetWhitelisted(player, faction, isWhitelisted)
server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1185Adds 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:494Starts 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.75Volume from0to1
See also
cw.player:StartUnragdollTime(player)
server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:3103Resumes 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:513Stops 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
0Fade-out time in seconds
cw.player:StripDefaultAmmo(player, weapon, itemTable)
server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1131Removes 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
nilThe weapon's item; looked up from the weapon if not given
Removes all of the player's gear entities.
Parameters
- player Player The player
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:1897Takes 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
nilDo not refund the door - bThisDoorOnly Boolean optional, defaults to
nilDo not take the door's parent or children - bChildrenOnly Boolean optional, defaults to
nilTake 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:2604Removes 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:1648Takes 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:1666Takes 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:1051Removes 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:1016Removes 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
nilUnused
cw.player:TakeSpawnAmmo(player, ammo, amount)
server gamemodes/catwork/gamemode/core/libraries/sv_player.lua:1354Takes 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:1387Strips 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:845Raises 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:4044Stores 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:67Internal
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:93Internal
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:2206Switches 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:1851Uses 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
nilThe command the code was used for, ornilfor chat - arguments List<String> The command arguments or the chat text