forked from minetest-mods/warps
Compare commits
6 Commits
5c24fff8b5
...
81c3bd5bd9
Author | SHA1 | Date | |
---|---|---|---|
81c3bd5bd9 | |||
70fedaa536 | |||
0a6451608d | |||
c8e4942e41 | |||
b7fd67c431 | |||
37315e72c9 |
11
README
11
README
@ -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.
|
||||
|
||||
|
||||
========
|
||||
|
||||
|
@ -1 +0,0 @@
|
||||
default
|
||||
|
85
init.lua
85
init.lua
@ -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()
|
||||
|
||||
|
Reference in New Issue
Block a user