Spawn Points lets staff choose where players appear on the map. A spawn point is a position, a facing direction and a group. The group says who the point is for: default is for everyone and faction:<faction ID> for the characters of a faction. Factions need the Factions plugin; the plugin works without it, with default points only. Points are saved separately for every map. The group names are built and taken apart by SpawnPoints:make_group and SpawnPoints:split_group, which take any kind, so a plugin can add a kind of its own and resolve it through the GetPlayerSpawnPoint hook.

Staff with the 'spawnpoints' permission place and remove points with the Spawn Point Tool. While the tool is held, every point is drawn in the world as a box of the size of a player with a line that shows its direction and a label that names its group.

When a player spawns, the server looks at the groups the player belongs to, the most specific one first: their faction, then default. The first group that has any points is used, and the player is put at a random point of it that nobody is standing on. Without any points the map's own spawn is used. The GetPlayerSpawnPoint hook can replace the choice or turn it down.

The point is handed to the game through PlayerSelectSpawn, the same way a map's spawn entity would be, so the player is never moved after they have spawned. A plugin that puts a player back where they were can simply set their position once they have spawned.

-- Server: a point for everyone and a point for the 'police' faction.
SpawnPoints:add_point(Vector(0, 0, 64), Angle(0, 90, 0))
SpawnPoints:add_point(Vector(512, 0, 64), Angle(0, 180, 0), 'faction:police')

Summary

Hooks

Draws the label of every spawn point above it: its number and the group it is for.
Keeps track of whether the local player is editing spawn points.
Loads the spawn points when the framework loads its data.
Gives the game the spawn point of a player, in place of a spawn entity of the map.
Draws every spawn point as a box of the size of a player, with a line at eye height that shows which way a player spawning there faces.
Registers the 'spawnpoints' level design permission.

Methods

Adds a spawn point, saves the list and sends it to the staff who edit spawn points.
Chooses the spawn point for a player: a random free point of the first of the player's groups that has any points.
Finds the spawn point a ray runs through, taking each point for a box of the size of a player.
Finds the spawn point that is closest to a position.
get_anchor()server internal
Returns the entity that stands in for the chosen spawn point.
Finds the spot on the ground where a player stands, or the spot they would land on when they are in the air or noclipping.
Returns the color a group is drawn with: the color of the faction, or SpawnPoints.color_default for default and for groups that are not valid any more.
Returns the translated text that describes a group in the tool settings and on the labels of the points, such as 'Everyone' or 'Faction: Police'.
Returns the name of who a group stands for: the name of the faction, or the 'ui.spawnpoints.group.default' phrase for default.
Returns every group that spawn points can be placed for: default, then the registered factions sorted by ID.
Returns the spawn point groups a player belongs to, the most specific one first: the faction of their character, then default.
Returns the spawn points of a group, or all of them.
Checks whether a player can be put on a spawn point without getting stuck in another player.
Checks whether the local player is holding the Spawn Point Tool and may use it, which is when the spawn points are drawn.
Checks whether a group can be given spawn points right now: it is default or a registered faction.
load()server
Reads the spawn points of the current schema and map from the plugin data, replacing the current list.
Builds the name of a spawn point group.
Picks a random point of a list, preferring the points that nobody stands on.
Removes a spawn point, saves the list and sends it to the staff who edit spawn points.
save()server
Writes the spawn points to the plugin data of the current schema and map.
Replaces the local list of spawn points and prepares the label and the color each point is drawn with.
Takes the name of a spawn point group apart.
Sends the whole list of spawn points to the clients that draw them.

Hooks

SpawnPoints:HUDPaint()

client plugins/spawnpoints/plugin/cl_hooks.lua:58

Draws the label of every spawn point above it: its number and the group it is for. Only drawn while the Spawn Point Tool is held.

SpawnPoints:LazyTick()

client plugins/spawnpoints/plugin/cl_hooks.lua:12

Implements hook LazyTick

Keeps track of whether the local player is editing spawn points. The points are asked for every time the tool is taken out, and again every couple of seconds until the server has answered, so that the list is fresh and a permission given later is picked up.

SpawnPoints:LoadData()

server plugins/spawnpoints/plugin/sv_hooks.lua:5

Implements hook LoadData

Loads the spawn points when the framework loads its data.

SpawnPoints:PlayerSelectSpawn(actor, transition)

server plugins/spawnpoints/plugin/sv_hooks.lua:19

Gives the game the spawn point of a player, in place of a spawn entity of the map. The game puts the player at the returned entity and turns them the way it faces before any spawn hook runs, so whatever moves the player afterwards keeps the last word. Nothing is returned, which leaves the choice to the map, for a level transition, for a player who has no character to spawn as, and when no point has been chosen.

Parameters

  • actor Player the player who is spawning
  • transition Boolean whether the player is arriving through a level transition

Returns

  • Entity the stand-in entity moved to the chosen point, or nil to use the spawn of the map

See also

SpawnPoints:PostDrawOpaqueRenderables(draw_depth, draw_skybox)

client plugins/spawnpoints/plugin/cl_hooks.lua:38

Draws every spawn point as a box of the size of a player, with a line at eye height that shows which way a player spawning there faces. Only drawn while the Spawn Point Tool is held.

Parameters

  • draw_depth Boolean whether the depth pass is being drawn
  • draw_skybox Boolean whether the skybox is being drawn

SpawnPoints:RegisterPermissions()

shared plugins/spawnpoints/plugin/sh_plugin.lua:48

Implements hook RegisterPermissions

Registers the 'spawnpoints' level design permission.

Methods

SpawnPoints:add_point(pos, ang, group)

server plugins/spawnpoints/plugin/sv_plugin.lua:79

Adds a spawn point, saves the list and sends it to the staff who edit spawn points. The group is stored as it is given, so that points can be placed for a faction before it is registered; see SpawnPoints:is_valid_group for checking it first.

SpawnPoints:add_point(actor:GetPos(), actor:EyeAngles(), SpawnPoints:make_group('faction', 'police'))

Parameters

  • pos Vector where the feet of a spawning player are put
  • ang Angle optional, defaults to nil the direction a spawning player faces; only the yaw is kept
  • group String optional, defaults to 'default' group the point is for, see SpawnPoints:make_group

Returns

  • Map the new point with its pos, ang and group; nil if the position is not a vector

SpawnPoints:choose_point(actor)

server plugins/spawnpoints/plugin/sv_plugin.lua:211

Chooses the spawn point for a player: a random free point of the first of the player's groups that has any points. The GetPlayerSpawnPoint hook can replace the choice.

Parameters

  • actor Player

Returns

  • Map the point to spawn the player at, with a pos and possibly an ang; nil to leave the player to the spawn of the map

See also

SpawnPoints:find_aimed_point(start, direction, distance)

shared plugins/spawnpoints/plugin/sh_plugin.lua:210

Finds the spawn point a ray runs through, taking each point for a box of the size of a player. When the ray runs through several points, the first one it enters is returned.

local index, point = SpawnPoints:find_aimed_point(actor:GetShootPos(), actor:GetAimVector(), 1024)

Parameters

  • start Vector where the ray starts
  • direction Vector normalized direction of the ray
  • distance Number length of the ray

Returns

  • Number index of the point in SpawnPoints.points
  • Map the point; nothing if the ray does not run through any point

SpawnPoints:find_nearest_point(pos, radius)

shared plugins/spawnpoints/plugin/sh_plugin.lua:235

Finds the spawn point that is closest to a position.

Parameters

  • pos Vector
  • radius Number optional, defaults to 64 how far from the position a point may be

Returns

  • Number index of the point in SpawnPoints.points
  • Map the point; nothing if there is no point within the radius

SpawnPoints:get_anchor()

server internal plugins/spawnpoints/plugin/sv_plugin.lua:250

Internal

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

Returns the entity that stands in for the chosen spawn point. The game only spawns players at entities, so the plugin keeps one invisible point entity and moves it to the point a player is about to spawn at. It is created again if something has removed it.

Returns

  • Entity the stand-in entity; nil if it could not be created

SpawnPoints:get_floor_position(actor)

server plugins/spawnpoints/plugin/sv_plugin.lua:118

Finds the spot on the ground where a player stands, or the spot they would land on when they are in the air or noclipping. This is where the Spawn Point Tool puts a new point.

Parameters

  • actor Player

Returns

  • Vector position for the feet of a player; nil if the player is inside of something solid or there is no ground below them

SpawnPoints:get_group_color(group)

shared plugins/spawnpoints/plugin/sh_plugin.lua:167

Returns the color a group is drawn with: the color of the faction, or SpawnPoints.color_default for default and for groups that are not valid any more.

Parameters

  • group String group, such as 'default' or 'faction:police'

Returns

  • Color

SpawnPoints:get_group_label(group)

shared plugins/spawnpoints/plugin/sh_plugin.lua:152

Returns the translated text that describes a group in the tool settings and on the labels of the points, such as 'Everyone' or 'Faction: Police'.

Parameters

  • group String group, such as 'default' or 'faction:police'

Returns

  • String

SpawnPoints:get_group_name(group)

shared plugins/spawnpoints/plugin/sh_plugin.lua:132

Returns the name of who a group stands for: the name of the faction, or the 'ui.spawnpoints.group.default' phrase for default. The name can be a language phrase and is not translated here.

Parameters

  • group String group, such as 'default' or 'faction:police'

Returns

  • String name or language phrase; the ID when the faction is not registered

SpawnPoints:get_groups()

shared plugins/spawnpoints/plugin/sh_plugin.lua:111

Returns every group that spawn points can be placed for: default, then the registered factions sorted by ID.

Returns

  • List<String> groups

SpawnPoints:get_player_groups(actor)

server plugins/spawnpoints/plugin/sv_plugin.lua:190

Returns the spawn point groups a player belongs to, the most specific one first: the faction of their character, then default. They are read from the character itself, which is already in place when the player is spawned for a character that is being loaded.

Parameters

  • actor Player

Returns

  • List<String> groups; always ends with 'default'

SpawnPoints:get_points(group)

shared plugins/spawnpoints/plugin/sh_plugin.lua:186

Returns the spawn points of a group, or all of them. The server knows every point; a client only knows them while the local player has the 'spawnpoints' permission and has held the Spawn Point Tool.

Parameters

  • group String optional, defaults to nil group to return the points of; every point if nil

Returns

  • List<Map> points, each with pos, ang and group; a new list that is safe to change

SpawnPoints:is_point_free(point, ignore)

server plugins/spawnpoints/plugin/sv_plugin.lua:144

Checks whether a player can be put on a spawn point without getting stuck in another player. Only living, solid players count as being in the way.

Parameters

  • point Map spawn point
  • ignore Player optional, defaults to nil a player who is not in the way, usually the one who is spawning

Returns

  • Boolean

SpawnPoints:is_tool_held()

client plugins/spawnpoints/plugin/cl_plugin.lua:22

Checks whether the local player is holding the Spawn Point Tool and may use it, which is when the spawn points are drawn.

Returns

  • Boolean

SpawnPoints:is_valid_group(group)

shared plugins/spawnpoints/plugin/sh_plugin.lua:96

Checks whether a group can be given spawn points right now: it is default or a registered faction. Points of a group that is not valid any more are kept, but no player belongs to it.

Parameters

  • group String group, such as 'default' or 'faction:police'

Returns

  • Boolean

SpawnPoints:load()

server plugins/spawnpoints/plugin/sv_plugin.lua:6

Reads the spawn points of the current schema and map from the plugin data, replacing the current list. Does not send them to clients.

SpawnPoints:make_group(kind, id)

shared plugins/spawnpoints/plugin/sh_plugin.lua:65

Builds the name of a spawn point group.

SpawnPoints:make_group('faction', 'police') -- 'faction:police'
SpawnPoints:make_group('default') -- 'default'

Parameters

  • kind String 'default', 'faction' or any kind of a plugin's own
  • id String optional, defaults to nil faction ID, or the ID the kind takes; not used for 'default'

Returns

  • String the group, 'default' when the kind is 'default' or there is no ID

SpawnPoints:pick_point(points, ignore)

server plugins/spawnpoints/plugin/sv_plugin.lua:164

Picks a random point of a list, preferring the points that nobody stands on. When all of them are taken, any of them may be picked.

Parameters

  • points List<Map> spawn points to pick from
  • ignore Player optional, defaults to nil a player who is not in the way, usually the one who is spawning

Returns

  • Map the picked point, or nil if the list is empty

SpawnPoints:remove_point(index)

server plugins/spawnpoints/plugin/sv_plugin.lua:102

Removes a spawn point, saves the list and sends it to the staff who edit spawn points. Removing a point changes the indexes of the points after it.

Parameters

  • index Number index of the point in SpawnPoints.points

Returns

  • Map the removed point, or nil if there is no point with that index

Writes the spawn points to the plugin data of the current schema and map. Positions are stored as plain numbers and the direction as a yaw angle.

SpawnPoints:set_points(points)

client plugins/spawnpoints/plugin/cl_plugin.lua:7

Replaces the local list of spawn points and prepares the label and the color each point is drawn with.

Parameters

  • points List<Map> points sent by the server, each with pos, ang and group

SpawnPoints:split_group(group)

shared plugins/spawnpoints/plugin/sh_plugin.lua:81

Takes the name of a spawn point group apart.

local kind, id = SpawnPoints:split_group('faction:police') -- 'faction', 'police'

Parameters

  • group String group, such as 'default' or 'faction:police'

Returns

  • String 'default', 'faction' or whatever precedes the colon; nil when the group is not a group name at all
  • String the faction ID or whatever follows the colon; nil for 'default'

SpawnPoints:sync(target)

server plugins/spawnpoints/plugin/sv_plugin.lua:49

Sends the whole list of spawn points to the clients that draw them. Only players with the 'spawnpoints' permission are ever sent the points.

Parameters

  • target Player optional, defaults to nil who to send the points to; every player with the 'spawnpoints' permission if nil

Defined in