Added possibility to register spawnpoint providers.
parent
218a65a92c
commit
b4d0bab3d1
|
@ -88,6 +88,11 @@
|
||||||
<td class="name" nowrap><a href="#register_after_spawn_callback">register_after_spawn_callback (callback)</a></td>
|
<td class="name" nowrap><a href="#register_after_spawn_callback">register_after_spawn_callback (callback)</a></td>
|
||||||
<td class="summary">Allows to register callbacks after a player has been spawned by spawn usher.</td>
|
<td class="summary">Allows to register callbacks after a player has been spawned by spawn usher.</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="name" nowrap><a href="#register_spawnpoint_provider">register_spawnpoint_provider (provider)</a></td>
|
||||||
|
<td class="summary">Allows to register providers that are called after the final position of
|
||||||
|
the player has been determined.</td>
|
||||||
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<br/>
|
<br/>
|
||||||
|
@ -275,6 +280,32 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</dd>
|
||||||
|
<dt>
|
||||||
|
<a name = "register_spawnpoint_provider"></a>
|
||||||
|
<strong>register_spawnpoint_provider (provider)</strong>
|
||||||
|
</dt>
|
||||||
|
<dd>
|
||||||
|
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.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<h3>Parameters:</h3>
|
||||||
|
<ul>
|
||||||
|
<li><span class="parameter">provider</span>
|
||||||
|
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.
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</dd>
|
</dd>
|
||||||
</dl>
|
</dl>
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,8 @@ spawnusher = {
|
||||||
random_placement_radius = 40,
|
random_placement_radius = 40,
|
||||||
required_bubble_size = 2,
|
required_bubble_size = 2,
|
||||||
retry_time = 0.5,
|
retry_time = 0.5,
|
||||||
scheduled = false
|
scheduled = false,
|
||||||
|
spawnpoint_providers = List:new()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -244,11 +245,22 @@ function spawnusher.on_spawn_player(player)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
player:setpos(spawn_pos)
|
|
||||||
|
|
||||||
-- Move the player randomly afterwards.
|
-- Move the player randomly afterwards.
|
||||||
spawnusher.move_random(player)
|
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.
|
-- Now find a nice spawn place for the player.
|
||||||
spawnusher.move_player(player)
|
spawnusher.move_player(player)
|
||||||
|
|
||||||
|
@ -263,3 +275,15 @@ function spawnusher.register_after_spawn_callback(callback)
|
||||||
spawnusher.after_spawn_callbacks:add(callback)
|
spawnusher.after_spawn_callbacks:add(callback)
|
||||||
end
|
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
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue