> For the complete documentation index, see [llms.txt](https://cuhhub.gitbook.io/noir/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cuhhub.gitbook.io/noir/api-reference/built-ins/services/playerservice.md).

# PlayerService

**Noir.Services.PlayerService**: `NoirService`

A service that wraps SW players in a class. Essentially makes players OOP.

***

```lua
Noir.Services.PlayerService:_LoadPlayers()
```

Load players current in-game and returns a table of players to register later.

Used internally.

### Returns

* `table<integer, NoirPlayer>`

***

```lua
Noir.Services.PlayerService:_CharacterLoad(player, character)
```

To be called when a player's character is loaded.

### Parameters

* `player`: NoirPlayer
* `character`: NoirObject

***

```lua
Noir.Services.PlayerService:_ConstructPlayer(steam_id, name, peer_id, admin, auth)
```

Makes data for a player. Returns nil if player is invalid (e.g.: unnamed client).

Used internally.

### Parameters

* `steam_id`: integer|string
* `name`: string
* `peer_id`: integer
* `admin`: boolean
* `auth`: boolean

### Returns

* `NoirPlayer|nil`

***

```lua
Noir.Services.PlayerService:_RegisterPlayer(player, triggerEvent)
```

Registers a player.

Used internally.

### Parameters

* `player`: NoirPlayer
* `triggerEvent`: boolean

***

```lua
Noir.Services.PlayerService:_RemovePlayerData(player)
```

Removes data for a player.

Used internally.

### Parameters

* `player`: NoirPlayer

***

```lua
Noir.Services.PlayerService:_IsHost(peer_id)
```

Returns whether or not a player is the server's host. Only applies in dedicated servers.

Used internally.

### Parameters

* `peer_id`: integer

### Returns

* `boolean`

***

```lua
Noir.Services.PlayerService:_MarkRecognized(player)
```

Mark a player as recognized to prevent onJoin being called for them after an addon reload.

Used internally.

### Parameters

* `player`: NoirPlayer

***

```lua
Noir.Services.PlayerService:_IsRecognized(peerID)
```

Returns whether or not a player is recognized.

Used internally.

### Parameters

* `peerID`: integer

### Returns

* `boolean`

***

```lua
Noir.Services.PlayerService:_ClearRecognized()
```

Clear the list of recognized players.

Used internally.

***

```lua
Noir.Services.PlayerService:_UnmarkRecognized(player)
```

Mark a player as not recognized.

Used internally.

### Parameters

* `player`: NoirPlayer

***

```lua
Noir.Services.PlayerService:GetPlayers(usePeerIDsAsIndex)
```

Returns all players.

This is the preferred way to get all players instead of using `Noir.Services.PlayerService.Players`.

### Parameters

* `usePeerIDsAsIndex`: boolean|nil - If true, the indices of the returned table will match the peer ID of the value (player) matched to the index. Having this as true is slightly faster

### Returns

* `table<integer, NoirPlayer>`

***

```lua
Noir.Services.PlayerService:GetPlayer(ID)
```

Returns a player by their peer ID.

This is the preferred way to get a player.

### Parameters

* `ID`: integer

### Returns

* `NoirPlayer|nil`

***

```lua
Noir.Services.PlayerService:GetPlayerBySteam(steam)
```

Returns a player by their Steam ID.

Note that two players or more can have the same Steam ID if they spoof their Steam ID or join the server on two Stormworks instances.

### Parameters

* `steam`: string

### Returns

* `NoirPlayer|nil`

***

```lua
Noir.Services.PlayerService:GetPlayerByName(name)
```

Returns a player by their exact name.

Consider using `:SearchPlayerByName()` if the player name only needs to match partially.

### Parameters

* `name`: string

### Returns

* `NoirPlayer|nil`

***

```lua
Noir.Services.PlayerService:GetPlayerByCharacter(character)
```

Get a player by their character.

### Parameters

* `character`: NoirObject

### Returns

* `NoirPlayer|nil`

***

```lua
Noir.Services.PlayerService:SearchPlayerByName(name)
```

Searches for a player by their name, similar to a Google search but way simpler under the hood.

### Parameters

* `name`: string

### Returns

* `NoirPlayer|nil`

***

```lua
Noir.Services.PlayerService:IsSamePlayer(playerA, playerB)
```

Returns whether or not two players are the same.

### Parameters

* `playerA`: NoirPlayer
* `playerB`: NoirPlayer

### Returns

* `boolean`


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://cuhhub.gitbook.io/noir/api-reference/built-ins/services/playerservice.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
