S&box Wiki

Pawn

Pawn

What is a Pawn

A Pawn is an Entity any Client (player) can possess, this is the physical representation of your player within the world. This entity doesn't need to be anything specific, you can make it a physics object or a traditional animated player.

When a Client possesses a Pawn additional methods become active on the Entity:

There are several examples on how to use pawns in various ways:

  • sbox-minimal - a basic standard player pawn
  • sbox-netlab - a more complex pawn controlling it's own animations and movement

Setting a Client's Pawn

You can set the Client's Pawn at any point, a standard place to set it would be when the client first joins.

/// <summary> /// A client has joined the server. Make them a pawn to play with /// </summary> public override void ClientJoined( Client client ) { base.ClientJoined( client ); var player = new MinimalPlayer(); client.Pawn = player; player.Respawn(); }

Accessing Pawns

A good way to get all pawns in the game is to iterate through all clients and access their pawns:

// Loop through every Client (remember, these are our pawn owners) foreach ( var client in Client.All ) { // Always check if the pawn is assigned and the correct type if ( client.Pawn is not MyPawn pawn ) continue; pawn.Respawn(); }

Any time you want to access your pawn clientside you can do so through Local.Pawn:

public class MyHealth : Panel { Label healthLabel; // blah blah public override void Tick() { healthLabel.Text = $"Health: {Local.Pawn.Health}"; } }

Special Pages


Wikis

?

Render Time: 55ms

DB GetPage 45
Generate Html 1
SaveChanges (1) 5
Render Body 0
Render Sidebar 1