Compare commits

...

6 Commits

Author SHA1 Message Date
81c3bd5bd9 Remove debug info. 2019-02-02 22:15:26 -08:00
70fedaa536 Update docs. 2019-02-02 21:19:08 -08:00
0a6451608d Set the node to non-diggable, to prevent accidental digging by admin. 2019-02-02 21:13:19 -08:00
c8e4942e41 Convert warps to mod_storage. 2019-02-02 21:11:53 -08:00
b7fd67c431 Support send_mapblock when we can. 2019-02-02 20:47:23 -08:00
37315e72c9 Remove hard dependency on default. 2019-02-02 20:44:37 -08:00
3 changed files with 47 additions and 50 deletions

11
README
View File

@ -11,7 +11,9 @@
priv: warp_admin - set/change/delete warps
priv: warp_user - list, and use warps
warps are stored in the world folder file "warps.txt".
warps are stored in mod_storage. If you had an older version that
uses the `warps.txt` file, it will be converted on load, after
which the file can be removed.
A warpstone can be given or found in the creative inventory (item
id: warps:warpstone). This warpstone can be placed on the ground
@ -22,9 +24,10 @@ warpstone can be removed by shift-punching the warp stone.
All warps are delayed by ~5 seconds. You have to stand still for
that duration, otherwise the warp will be cancelled. This may avoid
warp spamming and warping out of combat a bit. There's a bit
of variation in time due to the timer resolution in minetest
being rather large.
warp spamming and warping out of combat a bit. The mod tries
really hard to make sure that the player finds themselves in a
loaded area.
========

View File

@ -1 +0,0 @@
default

View File

@ -18,6 +18,41 @@ local warps_freeze = 5
-- p = player obj
-- w = warp name
local S = minetest.get_mod_storage()
assert(S, "mod_storage is required")
-- import warps or load
local store = S:get("warps")
local worldpath = minetest.get_worldpath()
if store then
warps = minetest.deserialize(store)
else
local fh,err = io.open(worldpath .. "/warps.txt", "r")
if err then
minetest.log("action", "[warps] loaded ")
return
end
while true do
local line = fh:read()
if line == nil then
break
end
local paramlist = string.split(line, " ")
local w = {
name = paramlist[1],
x = tonumber(paramlist[2]),
y = tonumber(paramlist[3]),
z = tonumber(paramlist[4]),
yaw = tonumber(paramlist[5]),
pitch = tonumber(paramlist[6])
}
table.insert(warps, w)
end
fh:close()
minetest.log("action", "[warps] converted warps to mod_storage. Please delete 'warps.txt'.")
S:set_string("warps", minetest.serialize(warps))
end
local function lookup_warp(name)
for i = 1,table.getn(warps) do
if warps[i].name == name then
@ -103,48 +138,10 @@ local warp_queue_add = function(player, dest)
if not minetest.get_node_or_nil(pos) then
minetest.emerge_area(vector.subtract(pos, 80), vector.add(pos, 80))
end
end
local worldpath = minetest.get_worldpath()
local save = function ()
local fh,err = io.open(worldpath .. "/warps.txt", "w")
if err then
print("No existing warps to read.")
return
-- force mapblock send to player, if supported
if player.send_mapblock then
player:send_mapblock(vector.divide(dest, 16))
end
for i = 1,table.getn(warps) do
local s = warps[i].name .. " " .. warps[i].x .. " " .. warps[i].y .. " " ..
warps[i].z .. " " .. warps[i].yaw .. " " .. warps[i].pitch .. "\n"
fh:write(s)
end
fh:close()
end
local load = function ()
local fh,err = io.open(worldpath .. "/warps.txt", "r")
if err then
minetest.log("action", "[warps] loaded ")
return
end
while true do
local line = fh:read()
if line == nil then
break
end
local paramlist = string.split(line, " ")
local w = {
name = paramlist[1],
x = tonumber(paramlist[2]),
y = tonumber(paramlist[3]),
z = tonumber(paramlist[4]),
yaw = tonumber(paramlist[5]),
pitch = tonumber(paramlist[6])
}
table.insert(warps, w)
end
fh:close()
minetest.log("action", "[warps] loaded " .. table.getn(warps) .. " warp location(s)")
end
minetest.register_privilege("warp_admin", {
@ -188,7 +185,7 @@ minetest.register_chatcommand("setwarp", {
yaw = round_digits(player:get_look_horizontal(), 3),
pitch = round_digits(player:get_look_vertical(), 3)
})
save()
S:set_string("warps", minetest.serialize(warps))
minetest.log("action", name .. " " .. h .. " warp \"" .. param .. "\": " ..
pos.x .. ", " .. pos.y .. ", " .. pos.z)
@ -250,6 +247,7 @@ minetest.register_node("warps:warpstone", {
paramtype = "light",
groups = { choppy=3 },
light_source = 8,
diggable = false,
selection_box = {
type = "fixed",
fixed = {-0.25, -0.5, -0.25, 0.25, 0.5, 0.25}
@ -294,6 +292,3 @@ minetest.register_node("warps:warpstone", {
end,
})
-- load existing warps
load()