From 66eafdfa8cb3d90ee598d740d1b7a9eb3b6d67fb Mon Sep 17 00:00:00 2001 From: Robert Zenz Date: Sat, 12 Sep 2015 16:08:39 +0200 Subject: [PATCH] Spawn Usher can now be configured from the configuration. --- README | 42 +++--- doc/index.html | 238 +++++++++++++++++++++++++++++--- mods/spawn_usher/init.lua | 3 + mods/spawn_usher/spawnusher.lua | 58 ++++---- 4 files changed, 276 insertions(+), 65 deletions(-) diff --git a/README b/README index f1b7600..c9b459b 100644 --- a/README +++ b/README @@ -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 diff --git a/doc/index.html b/doc/index.html index 49b1472..19f19d1 100644 --- a/doc/index.html +++ b/doc/index.html @@ -30,6 +30,8 @@

Contents

@@ -57,8 +59,9 @@

Functions

- - + + @@ -94,6 +97,52 @@ the player has been determined.
activate (random_placement_radius, required_bubble_size, retry_time)Activates the spawn usher system.activate ()Activates the spawn usher system, if it has not been deactivated by + a seeting in the configuration.
is_air_bubble (start_pos)
+

Tables

+ + + + + + + + + +
physics_overrideThe physics override that is set to make the player inmovable.
player_physicsThe original physics of the payers.
+

Fields

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
after_spawn_callbacksThe list of callbacks that are invoked after the player has been placed.
playersThe list of players that need to be placed.
randomThe random object that is used to get random values.
random_placement_radiusThe placement radius around the spawn.
required_bubble_sizeThe required air bubble size.
retry_timeThe retry time.
scheduledIf the system is currently scheduled for execution.
spawnpoint_providersThe registered spawnpoint providers.


@@ -103,28 +152,13 @@
- activate (random_placement_radius, required_bubble_size, retry_time) + activate ()
- Activates the spawn usher system. + Activates the spawn usher system, if it has not been deactivated by + a seeting in the configuration. -

Parameters:

-
    -
  • random_placement_radius - Optional. The player will be respawned in - the given radius around the spawn point. -
  • -
  • required_bubble_size - Optional. The size/height of the bubble of - air that is required for the player to spawn. - Defaults to 2. -
  • -
  • retry_time - Optional. This is the time that passes between tries to - place to the player. -
  • -
@@ -309,6 +343,170 @@ +
+
+

Tables

+
+
+ + physics_override +
+
+ The physics override that is set to make the player inmovable. + + +

Fields:

+
    +
  • speed + +
  • +
  • jump + +
  • +
  • gravity + +
  • +
  • sneak + +
  • +
  • sneak_glitch + +
  • +
+ + + + + +
+
+ + player_physics +
+
+ The original physics of the payers. + + + + + + + +
+
+

Fields

+
+
+ + after_spawn_callbacks +
+
+ The list of callbacks that are invoked after the player has been placed. + + + + + + + +
+
+ + players +
+
+ The list of players that need to be placed. + + + + + + + +
+
+ + random +
+
+ The random object that is used to get random values. + + + + + + + +
+
+ + random_placement_radius +
+
+ The placement radius around the spawn. + + + + + + + +
+
+ + required_bubble_size +
+
+ The required air bubble size. + + + + + + + +
+
+ + retry_time +
+
+ The retry time. + + + + + + + +
+
+ + scheduled +
+
+ If the system is currently scheduled for execution. + + + + + + + +
+
+ + spawnpoint_providers +
+
+ The registered spawnpoint providers. + + + + + + +
diff --git a/mods/spawn_usher/init.lua b/mods/spawn_usher/init.lua index 50351f5..7c1d3a0 100644 --- a/mods/spawn_usher/init.lua +++ b/mods/spawn_usher/init.lua @@ -30,3 +30,6 @@ local base_path = minetest.get_modpath(minetest.get_current_modname()) dofile(base_path .. "/spawnusher.lua") + +spawnusher.activate() + diff --git a/mods/spawn_usher/spawnusher.lua b/mods/spawn_usher/spawnusher.lua index 2ef6d90..020b068 100644 --- a/mods/spawn_usher/spawnusher.lua +++ b/mods/spawn_usher/spawnusher.lua @@ -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.