diff --git a/doc/index.html b/doc/index.html
index 8aa5b94..07f302d 100644
--- a/doc/index.html
+++ b/doc/index.html
@@ -88,6 +88,11 @@
register_after_spawn_callback (callback) |
Allows to register callbacks after a player has been spawned by spawn usher. |
+
+ register_spawnpoint_provider (provider) |
+ Allows to register providers that are called after the final position of
+ the player has been determined. |
+
@@ -275,6 +280,32 @@
+
+
+
+ register_spawnpoint_provider (provider)
+
+
+ Allows to register providers that are called after the final position of
+ the player has been determined. The provider can return a different position,
+ or nil if it is happy with the given position.
+
+
+
+ Parameters:
+
+ - provider
+ The provider. A function that accepts two parameters,
+ the Player object and the spawn position that the system
+ calculated. It can return a new position, a table with
+ x y z values, or nil if the position should not be changed.
+
+
+
+
+
+
+
diff --git a/mods/spawn_usher/spawnusher.lua b/mods/spawn_usher/spawnusher.lua
index 200a3d1..fa564ff 100644
--- a/mods/spawn_usher/spawnusher.lua
+++ b/mods/spawn_usher/spawnusher.lua
@@ -50,7 +50,8 @@ spawnusher = {
random_placement_radius = 40,
required_bubble_size = 2,
retry_time = 0.5,
- scheduled = false
+ scheduled = false,
+ spawnpoint_providers = List:new()
}
@@ -244,11 +245,22 @@ function spawnusher.on_spawn_player(player)
}
end
- player:setpos(spawn_pos)
-
-- Move the player randomly afterwards.
spawnusher.move_random(player)
+ player:setpos(spawn_pos)
+
+ -- Run the position through the providers.
+ spawnusher.spawnpoint_providers:foreach(function(provider, index)
+ local provided_pos = provider(player, spawn_pos)
+
+ if provided_pos ~= nil then
+ spawn_pos = provided_pos
+ end
+ end)
+
+ player:setpos(spawn_pos)
+
-- Now find a nice spawn place for the player.
spawnusher.move_player(player)
@@ -263,3 +275,15 @@ function spawnusher.register_after_spawn_callback(callback)
spawnusher.after_spawn_callbacks:add(callback)
end
+--- Allows to register providers that are called after the final position of
+-- the player has been determined. The provider can return a different position,
+-- or nil if it is happy with the given position.
+--
+-- @param provider The provider. A function that accepts two parameters,
+-- the Player object and the spawn position that the system
+-- calculated. It can return a new position, a table with
+-- x y z values, or nil if the position should not be changed.
+function spawnusher.register_spawnpoint_provider(provider)
+ spawnusher.spawnpoint_providers:add(provider)
+end
+