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
Methods
SpawnPoints.color_default for default and for groups that are not valid any more.default.default, then the registered factions sorted by ID.default.default or a registered faction.Hooks
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.
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.
Implements hook LoadData
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. 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:38Draws 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
Implements hook RegisterPermissions
Registers the 'spawnpoints' level design permission.
Methods
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
nilthe direction a spawning player faces; only the yaw is kept - group String optional, defaults to
'default'group the point is for, seeSpawnPoints:make_group
Returns
- Map the new point with its pos, ang and group; nil if the position is not a vector
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:210Finds 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
Finds the spawn point that is closest to a position.
Parameters
- pos Vector
- radius Number optional, defaults to
64how 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
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
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
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
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
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
Returns every group that spawn points can be placed for: default, then the registered
factions sorted by ID.
Returns
- List<String> groups
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'
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
nilgroup 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
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
nila player who is not in the way, usually the one who is spawning
Returns
- Boolean
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
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
Reads the spawn points of the current schema and map from the plugin data, replacing the current list. Does not send them to clients.
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
nilfaction 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
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
nila 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
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.
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
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'
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
nilwho to send the points to; every player with the 'spawnpoints' permission if nil