Add teleportation countdown
parent
faf9e2824f
commit
5844868589
|
@ -8,6 +8,8 @@ Static Spawnpoint [spawnpoint]
|
|||
|
||||
This is a rather simple mod introducing two commands to set a static spawnpoint and to teleport to it. Yes, I know you can set this in `minetest.conf`, however, doing so causes the spawnpoint to be the same across all of your worlds (very inconvenient). Instead of using `minetest.conf`, this mod stores the spawnpoint as a string in a file called `spawnpoint.conf` in the world directory. This allows each and every world to have a different spawnpoint.
|
||||
|
||||
The most unique thing about this spawn mod, is that it includes a feature allowing you to set the time between executing the command until the player is actually teleported. By default, the teleportation will be interupted if the player moves within that time. The time can be configured in `minetest.conf` with `spawnpoint.time` (if `0`, players will be immediately teleported), and you can disable the feature requiring players to stand still by setting `spawnpoint.do_not_move` to `false` (default: `true`).
|
||||
|
||||
### Commands
|
||||
- `/spawn <player>`: Teleports you or the player specified to the spawnpoint (requires `spawn` privilege, and `bring` privilege to teleport another player)
|
||||
- `/setspawn <position>`: Sets the spawn to the position specified (in format `x, y, z`) or to your current location (requires `server` privilege)
|
||||
|
|
82
init.lua
82
init.lua
|
@ -2,6 +2,9 @@
|
|||
|
||||
spawnpoint = {}
|
||||
|
||||
spawnpoint.time = tonumber(minetest.setting_get("spawnpoint.time")) or 3
|
||||
spawnpoint.do_not_move = not not minetest.setting_get("spawnpoint.do_not_move") or true
|
||||
|
||||
local path = minetest.get_worldpath().."/spawnpoint.conf"
|
||||
|
||||
-- [function] Log
|
||||
|
@ -60,6 +63,81 @@ function spawnpoint.bring(player)
|
|||
end
|
||||
end
|
||||
|
||||
-- [function] Begin Countdown
|
||||
function spawnpoint.begin(player, time)
|
||||
if not time then
|
||||
time = spawnpoint.time
|
||||
end
|
||||
|
||||
if type(player) == string then
|
||||
player = minetest.get_player_by_name(player)
|
||||
end
|
||||
|
||||
local name = player:get_player_name()
|
||||
|
||||
if player and time and time ~= 0 then
|
||||
local move = "Do not move!"
|
||||
if spawnpoint.do_not_move ~= true then
|
||||
move = ""
|
||||
end
|
||||
|
||||
local pos = player:get_pos()
|
||||
local has_moved = false
|
||||
local seconds = "s"
|
||||
|
||||
if time < 2 then
|
||||
seconds = ""
|
||||
end
|
||||
|
||||
-- Send to chat
|
||||
minetest.chat_send_player(name, "Teleportation will be complete in "..time..
|
||||
" second"..seconds..". "..move)
|
||||
|
||||
-- Add initial HUD
|
||||
local hud = player:hud_add({
|
||||
hud_elem_type = "text",
|
||||
text = "Teleportation Progress: "..time.." seconds remaining!",
|
||||
position = {x = 0.5, y = 0.5},
|
||||
number = 0xFFFFFF,
|
||||
})
|
||||
|
||||
-- Register update callbacks
|
||||
for i = 1, time do
|
||||
if i == time then
|
||||
minetest.after(i, function()
|
||||
if move ~= "" and has_moved ~= true and not vector.equals(pos, player:get_pos()) then
|
||||
player:hud_remove(hud)
|
||||
minetest.chat_send_player(name, "Teleportation interrupted! (Player moved)")
|
||||
has_moved = true
|
||||
return
|
||||
end
|
||||
|
||||
player:hud_remove(hud)
|
||||
spawnpoint.bring(player)
|
||||
|
||||
-- Send to chat
|
||||
minetest.chat_send_player(name, "Teleportation successful!")
|
||||
end)
|
||||
else
|
||||
minetest.after(i, function()
|
||||
if move ~= "" and has_moved ~= true and not vector.equals(pos, player:get_pos()) then
|
||||
player:hud_remove(hud)
|
||||
minetest.chat_send_player(name, "Teleportation interrupted! (Player moved)")
|
||||
has_moved = true
|
||||
spawnpoint.log(dump(pos)..", "..dump(player:getpos()))
|
||||
return
|
||||
end
|
||||
|
||||
player:hud_change(hud, "text", "Teleportation Progress: "..time - i.." seconds remaining!")
|
||||
end)
|
||||
end
|
||||
end
|
||||
elseif player then
|
||||
minetest.chat_send_player(name, "Teleporting to spawn")
|
||||
spawnpoint.bring(player)
|
||||
end
|
||||
end
|
||||
|
||||
-------------------
|
||||
---- CALLBACKS ----
|
||||
-------------------
|
||||
|
@ -116,8 +194,6 @@ minetest.register_chatcommand("spawn", {
|
|||
end
|
||||
end
|
||||
|
||||
spawnpoint.bring(player)
|
||||
|
||||
return true, "Teleporting to spawn"
|
||||
spawnpoint.begin(player)
|
||||
end,
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue