Player

Physical representation of connected player.

Players are a type of Entity. They are a physical representation of a Character - and can possess at most one Character object at a time that you can interface with.

See the Garry's Mod Wiki for all other methods that the Player class has.

Functions

Player:CanShootWeapon()

View source »

Returns true if the player is able to shoot their weapon.

Returns

  • bool

    Whether or not the player can shoot their weapon

Player:ChatNotify(message)

View source »

Displays a notification for this player in the chatbox.

Parameters

  • message string

    Text to display in the notification

Player:ChatNotifyLocalized(message, ...)

View source »

Displays a notification for this player in the chatbox with the given language phrase.

Parameters

  • message string

    ID of the phrase to display to the player

  • ...

    Arguments to pass to the phrase

See Also

Player:CreateServerRagdoll(bDontSetPlayer)

View source »

Creates a ragdoll entity of this player that will be synced with clients. This does not affect the player like SetRagdolled does.

Parameters

  • bDontSetPlayer boolean default: false

    Whether or not to avoid setting the ragdoll's owning player

Returns

  • entity

    Created ragdoll entity

Player:DoStaredAction(entity, callback, time, onCancel, distance)

View source »

Performs a time-delay action that requires this player to look at an entity. If this player looks away from the entity before the action timer completes, the action is cancelled. This is usually used in conjunction with SetAction to display progress to the player.

Parameters

  • entity Entity

    that this player must look at

  • callback function

    Function to call when the timer completes

  • time number

    How much time in seconds this player must look at the entity for

  • onCancel function default: nil

    Function to call when the timer has been cancelled

  • distance number default: 96

    Maximum distance a player can move away from the entity before the action is cancelled

Example Usage

client:SetAction("Searching...", 4) -- for displaying the progress bar
client:DoStaredAction(entity, function()
	print("hello!")
end)
-- prints "hello!" after looking at the entity for 4 seconds

See Also

Player:ForceSequence(sequence, callback, time, bNoFreeze)

View source »

Forces this player's model to play an animation sequence. It also prevents the player from firing their weapon while the animation is playing.

Parameters

  • sequence string

    Name of the animation sequence to play

  • callback function default: nil

    Function to call when the animation finishes. This is also called immediately if the animation fails to play

  • time number default: nil

    How long to play the animation for. This defaults to the duration of the animation

  • bNoFreeze boolean default: false

    Whether or not to avoid freezing this player in place while the animation is playing

See Also

Player:GetCharacter()

View source »

Returns this player's currently possessed Character object if it exists.

Returns

  • Character

    Currently loaded character

  • OR
  • nil

    If this player has no character loaded

Player:GetItemDropPos(entity)

View source »

Returns a good position in front of the player for an entity to be placed. This is usually used for item entities.

Parameters

  • entity Entity

    Entity to get a position for

Returns

  • vector

    Best guess for a good drop position in front of the player

Example Usage

local position = client:GetItemDropPos(entity)
 entity:SetPos(position)

Player:GetLocalVar(key, default)

View source »

Retrieves a local networked variable. If it is not set, it'll return the default that you've specified. Locally networked variables can only be retrieved from the owning player when used from the client.

Parameters

  • key string

    Identifier of the local variable

  • default

    Default value to return if the local variable is not set

Returns

  • any

    Value associated with the key, or the default that was given if it doesn't exist

Example Usage

print(client:GetLocalVar("secret"))
 > 12345678

See Also

Player:GetName()

View source »

Returns this player's current name.

Returns

  • string

    Name of this player's currently loaded character

  • OR
  • string

    Steam name of this player if the player has no character loaded

Player:GetPlayTime()

View source »

Returns the amount of time the player has played on the server.

Returns

  • number

    Number of seconds the player has played on the server

Player:IsFemale()

View source »

Returns true if the player currently has a female model. This checks if the model has female, alyx or mossman in its name, or if the player's model class is citizen_female.

Returns

  • bool

    Whether or not the player has a female model

Player:IsRestricted()

View source »

Returns true if the player is restricted - that is to say that they are considered "bound" and cannot interact with objects normally (e.g hold weapons, use items, etc). An example of this would be a player in handcuffs.

Returns

  • bool

    Whether or not the player is restricted

Player:IsRunning()

View source »

Returns true if the player is running. Running in this case means that their current speed is greater than their regularly set walk speed.

Returns

  • bool

    Whether or not the player is running

Player:IsStuck()

View source »

Whether or not this player is stuck and cannot move.

Returns

  • bool

    Whether or not this player is stuck

Player:IsWepRaised()

View source »

Returns true if the player has their weapon raised.

Returns

  • bool

    Whether or not the player has their weapon raised

Player:LeaveSequence()

View source »

Forcefully stops this player's model from playing an animation that was started by ForceSequence.

Player:Notify(message)

View source »

Displays a prominent notification in the top-right of this player's screen.

Parameters

  • message string

    Text to display in the notification

Player:NotifyLocalized(message, ...)

View source »

Displays a notification for this player with the given language phrase.

Parameters

  • message string

    ID of the phrase to display to the player

  • ...

    Arguments to pass to the phrase

Example Usage

client:NotifyLocalized("mapRestarting", 10)
 -- displays "The map will restart in 10 seconds!" if the player's language is set to English

See Also

Player:PerformInteraction(time, entity, callback)

View source »

Performs a delayed action that requires this player to hold use on an entity. This is displayed to this player as a closing ring over their crosshair.

Parameters

  • time number

    How much time in seconds this player has to hold use for

  • entity Entity

    Entity that this player must be looking at

  • callback function

    Function to run when the timer completes. It will be ran right away if time is 0. Returning false in the callback will not mark this interaction as dirty if you're managing the interaction state manually.

Player:RequestString(title, subTitle, callback, default)

View source »

Opens up a text box on this player's screen for input and returns the result. Remember to sanitize the user's input if it's needed!

Parameters

  • title string

    Title to display on the panel

  • subTitle string

    Subtitle to display on the panel

  • callback function

    Function to run when this player enters their input. Callback is ran with the user's input string.

  • default string default: nil

    Default value to put in the text box.

Example Usage

client:RequestString("Hello", "Please enter your name", function(text)
	client:ChatPrint("Hello, " .. text)
end)
-- prints "Hello, " in the player's chat

Player:ResetBodygroups()

View source »

Resets all bodygroups this player's model has to their defaults (0).

Player:SetAction(text, time, callback, startTime, finishTime)

View source »

Displays a progress bar for this player that takes the given amount of time to complete.

Parameters

  • text string

    Text to display above the progress bar

  • time number default: 5

    How much time in seconds to wait before the timer completes

  • callback function

    Function to run once the timer completes

  • startTime number default: CurTime()

    Game time in seconds that the timer started. If you are using time, then you shouldn't use this argument

  • finishTime number default: startTime + time

    Game time in seconds that the timer should complete at. If you are using time, then you shouldn't use this argument

Player:SetLocalVar(key, value)

View source »

Sets the value of a local networked variable.

Parameters

  • key string

    Identifier of the local variable

  • value

    New value to assign to the local variable

Example Usage

client:SetLocalVar("secret", 12345678)

See Also

Player:SetRagdolled(bState, time, getUpGrace)

View source »

Sets this player's ragdoll status.

Parameters

  • bState boolean

    Whether or not to ragdoll this player

  • time number default: 0

    How long this player should stay ragdolled for. Set to 0 if they should stay ragdolled until they get back up manually

  • getUpGrace number default: 5

    How much time in seconds to wait before the player is able to get back up manually. Set to the same number as time to disable getting up manually entirely

Player:SetRestricted(bState, bNoMessage)

View source »

Sets this player's restricted status.

Parameters

  • bState boolean

    Whether or not to restrict this player

  • bNoMessage boolean

    Whether or not to suppress the restriction notification

Player:SetWepRaised(bState, weapon)

View source »

Sets whether or not this player's current weapon is raised.

Parameters

  • bState boolean

    Whether or not the raise the weapon

  • weapon Entity default: GetActiveWeapon()

    Weapon to raise or lower. You should pass this argument if you already have a reference to this player's current weapon to avoid an expensive lookup for this player's current weapon.

Player:SyncVars()

Internal

This is an internal function! You are able to use it, but you risk unintended side effects if used incorrectly.

View source »

Synchronizes networked variables to the client.

Player:ToggleWepRaised()

View source »

Inverts this player's weapon raised state. You should use SetWepRaised instead of this if you already have a reference to this player's current weapon.