Providers can now provided exact positions.
parent
fc42289902
commit
54c78fb2ef
20
README
20
README
|
@ -38,15 +38,19 @@ Providers
|
|||
|
||||
You can register providers which allow to customize the spawn point of
|
||||
the players. The provider is a callback that is able to provide a different
|
||||
spawn point. The signature is:
|
||||
spawn point. As second return value it can return a boolean determining if
|
||||
the system should look for an air bubble above or below the given location.
|
||||
The signature is:
|
||||
|
||||
function(
|
||||
player, -- The Player object of the player that is going to respawn.
|
||||
spawn_pos) -- The current spawn position of the player.
|
||||
|
||||
returns
|
||||
spawn_pos -- The position at which the player should ge respawned.
|
||||
spawn_pos, -- The position at which the player should ge respawned.
|
||||
-- nil to use the current one.
|
||||
exact_spot -- true if the given position is the exact position to be
|
||||
-- used. nil to keep the current value.
|
||||
|
||||
And a usage example:
|
||||
|
||||
|
@ -57,9 +61,19 @@ And a usage example:
|
|||
x = 0,
|
||||
y = 125,
|
||||
z = 50
|
||||
}
|
||||
},
|
||||
true
|
||||
end
|
||||
end)
|
||||
|
||||
-- We want to move all players further out.
|
||||
spawnusher.register_spawnpoint_provider(function(player, spawn_pos)
|
||||
return {
|
||||
x = spawn_pos.x + 150,
|
||||
y = spawn_pos.y,
|
||||
z = spawn_pos.z + 150
|
||||
}
|
||||
end)
|
||||
|
||||
|
||||
After Spawn Callbacks
|
||||
|
|
|
@ -288,7 +288,8 @@
|
|||
<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.
|
||||
or nil if it is happy with the given position, and if it is is the exact
|
||||
position or not.
|
||||
|
||||
|
||||
|
||||
|
@ -299,6 +300,8 @@
|
|||
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.
|
||||
The second return value can be true to make the system use
|
||||
the provided position without looking for an air bubble.
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
|
|
|
@ -250,19 +250,26 @@ function spawnusher.on_spawn_player(player)
|
|||
|
||||
player:setpos(spawn_pos)
|
||||
|
||||
local exact_pos = false
|
||||
|
||||
-- Run the position through the providers.
|
||||
spawnusher.spawnpoint_providers:foreach(function(provider, index)
|
||||
local provided_pos = provider(player, spawn_pos)
|
||||
local provided_pos, provided_exact_pos = provider(player, spawn_pos)
|
||||
|
||||
if provided_pos ~= nil then
|
||||
spawn_pos = provided_pos
|
||||
end
|
||||
if provided_exact_pos ~= nil then
|
||||
exact_pos = provided_exact_pos
|
||||
end
|
||||
end)
|
||||
|
||||
player:setpos(spawn_pos)
|
||||
|
||||
-- Now find a nice spawn place for the player.
|
||||
spawnusher.move_player(player)
|
||||
if not exact_pos then
|
||||
-- Now find a nice spawn place for the player.
|
||||
spawnusher.move_player(player)
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
@ -277,12 +284,15 @@ 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.
|
||||
-- or nil if it is happy with the given position, and if it is is the exact
|
||||
-- position or not.
|
||||
--
|
||||
-- @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.
|
||||
-- The second return value can be true to make the system use
|
||||
-- the provided position without looking for an air bubble.
|
||||
function spawnusher.register_spawnpoint_provider(provider)
|
||||
spawnusher.spawnpoint_providers:add(provider)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue