Spawn Usher can now be configured from the configuration.

master
Robert Zenz 2015-09-12 16:08:39 +02:00
parent f591243212
commit 66eafdfa8c
4 changed files with 276 additions and 65 deletions

42
README
View File

@ -8,29 +8,29 @@ about the mapgen that is used.
Usage
=====
To activate the system, add it to your `depends.txt` and call this in your
`init.lua.`:
The system activates itself, you just need to add the mod to the subgame.
spawnusher.activate()
Configuration
=============
The system can be configured by adding settings to the `minetest.conf`:
# The radius around the spawnpoint in which the players will be randomly
# placed, defaults to 40.
spawnusher_placement_radius = 40.
-- With parameters.
spawnusher.activate(
40, -- random_placement_radius
2, -- required_bubble_size
0.5) -- retry_time
Optionally, you can set parameters when activating it, it accepts three
parameters:
1. `random_placement_radius`, the player will be randomly placed around
the spawn point inside the given radius.
Defaults to 40.
2. `required_bubble_size`, the size of the air bubble that is required for
the player to be placed there. Note this is only the vertical size.
Defaults to 2.
3. `retry_time`, if the player can't be placed because a block is not loaded
yet, this is the amount of time that is elapsed until a retry.
Defaults to 0.5 seconds.
# The size of the air bubble that is required for the player to be placed.
# Note that this is only the vertical size, defaults to 2.
# If you want to avoid spawns in caves, this value needs to be increased
# to a sensible value.
spawnusher_bubble_size = 2
# If the player can not be placed because the block is currently not loaded,
# this amount of time will be waited before it is retried to place
# place the player, defaults to 0.5.
# In seconds.
spawnusher_retry_time = 0.5
Providers

View File

@ -30,6 +30,8 @@
<h2>Contents</h2>
<ul>
<li><a href="#Functions">Functions</a></li>
<li><a href="#Tables">Tables</a></li>
<li><a href="#Fields">Fields</a></li>
</ul>
@ -57,8 +59,9 @@
<h2><a href="#Functions">Functions</a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#activate">activate (random_placement_radius, required_bubble_size, retry_time)</a></td>
<td class="summary">Activates the spawn usher system.</td>
<td class="name" nowrap><a href="#activate">activate ()</a></td>
<td class="summary">Activates the spawn usher system, if it has not been deactivated by
a seeting in the configuration.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#is_air_bubble">is_air_bubble (start_pos)</a></td>
@ -94,6 +97,52 @@
the player has been determined.</td>
</tr>
</table>
<h2><a href="#Tables">Tables</a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#physics_override">physics_override</a></td>
<td class="summary">The physics override that is set to make the player inmovable.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#player_physics">player_physics</a></td>
<td class="summary">The original physics of the payers.</td>
</tr>
</table>
<h2><a href="#Fields">Fields</a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#after_spawn_callbacks">after_spawn_callbacks</a></td>
<td class="summary">The list of callbacks that are invoked after the player has been placed.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#players">players</a></td>
<td class="summary">The list of players that need to be placed.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#random">random</a></td>
<td class="summary">The random object that is used to get random values.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#random_placement_radius">random_placement_radius</a></td>
<td class="summary">The placement radius around the spawn.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#required_bubble_size">required_bubble_size</a></td>
<td class="summary">The required air bubble size.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#retry_time">retry_time</a></td>
<td class="summary">The retry time.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#scheduled">scheduled</a></td>
<td class="summary">If the system is currently scheduled for execution.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#spawnpoint_providers">spawnpoint_providers</a></td>
<td class="summary">The registered spawnpoint providers.</td>
</tr>
</table>
<br/>
<br/>
@ -103,28 +152,13 @@
<dl class="function">
<dt>
<a name = "activate"></a>
<strong>activate (random_placement_radius, required_bubble_size, retry_time)</strong>
<strong>activate ()</strong>
</dt>
<dd>
Activates the spawn usher system.
Activates the spawn usher system, if it has not been deactivated by
a seeting in the configuration.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">random_placement_radius</span>
Optional. The player will be respawned in
the given radius around the spawn point.
</li>
<li><span class="parameter">required_bubble_size</span>
Optional. The size/height of the bubble of
air that is required for the player to spawn.
Defaults to 2.
</li>
<li><span class="parameter">retry_time</span>
Optional. This is the time that passes between tries to
place to the player.
</li>
</ul>
@ -309,6 +343,170 @@
</dd>
</dl>
<h2><a name="Tables"></a>Tables</h2>
<dl class="function">
<dt>
<a name = "physics_override"></a>
<strong>physics_override</strong>
</dt>
<dd>
The physics override that is set to make the player inmovable.
<h3>Fields:</h3>
<ul>
<li><span class="parameter">speed</span>
</li>
<li><span class="parameter">jump</span>
</li>
<li><span class="parameter">gravity</span>
</li>
<li><span class="parameter">sneak</span>
</li>
<li><span class="parameter">sneak_glitch</span>
</li>
</ul>
</dd>
<dt>
<a name = "player_physics"></a>
<strong>player_physics</strong>
</dt>
<dd>
The original physics of the payers.
</dd>
</dl>
<h2><a name="Fields"></a>Fields</h2>
<dl class="function">
<dt>
<a name = "after_spawn_callbacks"></a>
<strong>after_spawn_callbacks</strong>
</dt>
<dd>
The list of callbacks that are invoked after the player has been placed.
</dd>
<dt>
<a name = "players"></a>
<strong>players</strong>
</dt>
<dd>
The list of players that need to be placed.
</dd>
<dt>
<a name = "random"></a>
<strong>random</strong>
</dt>
<dd>
The random object that is used to get random values.
</dd>
<dt>
<a name = "random_placement_radius"></a>
<strong>random_placement_radius</strong>
</dt>
<dd>
The placement radius around the spawn.
</dd>
<dt>
<a name = "required_bubble_size"></a>
<strong>required_bubble_size</strong>
</dt>
<dd>
The required air bubble size.
</dd>
<dt>
<a name = "retry_time"></a>
<strong>retry_time</strong>
</dt>
<dd>
The retry time.
</dd>
<dt>
<a name = "scheduled"></a>
<strong>scheduled</strong>
</dt>
<dd>
If the system is currently scheduled for execution.
</dd>
<dt>
<a name = "spawnpoint_providers"></a>
<strong>spawnpoint_providers</strong>
</dt>
<dd>
The registered spawnpoint providers.
</dd>
</dl>

View File

@ -30,3 +30,6 @@ local base_path = minetest.get_modpath(minetest.get_current_modname())
dofile(base_path .. "/spawnusher.lua")
spawnusher.activate()

View File

@ -36,7 +36,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--
-- The only function that should be called from clients is activate.
spawnusher = {
--- The list of callbacks that are invoked after the player has been placed.
after_spawn_callbacks = List:new(),
--- The physics override that is set to make the player inmovable.
physics_override = {
speed = 0,
jump = 0,
@ -44,38 +47,45 @@ spawnusher = {
sneak = false,
sneak_glitch = false
},
--- The original physics of the payers.
player_physics = {},
--- The list of players that need to be placed.
players = List:new(),
--- The random object that is used to get random values.
random = nil,
random_placement_radius = 40,
required_bubble_size = 2,
retry_time = 0.5,
--- The placement radius around the spawn.
random_placement_radius = settings.get_number("spawnusher_placement_radius", 40),
--- The required air bubble size.
required_bubble_size = settings.get_number("spawnusher_bubble_size", 2),
--- The retry time.
retry_time = settings.get_number("spawnusher_retry_time", 0.5),
--- If the system is currently scheduled for execution.
scheduled = false,
--- The registered spawnpoint providers.
spawnpoint_providers = List:new()
}
--- Activates the spawn usher system.
--
-- @param random_placement_radius Optional. The player will be respawned in
-- the given radius around the spawn point.
-- @param required_bubble_size Optional. The size/height of the bubble of
-- air that is required for the player to spawn.
-- Defaults to 2.
-- @param retry_time Optional. This is the time that passes between tries to
-- place to the player.
function spawnusher.activate(random_placement_radius, required_bubble_size, retry_time)
spawnusher.random_placement_radius = random_placement_radius or 40
spawnusher.required_bubble_size = required_bubble_size or 2
spawnusher.retry_time = retry_time or 0.5
-- Initialize the PcgRandom with the current time. Given that placement
-- of the player is not critical or needs to be reproducable in any way,
-- it really does not matter here.
spawnusher.random = PcgRandom(os.time())
minetest.register_on_newplayer(spawnusher.on_spawn_player)
minetest.register_on_respawnplayer(spawnusher.on_spawn_player)
--- Activates the spawn usher system, if it has not been deactivated by
-- a seeting in the configuration.
function spawnusher.activate()
if settings.get_bool("spawnusher_activate", true) then
-- Initialize the PcgRandom with the current time. Given that placement
-- of the player is not critical or needs to be reproducable in any way,
-- it really does not matter here.
spawnusher.random = PcgRandom(os.time())
minetest.register_on_newplayer(spawnusher.on_spawn_player)
minetest.register_on_respawnplayer(spawnusher.on_spawn_player)
end
end
--- Tests if the given position is an air bubble big enough.