Version 1.4
This commit is contained in:
parent
d61761f368
commit
d80728e112
@ -1,6 +1,6 @@
|
||||
--------------------------------------------------------------------------------
|
||||
--
|
||||
-- Minetest Mod "Travelpoints" Version 1.3 2015-03-24
|
||||
-- Minetest Mod "Travelpoints" Version 1.4 2015-03-27
|
||||
--
|
||||
-- By Racso Rhodes
|
||||
--
|
||||
|
@ -1,4 +1,4 @@
|
||||
Travelpoints 1.3 2015-03-24
|
||||
Travelpoints 1.4 2015-03-27
|
||||
|
||||
Save world specific bookmarks to locations you travel to as "travelpoints", then easily teleport to those travelpoints.
|
||||
|
||||
|
752
functions.lua
752
functions.lua
@ -1,6 +1,6 @@
|
||||
--------------------------------------------------------------------------------
|
||||
--
|
||||
-- Minetest Mod "Travelpoints" Version 1.3 2015-03-24
|
||||
-- Minetest Mod "Travelpoints" Version 1.4 2015-03-27
|
||||
--
|
||||
-- By Racso Rhodes
|
||||
--
|
||||
@ -19,6 +19,8 @@
|
||||
--
|
||||
-- Functions
|
||||
--
|
||||
-- travelpoints.after_place_node()
|
||||
-- travelpoints.can_dig()
|
||||
-- travelpoints.default_restrictions()
|
||||
-- travelpoints.get_duration()
|
||||
-- travelpoints.get_formspec()
|
||||
@ -30,12 +32,15 @@
|
||||
-- travelpoints.get_travelpoints_table()
|
||||
-- travelpoints.get_world_restrictions()
|
||||
-- travelpoints.is_empty()
|
||||
-- travelpoints.on_destruct()
|
||||
-- travelpoints.on_receive_fields()
|
||||
-- travelpoints.player_can_use_pad()
|
||||
-- travelpoints.player_exists()
|
||||
-- travelpoints.player_in_players()
|
||||
-- travelpoints.print_notice()
|
||||
-- travelpoints.save_travelpoints_table()
|
||||
-- travelpoints.save_world_restrictions()
|
||||
-- travelpoints.set_pad_destination()
|
||||
-- travelpoints.swap_node()
|
||||
-- travelpoints.validate_config()
|
||||
-- travelpoints.validate_desc()
|
||||
@ -45,10 +50,158 @@
|
||||
--
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
--[[
|
||||
|
||||
Meta Data 1.4d
|
||||
|
||||
string("location")
|
||||
string("owner")
|
||||
string("title")
|
||||
string("destination")
|
||||
string("source")
|
||||
string("version")
|
||||
int("timestamp")
|
||||
int("modstamp")
|
||||
|
||||
int("utp_index") \ tp_index
|
||||
int("gtp_index") /
|
||||
|
||||
int("mode_index")
|
||||
string("players")
|
||||
|
||||
string("user_travelpoints_array") \ tp_array
|
||||
string("global_travelpoints_array") /
|
||||
|
||||
string("formspec")
|
||||
string("infotext")
|
||||
|
||||
|
||||
|
||||
]]--
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- Functions
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
--[After Place Node]------------------------------------------------------------
|
||||
--
|
||||
-- Node callback function.
|
||||
-- Builds the default meta values for the placed node.
|
||||
--
|
||||
function travelpoints.after_place_node(pos, placer)
|
||||
|
||||
-- Get node metadata.
|
||||
local meta = minetest.get_meta(pos)
|
||||
|
||||
-- Get placer's name.
|
||||
local name = placer:get_player_name()
|
||||
|
||||
-- Get player's travelpad count for this world.
|
||||
local travelpad_count = travelpoints.travelpad_log(name, meta, "count")
|
||||
|
||||
-- Verify privs.
|
||||
if not minetest.get_player_privs(name)["travelpads"] then
|
||||
|
||||
-- Report
|
||||
travelpoints.print_notice(name, "You do not have the privilege to place transporter pads.")
|
||||
|
||||
-- Remove travelpad.
|
||||
minetest.remove_node(pos)
|
||||
|
||||
-- Drop travelpad for pickup.
|
||||
minetest.add_item(pos, 'travelpoints:transporter_pad')
|
||||
|
||||
-- Verify status.
|
||||
elseif minetest.get_node(pos).name == "travelpoints:transporter_pad_active" then
|
||||
|
||||
-- Report
|
||||
travelpoints.print_notice(name, "You can not place an active transporter pad.")
|
||||
|
||||
-- Remove active travelpad.
|
||||
minetest.remove_node(pos)
|
||||
|
||||
-- Drop travelpad for pickup.
|
||||
minetest.add_item(pos, 'travelpoints:transporter_pad')
|
||||
|
||||
-- Handle maximum_travelpads if it is configured.
|
||||
elseif ( not minetest.is_singleplayer() ) and ( travelpoints.restrictions.max_travelpads > 0 ) and ( travelpad_count >= travelpoints.restrictions.max_travelpads ) and ( not minetest.get_player_privs(name)["server"]) then
|
||||
|
||||
-- Report
|
||||
travelpoints.print_notice(name, "You have already reached your maximum number of transporter pads: " .. travelpoints.restrictions.max_travelpads .. ".")
|
||||
|
||||
-- Remove travelpad.
|
||||
minetest.remove_node(pos)
|
||||
|
||||
-- Drop travelpad for pickup.
|
||||
minetest.add_item(pos, 'travelpoints:transporter_pad')
|
||||
|
||||
else
|
||||
|
||||
-- Set default values.
|
||||
meta:set_string("location", minetest.pos_to_string(pos))
|
||||
meta:set_string("owner", name)
|
||||
meta:set_string("title", "")
|
||||
meta:set_string("destination", "")
|
||||
meta:set_string("source", "") --(Mine/Global)
|
||||
meta:set_string("version", travelpoints.version_number)
|
||||
meta:set_int("timestamp", os.time())
|
||||
meta:set_int("modstamp", 0)
|
||||
meta:set_int("tp_index", 1)
|
||||
meta:set_string("tp_array", "return { }")
|
||||
meta:set_int("mode_index", 1)
|
||||
meta:set_string("players", "return { }")
|
||||
|
||||
-- Add travelpad to log.
|
||||
travelpoints.travelpad_log(name, meta, "add")
|
||||
|
||||
-- Save default formspec
|
||||
meta:set_string("formspec", travelpoints.get_formspec("", meta))
|
||||
|
||||
-- Save default infotext.
|
||||
meta:set_string("infotext", travelpoints.get_infotext(meta))
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[Can Dig]---------------------------------------------------------------------
|
||||
--
|
||||
-- Node callback function.
|
||||
-- Determines if the node can be dug.
|
||||
--
|
||||
travelpoints.can_dig = function(pos, player)
|
||||
|
||||
-- Get node's metadata.
|
||||
local meta = minetest.get_meta(pos)
|
||||
|
||||
-- Get player's name.
|
||||
local name = player:get_player_name()
|
||||
|
||||
-- Dug by admin?
|
||||
if minetest.get_player_privs(name)["server"] then
|
||||
|
||||
return true
|
||||
|
||||
-- Dug by owner?
|
||||
elseif meta:get_string("owner") == name then
|
||||
|
||||
-- Check if travelpad is "offline".
|
||||
if meta:get_string("destination") == "" then
|
||||
return true
|
||||
else
|
||||
travelpoints.print_notice(name, "A transporter pad can not be dug unless its destination is unset.")
|
||||
return false
|
||||
end
|
||||
|
||||
-- Dug by Anyone else.
|
||||
else
|
||||
travelpoints.print_notice(name, "You can not dig a transporter pad you do not own.")
|
||||
return false
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[Default Restrictions]--------------------------------------------------------
|
||||
--
|
||||
-- Returns table of default restriction values for overriding bad values in
|
||||
@ -186,35 +339,54 @@ end
|
||||
--
|
||||
-- Build formspec for travelpoints:transporter_pad/_active.
|
||||
--
|
||||
function travelpoints.get_formspec(meta)
|
||||
function travelpoints.get_formspec(mode, meta) -- mode(|user|global)
|
||||
|
||||
-- Pull metadata.
|
||||
local title = meta:get_string("title")
|
||||
local destination = meta:get_string("destination")
|
||||
local source = meta:get_string("source")
|
||||
local timestamp = meta:get_int("timestamp")
|
||||
local modstamp = meta:get_int("modstamp")
|
||||
local travelpoints_array = minetest.deserialize(meta:get_string("travelpoints_array"))
|
||||
local version = meta:get_string("version")
|
||||
local tp_array = minetest.deserialize(meta:get_string("tp_array"))
|
||||
local tp_index = meta:get_int("tp_index")
|
||||
local tp_count = ""
|
||||
local tp_count = 0
|
||||
local mode_index = meta:get_int("mode_index")
|
||||
local players = minetest.deserialize(meta:get_string("players"))
|
||||
|
||||
-- Get travelpoint count.
|
||||
if #travelpoints_array > 1 then
|
||||
tp_count = #travelpoints_array - 1
|
||||
if #tp_array > 0 then
|
||||
tp_count = #tp_array
|
||||
end
|
||||
|
||||
-- Convert travelpoints_array to string.
|
||||
local tp_string = table.concat(travelpoints_array, ",")
|
||||
|
||||
-- Convert travelpoints array to string.
|
||||
local tp_string = table.concat(tp_array, ",")
|
||||
|
||||
-- Set status
|
||||
local status
|
||||
if (title ~= "") and (destination ~= "") then
|
||||
status = "Destination: " .. title .. " " .. destination
|
||||
status = "Destination: " .. title .. " " .. destination .. " (" .. source .. ")"
|
||||
else
|
||||
status = "Offline"
|
||||
end
|
||||
|
||||
-- Set list label
|
||||
local list_label
|
||||
if mode == "user" then
|
||||
list_label = "My Travelpoints: " .. tp_count
|
||||
elseif mode == "global" then
|
||||
list_label = "Global Travelpoints: " .. tp_count
|
||||
else
|
||||
list_label = "Travelpoints:"
|
||||
end
|
||||
|
||||
-- Set tp string
|
||||
if mode == "user" then
|
||||
tp_string = "user_list;" .. tp_string .. ";" .. tp_index
|
||||
else
|
||||
tp_string = "global_list;" .. tp_string .. ";" .. tp_index
|
||||
end
|
||||
|
||||
-- Set last_modified
|
||||
local last_modified
|
||||
if modstamp > 0 then
|
||||
@ -228,13 +400,15 @@ function travelpoints.get_formspec(meta)
|
||||
formspec = formspec .. "size[10,6.8]"
|
||||
formspec = formspec .. "label[0.1,0.0;" .. status .. "]"
|
||||
formspec = formspec .. "box[-0.28,0.6;10.37,0.05;#FFFFFF]"
|
||||
formspec = formspec .. "label[0.1,0.7;Available Travelpoints: " .. tp_count .."]"
|
||||
formspec = formspec .. "textlist[0.1,1.2;5.7,3.6;travelpoint;" .. tp_string .. ";" .. tp_index .. "]"
|
||||
formspec = formspec .. "button[0.1,4.83;2.9,1;list_travelpoints;List Travelpoints]"
|
||||
formspec = formspec .. "button_exit[3.15,4.83;2.9,1;unset_destination;Unset Destination]"
|
||||
formspec = formspec .. "label[2.5,5.95;Placed on " .. os.date("%Y-%m-%d", timestamp) .. "]"
|
||||
formspec = formspec .. "button_exit[0.1,5.65;2,1;save;Save]"
|
||||
formspec = formspec .. "label[0.1,6.5;Last Modified: " .. last_modified .. "]"
|
||||
formspec = formspec .. "label[0.1,0.7;" .. list_label .."]"
|
||||
formspec = formspec .. "textlist[0.1,1.2;5.7,3.6;" .. tp_string .. "]"
|
||||
formspec = formspec .. "button[0.1,4.83;2.9,1;my_travelpoints;My Travelpoints]"
|
||||
formspec = formspec .. "button[3.15,4.83;2.9,1;global_travelpoints;Global Travelpoints]"
|
||||
formspec = formspec .. "button[0.1,5.65;2.9,1;unset_destination;Unset Destination]"
|
||||
formspec = formspec .. "button_exit[3.15,5.65;2.9,1;exit;Exit]"
|
||||
formspec = formspec .. "label[0.1,6.6;Placed: " .. os.date("%Y-%m-%d", timestamp) .. "]"
|
||||
formspec = formspec .. "label[3.15,6.6;Modified: " .. last_modified .. "]"
|
||||
formspec = formspec .. "label[9.2,6.6;v" .. version .. "]"
|
||||
|
||||
-- Multiplayer fields.
|
||||
if not minetest.is_singleplayer() then
|
||||
@ -284,7 +458,7 @@ function travelpoints.get_infotext(meta)
|
||||
if minetest.is_singleplayer() then
|
||||
return status
|
||||
else
|
||||
return status .. " (Placed by " .. owner .. ")"
|
||||
return status .. " (" .. owner .. ")"
|
||||
end
|
||||
end
|
||||
|
||||
@ -341,17 +515,17 @@ end
|
||||
-- Written initially for travelpoints:transpoerter_pad/_active formspec then
|
||||
-- became useful for getting a travelpoint count.
|
||||
--
|
||||
function travelpoints.get_travelpoints_array(name)
|
||||
function travelpoints.get_travelpoints_array(mode, name) -- mode(user/global)
|
||||
|
||||
-- Get travelpoints_table.
|
||||
local travelpoints_table = travelpoints.get_travelpoints_table(name)
|
||||
|
||||
-- Check if travelpoints_table is empty.
|
||||
-- Get table.
|
||||
local travelpoints_table = travelpoints.get_travelpoints_table(mode, name)
|
||||
|
||||
-- Check if travelpoints table is empty.
|
||||
if not travelpoints.is_empty(travelpoints_table) then
|
||||
|
||||
local travelpoints_array = {}
|
||||
|
||||
-- Step through travelpoints_table to pack travelpoints_array.
|
||||
-- Step through travelpoints table to pack travelpoints array.
|
||||
for key, value in pairs(travelpoints_table) do
|
||||
|
||||
-- Omit keys that begin with an underscore.
|
||||
@ -367,14 +541,11 @@ function travelpoints.get_travelpoints_array(name)
|
||||
-- Sort values.
|
||||
table.sort(travelpoints_array, function(A, B) return A < B end)
|
||||
|
||||
-- Add "none" at index 1.
|
||||
table.insert(travelpoints_array, 1, "none")
|
||||
|
||||
return travelpoints_array
|
||||
|
||||
else
|
||||
|
||||
return { "none" }
|
||||
return { }
|
||||
|
||||
end
|
||||
|
||||
@ -384,21 +555,33 @@ end
|
||||
--
|
||||
-- Get player's travelpoints table for the current world.
|
||||
--
|
||||
function travelpoints.get_travelpoints_table(name)
|
||||
function travelpoints.get_travelpoints_table(mode, name) -- mode(user/global), name
|
||||
|
||||
-- Set travelpoints_table file path.
|
||||
local travelpoints_table_file = travelpoints.travelpoints_tables .. travelpoints.delimiter .. name .. ".tpt"
|
||||
|
||||
-- Open player's travelpoints_table file for reading.
|
||||
local travelpoints_table_file
|
||||
|
||||
-- Set travelpoints table file path.
|
||||
if mode == "user" then
|
||||
|
||||
-- User's table.
|
||||
travelpoints_table_file = travelpoints.travelpoints_tables .. travelpoints.delimiter .. name .. ".tpt"
|
||||
|
||||
else
|
||||
|
||||
-- Global table.
|
||||
travelpoints_table_file = travelpoints.worldpath .. travelpoints.delimiter .. "travelpoints_global.tpt"
|
||||
|
||||
end
|
||||
|
||||
-- Open travelpoints table file for reading.
|
||||
local read_handle, read_error = io.open(travelpoints_table_file, "r")
|
||||
|
||||
-- Check if travelpoints_table file failed to open. (Might not exist yet.)
|
||||
-- Check if travelpoints table file failed to open. (Might not exist yet.)
|
||||
if read_error ~= nil then
|
||||
|
||||
-- Create travelpoints_table file.
|
||||
-- Create travelpoints table file.
|
||||
local write_handle, write_error = io.open(travelpoints_table_file, "w")
|
||||
|
||||
-- Check if travelpoints_table file could not be created.
|
||||
-- Check if travelpoints table file could not be created.
|
||||
if write_error ~= nil then
|
||||
|
||||
-- Report error to player.
|
||||
@ -530,6 +713,393 @@ function travelpoints.is_empty(table_name)
|
||||
|
||||
end
|
||||
|
||||
--[On Destruct]-----------------------------------------------------------------
|
||||
--
|
||||
-- Node callback function.
|
||||
-- Removes entry from travelpad log when pad is destroyed.
|
||||
--
|
||||
function travelpoints.on_destruct(pos)
|
||||
|
||||
-- Get nodes metadata.
|
||||
local meta = minetest.get_meta(pos)
|
||||
|
||||
if meta:get_string("owner") ~= "" then
|
||||
|
||||
-- Remove travelpad from log.
|
||||
travelpoints.travelpad_log(meta:get_string("owner"), meta, "remove")
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[On Receive Fields]-----------------------------------------------------------
|
||||
--
|
||||
-- Node callback function.
|
||||
-- Handles data from form.
|
||||
--
|
||||
function travelpoints.on_receive_fields(pos, formname, fields, sender)
|
||||
|
||||
local meta = minetest.get_meta(pos)
|
||||
|
||||
local name = sender:get_player_name()
|
||||
|
||||
local owner = meta:get_string("owner")
|
||||
|
||||
-- Only pad owner can make changes.
|
||||
if name == owner then
|
||||
|
||||
--------------------------------------------------------------------
|
||||
-- Button "My Travelpoints"
|
||||
--------------------------------------------------------------------
|
||||
--
|
||||
-- This lists the user's travelpoints.
|
||||
--
|
||||
if fields.my_travelpoints == "My Travelpoints" then
|
||||
|
||||
-- Get the user's travelpoints as an array.
|
||||
local tp_array = travelpoints.get_travelpoints_array("user", owner)
|
||||
|
||||
-- Serialize the travelpoints array.
|
||||
local tp_array = minetest.serialize(tp_array)
|
||||
|
||||
-- Set the travelpoints array.
|
||||
meta:set_string("tp_array", tp_array)
|
||||
|
||||
-- Set pad to "Offline".
|
||||
--
|
||||
-- Assumed that player chose to refresh in order to point the pad to
|
||||
-- new coords.
|
||||
--
|
||||
meta:set_string("title", "")
|
||||
meta:set_string("destination", "")
|
||||
meta:set_int("tp_index", 0)
|
||||
|
||||
-- Save formspec.
|
||||
meta:set_string("formspec", travelpoints.get_formspec("user", meta))
|
||||
|
||||
-- Save infotext.
|
||||
meta:set_string("infotext", travelpoints.get_infotext(meta))
|
||||
|
||||
--------------------------------------------------------------------
|
||||
-- Button "Global Travelpoints"
|
||||
--------------------------------------------------------------------
|
||||
--
|
||||
-- This syncs the node's global travelpoints array with the current
|
||||
-- global travelpoints table.
|
||||
--
|
||||
elseif fields.global_travelpoints == "Global Travelpoints" then
|
||||
|
||||
-- Get the user's travelpoints as an array.
|
||||
local tp_array = travelpoints.get_travelpoints_array("global", owner)
|
||||
|
||||
-- Serialize the travelpoints array.
|
||||
local tp_array = minetest.serialize(tp_array)
|
||||
|
||||
-- Set the travelpoints array.
|
||||
meta:set_string("tp_array", tp_array)
|
||||
|
||||
-- Set pad to "Offline".
|
||||
--
|
||||
-- Assumed that player chose to refresh in order to point the pad to
|
||||
-- new coords.
|
||||
--
|
||||
meta:set_string("title", "")
|
||||
meta:set_string("destination", "")
|
||||
meta:set_int("tp_index", 0)
|
||||
|
||||
-- Save formspec.
|
||||
meta:set_string("formspec", travelpoints.get_formspec("global", meta))
|
||||
|
||||
-- Save infotext.
|
||||
meta:set_string("infotext", travelpoints.get_infotext(meta))
|
||||
|
||||
--------------------------------------------------------------------
|
||||
-- Text list - select user travelpoint.
|
||||
--------------------------------------------------------------------
|
||||
|
||||
elseif ( fields.user_list ) and ( name == owner) then
|
||||
|
||||
-- Get index value.
|
||||
local index = travelpoints.get_textlist_index(fields.user_list)
|
||||
|
||||
if index ~= meta:get_int("tp_index") then
|
||||
|
||||
-- Get this node's travelpoints array.
|
||||
local tp_array = minetest.deserialize(meta:get_string("tp_array"))
|
||||
|
||||
-- Extract title and destination from array value.
|
||||
local title, destination = string.match(tp_array[index], "^([^ ]+)%s+(.+)")
|
||||
|
||||
-- Remove escapes.
|
||||
destination = string.gsub(destination, "\\", "", 2)
|
||||
|
||||
-- Pads can't teleport to themselves.
|
||||
if destination ~= minetest.pos_to_string(pos) then
|
||||
|
||||
-- Set or clear title and destination meta data.
|
||||
if ( index == 0 ) or ( index > #tp_array ) then
|
||||
meta:set_string("title", "")
|
||||
meta:set_string("destination", "")
|
||||
meta:set_string("source", "")
|
||||
meta:set_int("tp_index", 0)
|
||||
else
|
||||
meta:set_string("title", title)
|
||||
meta:set_string("destination", destination)
|
||||
meta:set_string("source", "Mine")
|
||||
meta:set_int("tp_index", index)
|
||||
end
|
||||
|
||||
meta:set_string("tp_array", "return { }")
|
||||
|
||||
-- Save modification timestamp.
|
||||
meta:set_int("modstamp", os.time())
|
||||
|
||||
-- Save formspec.
|
||||
meta:set_string("formspec", travelpoints.get_formspec("", meta))
|
||||
|
||||
-- Save infotext.
|
||||
meta:set_string("infotext", travelpoints.get_infotext(meta))
|
||||
|
||||
else
|
||||
|
||||
-- Report
|
||||
travelpoints.print_notice(name, "Error: You can not set the transporter pad's location as its destination.")
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------
|
||||
-- Text list - select global travelpoint.
|
||||
--------------------------------------------------------------------
|
||||
|
||||
elseif fields.global_list then
|
||||
|
||||
-- Get index value.
|
||||
local index = travelpoints.get_textlist_index(fields.global_list)
|
||||
|
||||
if index ~= meta:get_int("tp_index") then
|
||||
|
||||
-- Get this node's travelpoints array.
|
||||
local tp_array = minetest.deserialize(meta:get_string("tp_array"))
|
||||
|
||||
-- Extract title and destination from array value.
|
||||
local title, destination = string.match(tp_array[index], "^([^ ]+)%s+(.+)")
|
||||
|
||||
-- Remove escapes.
|
||||
destination = string.gsub(destination, "\\", "", 2)
|
||||
|
||||
-- Pads can't teleport to themselves.
|
||||
if destination ~= minetest.pos_to_string(pos) then
|
||||
|
||||
-- Set or clear title and destination meta data.
|
||||
if ( index == 0 ) or ( index > #tp_array ) then
|
||||
meta:set_string("title", "")
|
||||
meta:set_string("destination", "")
|
||||
meta:set_string("source", "")
|
||||
meta:set_int("tp_index", 0)
|
||||
else
|
||||
meta:set_string("title", title)
|
||||
meta:set_string("destination", destination)
|
||||
meta:set_string("source", "Global")
|
||||
meta:set_int("tp_index", index)
|
||||
end
|
||||
|
||||
meta:set_string("tp_array", "return { }")
|
||||
|
||||
-- Save modification timestamp.
|
||||
meta:set_int("modstamp", os.time())
|
||||
|
||||
-- Save formspec.
|
||||
meta:set_string("formspec", travelpoints.get_formspec("", meta))
|
||||
|
||||
-- Save infotext.
|
||||
meta:set_string("infotext", travelpoints.get_infotext(meta))
|
||||
|
||||
else
|
||||
|
||||
-- Report
|
||||
travelpoints.print_notice(name, "Error: You can not set the transporter pad's location as its destination.")
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------
|
||||
-- Button "Add Player"
|
||||
--------------------------------------------------------------------
|
||||
|
||||
elseif ( fields.add_player == "Add Player" ) and ( string.len(fields.player_name) > 0 ) then
|
||||
|
||||
local player = fields.player_name
|
||||
|
||||
-- Validate input.
|
||||
if not string.find(player, "^[^%w_]+$") then
|
||||
|
||||
-- Owner can't add their name.
|
||||
if player ~= name then
|
||||
|
||||
-- Check if player exists.
|
||||
if travelpoints.player_exists(player) then
|
||||
|
||||
-- Check if player is already in array.
|
||||
if not travelpoints.player_in_players(player, meta:get_string("players")) then
|
||||
|
||||
-- Get players array.
|
||||
local players = minetest.deserialize(meta:get_string("players"))
|
||||
|
||||
-- Add player.
|
||||
table.insert(players, player)
|
||||
|
||||
-- Sort values.
|
||||
if #players > 1 then
|
||||
table.sort(players, function(A, B) return A < B end)
|
||||
end
|
||||
|
||||
-- Save players array.
|
||||
meta:set_string("players", minetest.serialize(players))
|
||||
|
||||
-- Save modification timestamp.
|
||||
meta:set_int("modstamp", os.time())
|
||||
|
||||
-- Save formspec.
|
||||
meta:set_string("formspec", travelpoints.get_formspec("", meta))
|
||||
|
||||
else
|
||||
|
||||
-- Report
|
||||
travelpoints.print_notice(name, "Error: \"" .. player .. "\" is already listed.")
|
||||
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
-- Report
|
||||
travelpoints.print_notice(name, "Error: \"" .. player .. "\" is not an existing player for this world.")
|
||||
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
-- Report
|
||||
travelpoints.print_notice(name, "Error: You can't add your own name.")
|
||||
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
-- Report
|
||||
travelpoints.print_notice(name, "Error: The name you entered contains disallowed characters.")
|
||||
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------
|
||||
-- Button "Remove Player"
|
||||
--------------------------------------------------------------------
|
||||
|
||||
elseif fields.remove_player == "Remove Player" then
|
||||
|
||||
local player = fields.players
|
||||
|
||||
-- Get players array.
|
||||
local players = minetest.deserialize(meta:get_string("players"))
|
||||
|
||||
local player_removed = false
|
||||
|
||||
-- Step through players to find player.
|
||||
for index, value in ipairs(players) do
|
||||
|
||||
-- Remove player when found.
|
||||
if value == player then
|
||||
table.remove(players, index)
|
||||
player_removed = true
|
||||
break
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-- Check if a player was removed.
|
||||
if player_removed then
|
||||
|
||||
-- Sort values.
|
||||
if #players > 1 then
|
||||
table.sort(players, function(A, B) return A < B end)
|
||||
end
|
||||
|
||||
-- Save players array.
|
||||
meta:set_string("players", minetest.serialize(players))
|
||||
|
||||
-- Save modification timestamp.
|
||||
meta:set_int("modstamp", os.time())
|
||||
|
||||
-- Save formspec.
|
||||
meta:set_string("formspec", travelpoints.get_formspec("", meta))
|
||||
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------
|
||||
-- Button "Unset Destination"
|
||||
--------------------------------------------------------------------
|
||||
elseif fields.unset_destination == "Unset Destination" then
|
||||
|
||||
-- Clear destination.
|
||||
meta:set_string("title", "")
|
||||
meta:set_string("destination", "")
|
||||
meta:set_string("source", "")
|
||||
meta:set_int("tp_index", 0)
|
||||
meta:set_string("tp_array", "return { }")
|
||||
|
||||
-- Save modification timestamp.
|
||||
meta:set_int("modstamp", os.time())
|
||||
|
||||
-- Save formspec.
|
||||
meta:set_string("formspec", travelpoints.get_formspec("", meta))
|
||||
|
||||
-- Save infotext.
|
||||
meta:set_string("infotext", travelpoints.get_infotext(meta))
|
||||
|
||||
--------------------------------------------------------------------
|
||||
-- Drop down list "Pad Usage Mode"
|
||||
--------------------------------------------------------------------
|
||||
elseif fields.mode then
|
||||
|
||||
-- Pad Access Mode
|
||||
if ( name == owner ) then
|
||||
if fields.mode then
|
||||
local mode_table = travelpoints.get_pad_modes("table")
|
||||
meta:set_int("mode_index", mode_table[fields.mode])
|
||||
end
|
||||
end
|
||||
|
||||
-- Save modification timestamp.
|
||||
meta:set_int("modstamp", os.time())
|
||||
|
||||
-- Save formspec.
|
||||
meta:set_string("formspec", travelpoints.get_formspec("", meta))
|
||||
|
||||
-- Makes no sense but this block only triggers when the Escape key is
|
||||
-- pressed, will not work with button_exit which also sends quit=>true
|
||||
-- on top of it's own field.
|
||||
elseif fields.quit == "true" then
|
||||
|
||||
-- Clear list.
|
||||
meta:set_int("tp_index", 0)
|
||||
meta:set_string("tp_array", "return { }")
|
||||
|
||||
-- Save formspec.
|
||||
meta:set_string("formspec", travelpoints.get_formspec("", meta))
|
||||
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
-- Report
|
||||
travelpoints.print_notice(name, "This transporter pad belongs to \"" .. owner .. "\", you can not modify it")
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[Player Can Use Pad]----------------------------------------------------------
|
||||
--
|
||||
-- Returns a boolean value for whether or not the player can use the pad.
|
||||
@ -641,19 +1211,31 @@ end
|
||||
|
||||
--[Save travelpoints_table]----------------------------------------------------------------
|
||||
--
|
||||
-- Saves any changes to the travelpoints table to the player's travelpoints_table file.
|
||||
-- Saves any changes to the travelpoints table.
|
||||
--
|
||||
function travelpoints.save_travelpoints_table(name, travelpoints_table)
|
||||
function travelpoints.save_travelpoints_table(mode, name, travelpoints_table) -- mode(user/global)
|
||||
|
||||
-- Validate travelpoints_table.
|
||||
if ( travelpoints_table == nil ) or ( type(travelpoints_table) ~= "table" ) then
|
||||
return false
|
||||
end
|
||||
|
||||
-- Set travelpoints_table file path.
|
||||
local travelpoints_table_file = travelpoints.travelpoints_tables .. travelpoints.delimiter .. name .. ".tpt"
|
||||
|
||||
-- Open travelpoints_table file for writing.
|
||||
|
||||
local travelpoints_table_file
|
||||
|
||||
-- Set travelpoints table file path.
|
||||
if mode == "user" then
|
||||
|
||||
-- User's table.
|
||||
travelpoints_table_file = travelpoints.travelpoints_tables .. travelpoints.delimiter .. name .. ".tpt"
|
||||
|
||||
else
|
||||
|
||||
-- Global table.
|
||||
travelpoints_table_file = travelpoints.worldpath .. travelpoints.delimiter .. "travelpoints_global.tpt"
|
||||
|
||||
end
|
||||
|
||||
-- Open travelpoints table file for writing.
|
||||
local write_handle, write_error = io.open(travelpoints_table_file, "w")
|
||||
|
||||
-- Check for error.
|
||||
@ -710,6 +1292,84 @@ function travelpoints.save_world_restrictions(restrictions)
|
||||
|
||||
end
|
||||
|
||||
--[Set Pad Destination]---------------------------------------------------------
|
||||
--
|
||||
-- Sets pad meta values for the destination chosen by user.
|
||||
--
|
||||
|
||||
-- Get index value.
|
||||
--local index = travelpoints.get_textlist_index(fields.global_list)
|
||||
|
||||
|
||||
function travelpoints.set_pad_destination(mode, index, meta)
|
||||
|
||||
local user_travelpoints_array, global_travelpoints_array
|
||||
|
||||
if mode == "user" then
|
||||
|
||||
if index ~= meta:get_int("gtp_index") then
|
||||
|
||||
-- Get this node's global travelpoints array.
|
||||
global_travelpoints_array = minetest.deserialize(meta:get_string("global_travelpoints_array"))
|
||||
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
end
|
||||
|
||||
if index ~= meta:get_int("gtp_index") then
|
||||
|
||||
-- Get this node's global travelpoints array.
|
||||
local global_travelpoints_array = minetest.deserialize(meta:get_string("global_travelpoints_array"))
|
||||
|
||||
-- Extract title and destination from array value.
|
||||
local title, destination = string.match(global_travelpoints_array[index], "^([^ ]+)%s+(.+)")
|
||||
|
||||
-- Remove escapes.
|
||||
destination = string.gsub(destination, "\\", "", 2)
|
||||
|
||||
-- Pads can't teleport to themselves.
|
||||
if destination ~= minetest.pos_to_string(pos) then
|
||||
|
||||
-- Set or clear title and destination meta data.
|
||||
if ( index == 1 ) or ( index > #global_travelpoints_array ) then
|
||||
meta:set_string("title", "")
|
||||
meta:set_string("destination", "")
|
||||
meta:set_string("source", "")
|
||||
meta:set_int("gtp_index", 1)
|
||||
else
|
||||
meta:set_string("title", title)
|
||||
meta:set_string("destination", destination)
|
||||
meta:set_string("source", "Global")
|
||||
meta:set_int("gtp_index", index)
|
||||
end
|
||||
|
||||
meta:set_string("global_travelpoints_array", "return { }")
|
||||
meta:set_int("utp_index", 1)
|
||||
meta:set_string("user_travelpoints_array", "return { }")
|
||||
|
||||
-- Save modification timestamp.
|
||||
meta:set_int("modstamp", os.time())
|
||||
|
||||
-- Save formspec.
|
||||
meta:set_string("formspec", travelpoints.get_formspec("global", meta))
|
||||
|
||||
-- Save infotext.
|
||||
meta:set_string("infotext", travelpoints.get_infotext(meta))
|
||||
|
||||
else
|
||||
|
||||
-- Report
|
||||
travelpoints.print_notice(name, "Error: You can not set the transporter pad's location as its destination.")
|
||||
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[Swap Node]-------------------------------------------------------------------
|
||||
--
|
||||
-- This function should not be needed after Minetest 0.4.9
|
||||
@ -855,7 +1515,7 @@ end
|
||||
function travelpoints.travelpad_log(name, meta, action)
|
||||
|
||||
-- Get travelpoints_table.
|
||||
local travelpoints_table = travelpoints.get_travelpoints_table(name)
|
||||
local travelpoints_table = travelpoints.get_travelpoints_table("user", name)
|
||||
|
||||
-- Initialize _travelpads if needed.
|
||||
if travelpoints_table._travelpads == nil then
|
||||
@ -889,7 +1549,7 @@ function travelpoints.travelpad_log(name, meta, action)
|
||||
travelpoints_table._travelpads[location] = meta:get_int("timestamp")
|
||||
|
||||
-- Save travelpoints_table.
|
||||
travelpoints.save_travelpoints_table(name, travelpoints_table)
|
||||
travelpoints.save_travelpoints_table("user", name, travelpoints_table)
|
||||
|
||||
return
|
||||
|
||||
@ -907,7 +1567,7 @@ function travelpoints.travelpad_log(name, meta, action)
|
||||
travelpoints_table._travelpads[location] = nil
|
||||
|
||||
-- Save travelpoints_table.
|
||||
travelpoints.save_travelpoints_table(name, travelpoints_table)
|
||||
travelpoints.save_travelpoints_table("user", name, travelpoints_table)
|
||||
|
||||
return
|
||||
|
||||
|
410
init.lua
410
init.lua
@ -1,6 +1,6 @@
|
||||
--------------------------------------------------------------------------------
|
||||
--
|
||||
-- Minetest Mod "Travelpoints" Version 1.3 2015-03-24
|
||||
-- Minetest Mod "Travelpoints" Version 1.4 2015-03-27
|
||||
--
|
||||
-- By Racso Rhodes
|
||||
--
|
||||
@ -23,7 +23,10 @@
|
||||
--
|
||||
-- /tpback
|
||||
-- /tpdrop
|
||||
-- /tpgdrop
|
||||
-- /tpggo
|
||||
-- /tpgo
|
||||
-- /tpgset
|
||||
-- /travelpads
|
||||
-- /travelpoints
|
||||
-- /tpset
|
||||
@ -36,7 +39,8 @@
|
||||
|
||||
-- Register privilege - travelpoints.
|
||||
--
|
||||
-- This allows usage of the "bookmarking" features of Travelpoints.
|
||||
-- This allows users to set, drop and use their own travelpoints.
|
||||
-- Also allows usage of global travelpoints.
|
||||
--
|
||||
minetest.register_privilege("travelpoints", "Can use the Travelpoints chat commands.")
|
||||
|
||||
@ -46,6 +50,12 @@ minetest.register_privilege("travelpoints", "Can use the Travelpoints chat comma
|
||||
--
|
||||
minetest.register_privilege("travelpads", "Can place Travelpoint Transporter Pads.")
|
||||
|
||||
-- Register privilege - tpglobal
|
||||
--
|
||||
-- This allows the saving and dropping of global travelpoints.
|
||||
--
|
||||
minetest.register_privilege("tpglobal", "Can set and drop global travelpoints.")
|
||||
|
||||
-- Initialize mod table.
|
||||
travelpoints = {}
|
||||
|
||||
@ -65,10 +75,10 @@ travelpoints.travelpoints_tables = travelpoints.worldpath .. travelpoints.delimi
|
||||
os.execute("mkdir \"" .. travelpoints.travelpoints_tables .. "\"")
|
||||
|
||||
-- Set version for /travelpoints.
|
||||
travelpoints.version_number = "1.3"
|
||||
travelpoints.version_number = "1.4"
|
||||
|
||||
-- Set version date for /travelpoints.
|
||||
travelpoints.version_date = "2015-03-24"
|
||||
travelpoints.version_date = "2015-03-27"
|
||||
|
||||
-- Initialize restrictions table.
|
||||
travelpoints.restrictions = {}
|
||||
@ -103,7 +113,7 @@ minetest.register_chatcommand("tpback", {
|
||||
func = function(name, param)
|
||||
|
||||
-- Get travelpoints_table.
|
||||
local travelpoints_table = travelpoints.get_travelpoints_table(name)
|
||||
local travelpoints_table = travelpoints.get_travelpoints_table("user", name)
|
||||
|
||||
-- Check for return location.
|
||||
if not travelpoints_table._back then
|
||||
@ -123,7 +133,7 @@ minetest.register_chatcommand("tpback", {
|
||||
-- Clear return location.
|
||||
if travelpoints.restrictions.clear_back_pos > 0 then
|
||||
travelpoints_table._back = nil
|
||||
travelpoints.save_travelpoints_table(name, travelpoints_table)
|
||||
travelpoints.save_travelpoints_table("user", name, travelpoints_table)
|
||||
end
|
||||
|
||||
end,
|
||||
@ -155,7 +165,7 @@ minetest.register_chatcommand("tpdrop", {
|
||||
elseif param == "all" then
|
||||
|
||||
-- Get travelpoints_table.
|
||||
local travelpoints_table = travelpoints.get_travelpoints_table(name)
|
||||
local travelpoints_table = travelpoints.get_travelpoints_table("user", name)
|
||||
|
||||
-- Initialize new travelpoints_table.
|
||||
local tpt = {}
|
||||
@ -171,7 +181,7 @@ minetest.register_chatcommand("tpdrop", {
|
||||
end
|
||||
|
||||
-- Overwrite existing travelpoints_table with new table.
|
||||
if travelpoints.save_travelpoints_table(name, tpt) then
|
||||
if travelpoints.save_travelpoints_table("user", name, tpt) then
|
||||
|
||||
-- Report success.
|
||||
travelpoints.print_notice(name, "You have removed all of your travelpoints for this world." )
|
||||
@ -201,7 +211,7 @@ minetest.register_chatcommand("tpdrop", {
|
||||
end
|
||||
|
||||
-- Get travelpoints_table.
|
||||
local travelpoints_table = travelpoints.get_travelpoints_table(name)
|
||||
local travelpoints_table = travelpoints.get_travelpoints_table("user", name)
|
||||
|
||||
-- Check if <title> is a valid travelpoint.
|
||||
if travelpoints_table[title] == nil then
|
||||
@ -213,7 +223,7 @@ minetest.register_chatcommand("tpdrop", {
|
||||
travelpoints_table[title] = nil
|
||||
|
||||
-- Save travelpoints_table.
|
||||
if travelpoints.save_travelpoints_table(name, travelpoints_table) then
|
||||
if travelpoints.save_travelpoints_table("user", name, travelpoints_table) then
|
||||
|
||||
-- Report success.
|
||||
travelpoints.print_notice(name, "Travelpoint \"" .. title .. "\" has been removed." )
|
||||
@ -230,6 +240,246 @@ minetest.register_chatcommand("tpdrop", {
|
||||
end,
|
||||
})
|
||||
|
||||
--[/tpgdrop]--------------------------------------------------------------------
|
||||
--
|
||||
-- Removes global travelpoints, or all if specified.
|
||||
--
|
||||
minetest.register_chatcommand("tpgdrop", {
|
||||
params = "<title> | all",
|
||||
description = "Removes the global travelpoint specified by <title>. To remove all global travelpoints for this world, use \"/tpgdrop all\".",
|
||||
privs = {tpglobal=true},
|
||||
func = function(name, param)
|
||||
|
||||
------------------------------------------------------------------------
|
||||
-- /tpgdrop
|
||||
------------------------------------------------------------------------
|
||||
if param == "" then
|
||||
|
||||
travelpoints.print_notice(name, "Error: No travelpoint was specified.")
|
||||
|
||||
return
|
||||
|
||||
------------------------------------------------------------------------
|
||||
-- /tpgdrop all
|
||||
------------------------------------------------------------------------
|
||||
elseif param == "all" then
|
||||
|
||||
-- Check if user has server privilege.
|
||||
if minetest.get_player_privs(name)["server"] then
|
||||
|
||||
-- Get travelpoints table.
|
||||
local travelpoints_table = travelpoints.get_travelpoints_table("global", name)
|
||||
|
||||
-- Initialize new travelpoints table.
|
||||
local tpt = {}
|
||||
|
||||
-- Overwrite existing travelpoints table with new table.
|
||||
if travelpoints.save_travelpoints_table("global", name, tpt) then
|
||||
|
||||
-- Report success.
|
||||
travelpoints.print_notice(name, "You have removed all global travelpoints for this world." )
|
||||
|
||||
else
|
||||
|
||||
-- Report error.
|
||||
travelpoints.print_notice(name, "Error: Global travelpoints for this world could not be removed.")
|
||||
|
||||
end
|
||||
|
||||
return
|
||||
|
||||
else
|
||||
|
||||
-- Report error.
|
||||
travelpoints.print_notice(name, "Server privilege required to drop all global travelpoints.")
|
||||
|
||||
end
|
||||
|
||||
------------------------------------------------------------------------
|
||||
-- /tpgdrop <title>
|
||||
------------------------------------------------------------------------
|
||||
else
|
||||
|
||||
-- Get Title.
|
||||
local title = string.match(param, "^([^ ]+)%s*")
|
||||
|
||||
-- Validate Title.
|
||||
local notice = travelpoints.validate_title(title)
|
||||
if notice ~= nil then
|
||||
travelpoints.print_notice(name, notice)
|
||||
return
|
||||
end
|
||||
|
||||
-- Get travelpoints_table.
|
||||
local travelpoints_table = travelpoints.get_travelpoints_table("global", name)
|
||||
|
||||
-- Check if <title> is a valid travelpoint.
|
||||
if travelpoints_table[title] == nil then
|
||||
travelpoints.print_notice(name, "Error: Global travelpoint \"" .. title .. "\" does not exist.")
|
||||
return
|
||||
end
|
||||
|
||||
-- Remove travelpoint from table.
|
||||
travelpoints_table[title] = nil
|
||||
|
||||
-- Save travelpoints_table.
|
||||
if travelpoints.save_travelpoints_table("global", name, travelpoints_table) then
|
||||
|
||||
-- Report success.
|
||||
travelpoints.print_notice(name, "Global travelpoint \"" .. title .. "\" has been removed." )
|
||||
|
||||
else
|
||||
|
||||
-- Report error.
|
||||
travelpoints.print_notice(name, "Error: Global travelpoint \"" .. title .. "\" could not be removed.")
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end,
|
||||
})
|
||||
|
||||
--[/tpggo]-----------------------------------------------------------------------
|
||||
--
|
||||
-- Teleports player to specified global travelpoint, or displays available
|
||||
-- global travelpoints if no title given.
|
||||
--
|
||||
minetest.register_chatcommand("tpggo", {
|
||||
params = "(nothing) | <title>",
|
||||
description = "Teleports you to the specified global travelpoint. If no travelpoint given, a list of available global travelpoints is displayed.",
|
||||
privs = {travelpoints=true},
|
||||
func = function(name, param)
|
||||
|
||||
-- Get global travelpoints table.
|
||||
local global_travelpoints_table = travelpoints.get_travelpoints_table("global", name)
|
||||
|
||||
-- Get player's travelpoints table.
|
||||
local user_travelpoints_table = travelpoints.get_travelpoints_table("user", name)
|
||||
|
||||
-- Assume no cooldown until calculated otherwise.
|
||||
local cooldown_remaining = "none"
|
||||
|
||||
-- Get current time.
|
||||
local now = os.time()
|
||||
|
||||
-- Check if coodown needs to be calculated.
|
||||
if ( not minetest.is_singleplayer() ) and ( travelpoints.restrictions.cooldown > 0 ) and ( not minetest.get_player_privs(name)["server"] ) then
|
||||
|
||||
if user_travelpoints_table._cooldown ~= nil then
|
||||
|
||||
-- Cooldown timestamp.
|
||||
local coolstamp = user_travelpoints_table._cooldown
|
||||
|
||||
-- Seconds since cooldown timestamp.
|
||||
local seconds_since = ( now - coolstamp )
|
||||
|
||||
-- Check if seconds since last /tpgo <title> or /tpggo <title>
|
||||
-- is less than cooldown time.
|
||||
if seconds_since < travelpoints.restrictions.cooldown then
|
||||
|
||||
-- Get time remaining for cooldown.
|
||||
cooldown_remaining = travelpoints.get_duration(travelpoints.restrictions.cooldown - seconds_since)
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
------------------------------------------------------------------------
|
||||
-- /tpggo
|
||||
------------------------------------------------------------------------
|
||||
if param == "" then
|
||||
|
||||
-- Get travelpoints array.
|
||||
local travelpoints_array = travelpoints.get_travelpoints_array("global", name)
|
||||
|
||||
-- Check if there are any travelpoints.
|
||||
if #travelpoints_array > 0 then
|
||||
|
||||
-- Begin output.
|
||||
travelpoints.print_notice(name, "Available global travelpoints:")
|
||||
|
||||
-- Step through travelpoints_array.
|
||||
for index, value in ipairs(travelpoints_array) do
|
||||
|
||||
-- Extract title from value: "<title> (<x>, <y>, <z>)"
|
||||
local title = string.match(value, "^([^ ]+)%s+")
|
||||
|
||||
-- Output lines.
|
||||
-- <n>. <title> (<x>, <y>, <z>). Saved on <date> at <time>. Descripton: <desc>
|
||||
travelpoints.print_notice(name, index .. ". \"" .. title .. "\" " .. minetest.pos_to_string(global_travelpoints_table[title].pos) .. ". Saved on " .. os.date("%Y-%m-%d at %I:%M:%S %p", global_travelpoints_table[title].timestamp) .. ". Description: " .. global_travelpoints_table[title].desc)
|
||||
|
||||
end
|
||||
|
||||
else
|
||||
travelpoints.print_notice(name, "There are no saved global travelpoints.")
|
||||
end
|
||||
|
||||
-- Cooldown remaining.
|
||||
if cooldown_remaining ~= "none" then
|
||||
travelpoints.print_notice(name, "Your remaining cooldown is: " .. cooldown_remaining .. ".")
|
||||
end
|
||||
|
||||
return
|
||||
|
||||
------------------------------------------------------------------------
|
||||
-- /tpggo <title>
|
||||
------------------------------------------------------------------------
|
||||
else
|
||||
|
||||
-- Check if player is on cooldown.
|
||||
if cooldown_remaining == "none" then
|
||||
|
||||
-- Get Title.
|
||||
local title = string.match(param, "^([^ ]+)%s*")
|
||||
|
||||
-- Validate Title.
|
||||
local notice = travelpoints.validate_title(title)
|
||||
if notice ~= nil then
|
||||
travelpoints.print_notice(name, notice)
|
||||
return
|
||||
end
|
||||
|
||||
-- Check for specified travelpoint.
|
||||
if not global_travelpoints_table[title] then
|
||||
travelpoints.print_notice(name, "Error: Global travelpoint \"" .. title .. "\"does not exist.")
|
||||
return
|
||||
end
|
||||
|
||||
-- Set location for /tpback
|
||||
user_travelpoints_table._back = travelpoints.get_location(name)
|
||||
|
||||
-- Get player.
|
||||
local player = minetest.get_player_by_name(name)
|
||||
|
||||
-- Teleport player.
|
||||
player:setpos(global_travelpoints_table[title].pos)
|
||||
|
||||
-- Report.
|
||||
travelpoints.print_notice(name, "Teleported to global travelpoint: \"" .. title .. "\". Use /tpback to return to " .. minetest.pos_to_string(user_travelpoints_table._back) .. "." )
|
||||
|
||||
-- Set cooldown if needed.
|
||||
if ( not minetest.is_singleplayer() ) and ( travelpoints.restrictions.cooldown > 0 ) then
|
||||
user_travelpoints_table._cooldown = now
|
||||
end
|
||||
|
||||
-- Save player's travelpoints table.
|
||||
travelpoints.save_travelpoints_table("user", name, user_travelpoints_table)
|
||||
|
||||
else
|
||||
|
||||
-- Report
|
||||
travelpoints.print_notice(name, "Time remaining on your cooldown: " .. cooldown_remaining .. ".")
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end,
|
||||
})
|
||||
|
||||
--[/tpgo]-----------------------------------------------------------------------
|
||||
--
|
||||
-- Teleports player to specified travelpoint, or displays available
|
||||
@ -242,7 +492,7 @@ minetest.register_chatcommand("tpgo", {
|
||||
func = function(name, param)
|
||||
|
||||
-- Get travelpoints_table.
|
||||
local travelpoints_table = travelpoints.get_travelpoints_table(name)
|
||||
local travelpoints_table = travelpoints.get_travelpoints_table("user", name)
|
||||
|
||||
-- Assume no cooldown until calculated otherwise.
|
||||
local cooldown_remaining = "none"
|
||||
@ -279,13 +529,10 @@ minetest.register_chatcommand("tpgo", {
|
||||
if param == "" then
|
||||
|
||||
-- Get travelpoints_array.
|
||||
local travelpoints_array = travelpoints.get_travelpoints_array(name)
|
||||
|
||||
-- Get travelpoint count.
|
||||
local tp_count = #travelpoints_array - 1
|
||||
local travelpoints_array = travelpoints.get_travelpoints_array("user", name)
|
||||
|
||||
-- Check if player has any travelpoints.
|
||||
if tp_count > 0 then
|
||||
if #travelpoints_array > 0 then
|
||||
|
||||
-- Begin output.
|
||||
travelpoints.print_notice(name, "Your available travelpoints:")
|
||||
@ -293,18 +540,12 @@ minetest.register_chatcommand("tpgo", {
|
||||
-- Step through travelpoints_array.
|
||||
for index, value in ipairs(travelpoints_array) do
|
||||
|
||||
-- Omit first index (used for
|
||||
-- travelpoints:transporter_pad/_active's formspec)
|
||||
if index > 1 then
|
||||
-- Extract title from value: "<title> (<x>, <y>, <z>)"
|
||||
local title = string.match(value, "^([^ ]+)%s+")
|
||||
|
||||
-- Extract title from value: "<title> (<x>, <y>, <z>)"
|
||||
local title = string.match(value, "^([^ ]+)%s+")
|
||||
|
||||
-- Output lines.
|
||||
-- <n>. <title> (<x>, <y>, <z>). Saved on <date> at <time>. Descripton: <desc>
|
||||
travelpoints.print_notice(name, index - 1 .. ". \"" .. title .. "\" " .. minetest.pos_to_string(travelpoints_table[title].pos) .. ". Saved on " .. os.date("%Y-%m-%d at %I:%M:%S %p", travelpoints_table[title].timestamp) .. ". Description: " .. travelpoints_table[title].desc)
|
||||
|
||||
end
|
||||
-- Output lines.
|
||||
-- <n>. <title> (<x>, <y>, <z>). Saved on <date> at <time>. Descripton: <desc>
|
||||
travelpoints.print_notice(name, index .. ". \"" .. title .. "\" " .. minetest.pos_to_string(travelpoints_table[title].pos) .. ". Saved on " .. os.date("%Y-%m-%d at %I:%M:%S %p", travelpoints_table[title].timestamp) .. ". Description: " .. travelpoints_table[title].desc)
|
||||
|
||||
end
|
||||
|
||||
@ -377,7 +618,7 @@ minetest.register_chatcommand("tpgo", {
|
||||
end
|
||||
|
||||
-- Save travelpoints_table.
|
||||
travelpoints.save_travelpoints_table(name, travelpoints_table)
|
||||
travelpoints.save_travelpoints_table("user", name, travelpoints_table)
|
||||
|
||||
else
|
||||
|
||||
@ -391,6 +632,93 @@ minetest.register_chatcommand("tpgo", {
|
||||
end,
|
||||
})
|
||||
|
||||
--[/tpgset]---------------------------------------------------------------------
|
||||
--
|
||||
-- Adds a new travelpoint to the world's global travelpoints table.
|
||||
--
|
||||
minetest.register_chatcommand("tpgset", {
|
||||
params = "<title> | <title> <desc>",
|
||||
description = "Set a new global travelpoint at your current location. Title required, description optional.",
|
||||
privs = {tpglobal=true},
|
||||
func = function(name, param)
|
||||
|
||||
------------------------------------------------------------------------
|
||||
-- /tpgset
|
||||
------------------------------------------------------------------------
|
||||
|
||||
if param == "" then
|
||||
travelpoints.print_notice(name, "Error: Travelpoint must be saved with a title.")
|
||||
return
|
||||
else
|
||||
|
||||
--------------------------------------------------------------------
|
||||
-- /tpgset <title> | <title> <desc>
|
||||
--------------------------------------------------------------------
|
||||
|
||||
local title, desc, notice, pos
|
||||
|
||||
-- Get parameters.
|
||||
if string.find(param, "^[^ ]+%s+.+") then
|
||||
title, desc = string.match(param, "^([^ ]+)%s+(.+)")
|
||||
else
|
||||
title = param
|
||||
desc = ""
|
||||
end
|
||||
|
||||
-- Validate Title.
|
||||
if title ~= nil then
|
||||
notice = travelpoints.validate_title(title)
|
||||
if notice ~= nil then
|
||||
travelpoints.print_notice(name, notice)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
-- Validate Description.
|
||||
if desc ~= "" then
|
||||
notice = travelpoints.validate_desc(desc)
|
||||
if notice ~= nil then
|
||||
travelpoints.print_notice(name, notice)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
-- Get player's location.
|
||||
pos = travelpoints.get_location(name)
|
||||
|
||||
-- Initialize temporary travelpoint table.
|
||||
local travelpoint = {}
|
||||
|
||||
-- Build travelpoint table.
|
||||
travelpoint.pos = pos
|
||||
travelpoint.desc = desc
|
||||
travelpoint.timestamp = os.time()
|
||||
|
||||
-- Get travelpoints_table.
|
||||
local travelpoints_table = travelpoints.get_travelpoints_table("global", name)
|
||||
|
||||
-- Check for duplicate title.
|
||||
if travelpoints_table[title] ~= nil then
|
||||
travelpoints.print_notice(name, "Error: A global travelpoint already exists for this title: " .. title)
|
||||
else
|
||||
|
||||
-- Merge tables.
|
||||
travelpoints_table[title] = travelpoint
|
||||
|
||||
-- Save travelpoints_table.
|
||||
if travelpoints.save_travelpoints_table("global", name, travelpoints_table) then
|
||||
travelpoints.print_notice(name, "Global travelpoint \"" .. title .. "\" has been saved.")
|
||||
else
|
||||
travelpoints.print_notice(name, "Error: Global travelpoint \"" .. title .. "\" could not be saved.")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end,
|
||||
})
|
||||
|
||||
--[/travelpads]-----------------------------------------------------------------
|
||||
--
|
||||
-- Returns a list of transporter pads the user has placed.
|
||||
@ -402,7 +730,7 @@ minetest.register_chatcommand("travelpads", {
|
||||
func = function(name, param)
|
||||
|
||||
-- Get travelpoints_table.
|
||||
local travelpoints_table = travelpoints.get_travelpoints_table(name)
|
||||
local travelpoints_table = travelpoints.get_travelpoints_table("user", name)
|
||||
|
||||
-- Initialize array
|
||||
local travelpads = {}
|
||||
@ -481,25 +809,31 @@ minetest.register_chatcommand("travelpoints", {
|
||||
local player_cooldown = "none"
|
||||
local travelpads = {}
|
||||
local tpback
|
||||
local travelpoints_table = travelpoints.get_travelpoints_table(name)
|
||||
local travelpoints_array = travelpoints.get_travelpoints_array(name)
|
||||
local travelpoints_table = travelpoints.get_travelpoints_table("user", name)
|
||||
local travelpoints_array = travelpoints.get_travelpoints_array("user", name)
|
||||
|
||||
-- Max travelpoints
|
||||
if travelpoints.restrictions.max_travelpoints == 0 then
|
||||
if minetest.get_player_privs(name)["server"] then
|
||||
max_travelpoints = "No limit (server privilege)"
|
||||
elseif travelpoints.restrictions.max_travelpoints == 0 then
|
||||
max_travelpoints = "No limit"
|
||||
else
|
||||
max_travelpoints = travelpoints.restrictions.max_travelpoints
|
||||
end
|
||||
|
||||
-- Max travelpads
|
||||
if travelpoints.restrictions.max_travelpads == 0 then
|
||||
if minetest.get_player_privs(name)["server"] then
|
||||
max_travelpads = "No limit (server privilege)"
|
||||
elseif travelpoints.restrictions.max_travelpads == 0 then
|
||||
max_travelpads = "No limit"
|
||||
else
|
||||
max_travelpads = travelpoints.restrictions.max_travelpads
|
||||
end
|
||||
|
||||
-- Cooldown
|
||||
if travelpoints.restrictions.cooldown == 0 then
|
||||
if minetest.get_player_privs(name)["server"] then
|
||||
cooldown = "No cooldown (server privilege)"
|
||||
elseif travelpoints.restrictions.cooldown == 0 then
|
||||
cooldown = "No cooldown"
|
||||
else
|
||||
cooldown = travelpoints.get_duration(travelpoints.restrictions.cooldown)
|
||||
@ -533,7 +867,7 @@ minetest.register_chatcommand("travelpoints", {
|
||||
-- Report
|
||||
travelpoints.print_notice(name, "Running Travelpoints version " .. travelpoints.version_number .. " released on " .. travelpoints.version_date .. ".")
|
||||
travelpoints.print_notice(name, "Restrictions:")
|
||||
travelpoints.print_notice(name, "Max Travelpoints: [" .. max_travelpoints .. "] You have: [" .. #travelpoints_array - 1 .. "]")
|
||||
travelpoints.print_notice(name, "Max Travelpoints: [" .. max_travelpoints .. "] You have: [" .. #travelpoints_array .. "]")
|
||||
travelpoints.print_notice(name, "Max Transporter Pads: [" .. max_travelpads .. "] You have: [" .. #travelpads .. "]")
|
||||
travelpoints.print_notice(name, "Cooldown: [" .. cooldown .. "] Your cooldown is: [" .. player_cooldown .. "]")
|
||||
travelpoints.print_notice(name, "Back Location: [" .. tpback .. "]")
|
||||
@ -702,7 +1036,7 @@ minetest.register_chatcommand("tpset", {
|
||||
-- /tpset <title> | <title> <desc>
|
||||
------------------------------------------------------------------------
|
||||
|
||||
local tp_count = #travelpoints.get_travelpoints_array(name) - 1
|
||||
local tp_count = #travelpoints.get_travelpoints_array("user", name)
|
||||
|
||||
-- Handle maximum_travelpoints if it is configured.
|
||||
if ( not minetest.is_singleplayer() ) and ( travelpoints.restrictions.max_travelpoints > 0 ) and ( tp_count >= travelpoints.restrictions.max_travelpoints ) and ( not minetest.get_player_privs(name)["server"] ) then
|
||||
@ -753,7 +1087,7 @@ minetest.register_chatcommand("tpset", {
|
||||
travelpoint.timestamp = os.time()
|
||||
|
||||
-- Get travelpoints_table.
|
||||
local travelpoints_table = travelpoints.get_travelpoints_table(name)
|
||||
local travelpoints_table = travelpoints.get_travelpoints_table("user", name)
|
||||
|
||||
-- Check for duplicate title.
|
||||
if travelpoints_table[title] ~= nil then
|
||||
@ -764,7 +1098,7 @@ minetest.register_chatcommand("tpset", {
|
||||
travelpoints_table[title] = travelpoint
|
||||
|
||||
-- Save travelpoints_table.
|
||||
if travelpoints.save_travelpoints_table(name, travelpoints_table) then
|
||||
if travelpoints.save_travelpoints_table("user", name, travelpoints_table) then
|
||||
travelpoints.print_notice(name, "Travelpoint \"" .. title .. "\" has been saved.")
|
||||
else
|
||||
travelpoints.print_notice(name, "Error: Travelpoint \"" .. title .. "\" could not be saved.")
|
||||
|
803
nodes.lua
803
nodes.lua
@ -1,6 +1,6 @@
|
||||
--------------------------------------------------------------------------------
|
||||
--
|
||||
-- Minetest Mod "Travelpoints" Version 1.3 2015-03-24
|
||||
-- Minetest Mod "Travelpoints" Version 1.4 2015-03-27
|
||||
--
|
||||
-- By Racso Rhodes
|
||||
--
|
||||
@ -130,398 +130,13 @@ minetest.register_node("travelpoints:transporter_pad", {
|
||||
},
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
-- ON DESTRUCT
|
||||
----------------------------------------------------------------------------
|
||||
on_destruct = travelpoints.on_destruct,
|
||||
|
||||
on_destruct = function(pos)
|
||||
after_place_node = travelpoints.after_place_node,
|
||||
|
||||
-- Get nodes metadata.
|
||||
local meta = minetest.get_meta(pos)
|
||||
on_receive_fields = travelpoints.on_receive_fields,
|
||||
|
||||
if meta:get_string("owner") ~= "" then
|
||||
|
||||
-- Remove travelpad from log.
|
||||
travelpoints.travelpad_log(meta:get_string("owner"), meta, "remove")
|
||||
|
||||
end
|
||||
|
||||
end,
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
-- AFTER PLACE NODE
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
after_place_node = function(pos, placer)
|
||||
|
||||
-- Get node metadata.
|
||||
local meta = minetest.get_meta(pos)
|
||||
|
||||
-- Get placer's name.
|
||||
local name = placer:get_player_name()
|
||||
|
||||
-- Get player's travelpad count for this world.
|
||||
local travelpad_count = travelpoints.travelpad_log(name, meta, "count")
|
||||
|
||||
-- Verify privs.
|
||||
if not minetest.get_player_privs(name)["travelpads"] then
|
||||
|
||||
-- Report
|
||||
travelpoints.print_notice(name, "You do not have the privilege to place transporter pads.")
|
||||
|
||||
-- Remove travelpad.
|
||||
minetest.remove_node(pos)
|
||||
|
||||
-- Drop travelpad for pickup.
|
||||
minetest.add_item(pos, 'travelpoints:transporter_pad')
|
||||
|
||||
-- Handle maximum_travelpads if it is configured.
|
||||
elseif ( not minetest.is_singleplayer() ) and ( travelpoints.restrictions.max_travelpads > 0 ) and ( travelpad_count >= travelpoints.restrictions.max_travelpads ) and ( not minetest.get_player_privs(name)["server"]) then
|
||||
|
||||
-- Report
|
||||
travelpoints.print_notice(name, "You have already reached your maximum number of transporter pads: " .. travelpoints.restrictions.max_travelpads .. ".")
|
||||
|
||||
-- Remove travelpad.
|
||||
minetest.remove_node(pos)
|
||||
|
||||
-- Drop travelpad for pickup.
|
||||
minetest.add_item(pos, 'travelpoints:transporter_pad')
|
||||
|
||||
else
|
||||
|
||||
-- Set default values.
|
||||
meta:set_string("location", minetest.pos_to_string(pos))
|
||||
meta:set_string("owner", name)
|
||||
meta:set_string("title", "")
|
||||
meta:set_string("destination", "")
|
||||
meta:set_int("timestamp", os.time())
|
||||
meta:set_int("modstamp", 0)
|
||||
meta:set_int("tp_index", 1)
|
||||
meta:set_int("mode_index", 1)
|
||||
meta:set_string("players", "return { }")
|
||||
|
||||
-- Add travelpad to log.
|
||||
travelpoints.travelpad_log(name, meta, "add")
|
||||
|
||||
-- Get the current travelpoints array.
|
||||
local travelpoints_array = travelpoints.get_travelpoints_array(name)
|
||||
|
||||
-- Serialize travelpoints_array.
|
||||
local travelpoints_array = minetest.serialize(travelpoints_array)
|
||||
|
||||
-- Save travelpoints_array.
|
||||
meta:set_string("travelpoints_array", travelpoints_array)
|
||||
|
||||
-- Save default formspec
|
||||
meta:set_string("formspec", travelpoints.get_formspec(meta))
|
||||
|
||||
-- Save default infotext.
|
||||
meta:set_string("infotext", travelpoints.get_infotext(meta))
|
||||
|
||||
end
|
||||
|
||||
end,
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
-- ON RECIEVE FIELDS
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
on_receive_fields = function(pos, formname, fields, sender)
|
||||
|
||||
local meta = minetest.get_meta(pos)
|
||||
|
||||
local name = sender:get_player_name()
|
||||
|
||||
local owner = meta:get_string("owner")
|
||||
|
||||
-- Only pad owner or a player with server privilege can make changes.
|
||||
if ( name == owner ) or ( minetest.get_player_privs(name)["server"] ) then
|
||||
|
||||
--------------------------------------------------------------------
|
||||
-- Handle get travelpoints press.
|
||||
--------------------------------------------------------------------
|
||||
--
|
||||
-- This syncs the node's travelpoints_array with the owner's current
|
||||
-- travelpoints_table.
|
||||
--
|
||||
if ( fields.list_travelpoints == "List Travelpoints" ) and ( name == owner ) then
|
||||
|
||||
-- Get the current travelpoints array.
|
||||
local travelpoints_array = travelpoints.get_travelpoints_array(owner)
|
||||
|
||||
-- Serialize travelpoints_array.
|
||||
local travelpoints_array = minetest.serialize(travelpoints_array)
|
||||
|
||||
-- Save travelpoints_array.
|
||||
meta:set_string("travelpoints_array", travelpoints_array)
|
||||
|
||||
-- Set pad to "Offline".
|
||||
--
|
||||
-- Assumed that player chose to refresh in order to point the pad to
|
||||
-- new coords.
|
||||
--
|
||||
meta:set_string("title", "")
|
||||
meta:set_string("destination", "")
|
||||
meta:set_int("tp_index", 1)
|
||||
|
||||
-- Save modification timestamp.
|
||||
meta:set_int("modstamp", os.time())
|
||||
|
||||
-- Save formspec.
|
||||
meta:set_string("formspec", travelpoints.get_formspec(meta))
|
||||
|
||||
-- Save infotext.
|
||||
meta:set_string("infotext", travelpoints.get_infotext(meta))
|
||||
|
||||
--------------------------------------------------------------------
|
||||
-- Handle travelpoint selection.
|
||||
--------------------------------------------------------------------
|
||||
|
||||
elseif ( fields.travelpoint ) and ( name == owner) then
|
||||
|
||||
-- Get index value.
|
||||
local index = travelpoints.get_textlist_index(fields.travelpoint)
|
||||
|
||||
if index ~= meta:get_int("tp_index") then
|
||||
|
||||
-- Get this node's travelpoints_array.
|
||||
local travelpoints_array = minetest.deserialize(meta:get_string("travelpoints_array"))
|
||||
|
||||
-- Extract title and destination from array value.
|
||||
local title, destination = string.match(travelpoints_array[index], "^([^ ]+)%s+(.+)")
|
||||
|
||||
-- Remove escapes.
|
||||
destination = string.gsub(destination, "\\", "", 2)
|
||||
|
||||
-- Pads can't teleport to themselves.
|
||||
if destination ~= minetest.pos_to_string(pos) then
|
||||
|
||||
-- Set or clear title and destination meta data.
|
||||
if ( index == 1 ) or ( index > #travelpoints_array ) then
|
||||
meta:set_string("title", "")
|
||||
meta:set_string("destination", "")
|
||||
meta:set_int("tp_index", 1)
|
||||
meta:set_string("travelpoints_array", "return { }")
|
||||
else
|
||||
meta:set_string("title", title)
|
||||
meta:set_string("destination", destination)
|
||||
meta:set_int("tp_index", index)
|
||||
meta:set_string("travelpoints_array", "return { }")
|
||||
end
|
||||
|
||||
-- Save modification timestamp.
|
||||
meta:set_int("modstamp", os.time())
|
||||
|
||||
-- Save formspec.
|
||||
meta:set_string("formspec", travelpoints.get_formspec(meta))
|
||||
|
||||
-- Save infotext.
|
||||
meta:set_string("infotext", travelpoints.get_infotext(meta))
|
||||
|
||||
else
|
||||
|
||||
-- Report
|
||||
travelpoints.print_notice(name, "Error: You can not set the transporter pad's location as its destination.")
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------
|
||||
-- Handle player addition.
|
||||
--------------------------------------------------------------------
|
||||
|
||||
elseif ( fields.add_player == "Add Player" ) and ( string.len(fields.player_name) > 0 ) and ( name == owner) then
|
||||
|
||||
local player = fields.player_name
|
||||
|
||||
-- Validate input.
|
||||
if not string.find(player, "^[^%w_]+$") then
|
||||
|
||||
-- Owner can't add their name.
|
||||
if player ~= name then
|
||||
|
||||
-- Check if player exists.
|
||||
if travelpoints.player_exists(player) then
|
||||
|
||||
-- Check if player is already in array.
|
||||
if not travelpoints.player_in_players(player, meta:get_string("players")) then
|
||||
|
||||
-- Get players array.
|
||||
local players = minetest.deserialize(meta:get_string("players"))
|
||||
|
||||
-- Add player.
|
||||
table.insert(players, player)
|
||||
|
||||
-- Sort values.
|
||||
if #players > 1 then
|
||||
table.sort(players, function(A, B) return A < B end)
|
||||
end
|
||||
|
||||
-- Save players array.
|
||||
meta:set_string("players", minetest.serialize(players))
|
||||
|
||||
-- Save modification timestamp.
|
||||
meta:set_int("modstamp", os.time())
|
||||
|
||||
-- Save formspec.
|
||||
meta:set_string("formspec", travelpoints.get_formspec(meta))
|
||||
|
||||
else
|
||||
|
||||
-- Report
|
||||
travelpoints.print_notice(name, "Error: \"" .. player .. "\" is already listed.")
|
||||
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
-- Report
|
||||
travelpoints.print_notice(name, "Error: \"" .. player .. "\" is not an existing player for this world.")
|
||||
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
-- Report
|
||||
travelpoints.print_notice(name, "Error: You can't add your own name.")
|
||||
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
-- Report
|
||||
travelpoints.print_notice(name, "Error: The name you entered contains disallowed characters.")
|
||||
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------
|
||||
-- Handle remove player.
|
||||
--------------------------------------------------------------------
|
||||
|
||||
elseif ( fields.remove_player == "Remove Player" ) and ( name == owner ) then
|
||||
|
||||
local player = fields.players
|
||||
|
||||
-- Get players array.
|
||||
local players = minetest.deserialize(meta:get_string("players"))
|
||||
|
||||
local player_removed = false
|
||||
|
||||
-- Step through players to find player.
|
||||
for index, value in ipairs(players) do
|
||||
|
||||
-- Remove player when found.
|
||||
if value == player then
|
||||
table.remove(players, index)
|
||||
player_removed = true
|
||||
break
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-- Check if a player was removed.
|
||||
if player_removed then
|
||||
|
||||
-- Sort values.
|
||||
if #players > 1 then
|
||||
table.sort(players, function(A, B) return A < B end)
|
||||
end
|
||||
|
||||
-- Save players array.
|
||||
meta:set_string("players", minetest.serialize(players))
|
||||
|
||||
-- Save modification timestamp.
|
||||
meta:set_int("modstamp", os.time())
|
||||
|
||||
-- Save formspec.
|
||||
meta:set_string("formspec", travelpoints.get_formspec(meta))
|
||||
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------
|
||||
-- Handle unset button press
|
||||
--------------------------------------------------------------------
|
||||
|
||||
elseif fields.unset_destination == "Unset Destination" then
|
||||
|
||||
-- Clear destination.
|
||||
meta:set_string("title", "")
|
||||
meta:set_string("destination", "")
|
||||
meta:set_int("tp_index", 1)
|
||||
|
||||
-- Save modification timestamp.
|
||||
meta:set_int("modstamp", os.time())
|
||||
|
||||
-- Save formspec.
|
||||
meta:set_string("formspec", travelpoints.get_formspec(meta))
|
||||
|
||||
-- Save infotext.
|
||||
meta:set_string("infotext", travelpoints.get_infotext(meta))
|
||||
|
||||
--------------------------------------------------------------------
|
||||
-- Handle pad access mode and save buttun press or escape key press.
|
||||
--------------------------------------------------------------------
|
||||
|
||||
elseif ( fields.save == "Save" ) or ( fields.quit == "true" ) then
|
||||
|
||||
-- Pad Access Mode
|
||||
if ( name == owner ) then
|
||||
if fields.mode then
|
||||
local mode_table = travelpoints.get_pad_modes("table")
|
||||
meta:set_int("mode_index", mode_table[fields.mode])
|
||||
end
|
||||
end
|
||||
|
||||
-- Save modification timestamp.
|
||||
meta:set_int("modstamp", os.time())
|
||||
|
||||
-- Save formspec.
|
||||
meta:set_string("formspec", travelpoints.get_formspec(meta))
|
||||
|
||||
else
|
||||
travelpoints.print_notice(name, "Only the owner of this pad can modify those fields")
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
-- Report
|
||||
travelpoints.print_notice(name, "This transporter pad belongs to \"" .. owner .. "\", you can not modify it")
|
||||
|
||||
end
|
||||
|
||||
end,
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
-- CAN DIG
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
can_dig = function(pos, player)
|
||||
|
||||
-- Get node's metadata.
|
||||
local meta = minetest.get_meta(pos)
|
||||
|
||||
-- Get player's name.
|
||||
local name = player:get_player_name()
|
||||
|
||||
-- Pads can be dug by their owners or by someone with server privilege.
|
||||
if ( minetest.get_player_privs(name)["server"] ) or ( meta:get_string("owner") == name ) then
|
||||
|
||||
-- Check if travelpad is "offline".
|
||||
if meta:get_string("destination") == "" then
|
||||
return true
|
||||
else
|
||||
travelpoints.print_notice(name, "A transporter pad can not be dug unless its destination is set to \"none\".")
|
||||
return false
|
||||
end
|
||||
|
||||
-- Anyone else.
|
||||
else
|
||||
travelpoints.print_notice(name, "You can not dig a transporter pad you do not own.")
|
||||
return false
|
||||
end
|
||||
|
||||
end,
|
||||
can_dig = travelpoints.can_dig,
|
||||
|
||||
})
|
||||
|
||||
@ -548,400 +163,16 @@ minetest.register_node("travelpoints:transporter_pad_active", {
|
||||
{ -0.5, -0.4375, -0.5, 0.5, -0.5, 0.5 },
|
||||
},
|
||||
},
|
||||
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
-- ON DESTRUCT
|
||||
----------------------------------------------------------------------------
|
||||
on_destruct = travelpoints.on_destruct,
|
||||
|
||||
on_destruct = function(pos)
|
||||
after_place_node = travelpoints.after_place_node,
|
||||
|
||||
-- Get nodes metadata.
|
||||
local meta = minetest.get_meta(pos)
|
||||
on_receive_fields = travelpoints.on_receive_fields,
|
||||
|
||||
if meta:get_string("owner") ~= "" then
|
||||
|
||||
-- Remove travelpad from log.
|
||||
travelpoints.travelpad_log(meta:get_string("owner"), meta, "remove")
|
||||
|
||||
end
|
||||
|
||||
end,
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
-- AFTER PLACE NODE
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
after_place_node = function(pos, placer)
|
||||
|
||||
-- Get node metadata.
|
||||
local meta = minetest.get_meta(pos)
|
||||
|
||||
-- Get placer's name.
|
||||
local name = placer:get_player_name()
|
||||
|
||||
-- Get player's travelpad count for this world.
|
||||
local travelpad_count = travelpoints.travelpad_log(name, meta, "count")
|
||||
|
||||
-- Verify privs.
|
||||
if not minetest.get_player_privs(name)["travelpads"] then
|
||||
|
||||
-- Report
|
||||
travelpoints.print_notice(name, "You do not have the privilege to place transporter pads.")
|
||||
|
||||
-- Remove travelpad.
|
||||
minetest.remove_node(pos)
|
||||
|
||||
-- Drop travelpad for pickup.
|
||||
minetest.add_item(pos, 'travelpoints:transporter_pad')
|
||||
|
||||
-- Handle maximum_travelpads if it is configured.
|
||||
elseif ( not minetest.is_singleplayer() ) and ( travelpoints.restrictions.max_travelpads > 0 ) and ( travelpad_count >= travelpoints.restrictions.max_travelpads ) and ( not minetest.get_player_privs(name)["server"]) then
|
||||
|
||||
-- Report
|
||||
travelpoints.print_notice(name, "You have already reached your maximum number of transporter pads: " .. travelpoints.restrictions.max_travelpads .. ".")
|
||||
|
||||
-- Remove travelpad.
|
||||
minetest.remove_node(pos)
|
||||
|
||||
-- Drop travelpad for pickup.
|
||||
minetest.add_item(pos, 'travelpoints:transporter_pad')
|
||||
|
||||
else
|
||||
|
||||
-- Set default values.
|
||||
meta:set_string("location", minetest.pos_to_string(pos))
|
||||
meta:set_string("owner", name)
|
||||
meta:set_string("title", "")
|
||||
meta:set_string("destination", "")
|
||||
meta:set_int("timestamp", os.time())
|
||||
meta:set_int("modstamp", 0)
|
||||
meta:set_int("tp_index", 1)
|
||||
meta:set_int("mode_index", 1)
|
||||
meta:set_string("players", "return { }")
|
||||
|
||||
-- Add travelpad to log.
|
||||
travelpoints.travelpad_log(name, meta, "add")
|
||||
|
||||
-- Get the current travelpoints array.
|
||||
local travelpoints_array = travelpoints.get_travelpoints_array(name)
|
||||
|
||||
-- Serialize travelpoints_array.
|
||||
local travelpoints_array = minetest.serialize(travelpoints_array)
|
||||
|
||||
-- Save travelpoints_array.
|
||||
meta:set_string("travelpoints_array", travelpoints_array)
|
||||
|
||||
-- Save default formspec
|
||||
meta:set_string("formspec", travelpoints.get_formspec(meta))
|
||||
|
||||
-- Save default infotext.
|
||||
meta:set_string("infotext", travelpoints.get_infotext(meta))
|
||||
|
||||
end
|
||||
|
||||
end,
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
-- ON RECIEVE FIELDS
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
on_receive_fields = function(pos, formname, fields, sender)
|
||||
|
||||
local meta = minetest.get_meta(pos)
|
||||
|
||||
local name = sender:get_player_name()
|
||||
|
||||
local owner = meta:get_string("owner")
|
||||
|
||||
-- Only pad owner or a player with server privilege can make changes.
|
||||
if ( name == owner ) or ( minetest.get_player_privs(name)["server"] ) then
|
||||
|
||||
--------------------------------------------------------------------
|
||||
-- Handle get travelpoints press.
|
||||
--------------------------------------------------------------------
|
||||
--
|
||||
-- This syncs the node's travelpoints_array with the owner's current
|
||||
-- travelpoints_table.
|
||||
--
|
||||
if ( fields.list_travelpoints == "List Travelpoints" ) and ( name == owner ) then
|
||||
|
||||
-- Get the current travelpoints array.
|
||||
local travelpoints_array = travelpoints.get_travelpoints_array(owner)
|
||||
|
||||
-- Serialize travelpoints_array.
|
||||
local travelpoints_array = minetest.serialize(travelpoints_array)
|
||||
|
||||
-- Save travelpoints_array.
|
||||
meta:set_string("travelpoints_array", travelpoints_array)
|
||||
|
||||
-- Set pad to "Offline".
|
||||
--
|
||||
-- Assumed that player chose to refresh in order to point the pad to
|
||||
-- new coords.
|
||||
--
|
||||
meta:set_string("title", "")
|
||||
meta:set_string("destination", "")
|
||||
meta:set_int("tp_index", 1)
|
||||
|
||||
-- Save modification timestamp.
|
||||
meta:set_int("modstamp", os.time())
|
||||
|
||||
-- Save formspec.
|
||||
meta:set_string("formspec", travelpoints.get_formspec(meta))
|
||||
|
||||
-- Save infotext.
|
||||
meta:set_string("infotext", travelpoints.get_infotext(meta))
|
||||
|
||||
--------------------------------------------------------------------
|
||||
-- Handle travelpoint selection.
|
||||
--------------------------------------------------------------------
|
||||
|
||||
elseif ( fields.travelpoint ) and ( name == owner) then
|
||||
|
||||
-- Get index value.
|
||||
local index = travelpoints.get_textlist_index(fields.travelpoint)
|
||||
|
||||
if index ~= meta:get_int("tp_index") then
|
||||
|
||||
-- Get this node's travelpoints_array.
|
||||
local travelpoints_array = minetest.deserialize(meta:get_string("travelpoints_array"))
|
||||
|
||||
-- Extract title and destination from array value.
|
||||
local title, destination = string.match(travelpoints_array[index], "^([^ ]+)%s+(.+)")
|
||||
|
||||
-- Remove escapes.
|
||||
destination = string.gsub(destination, "\\", "", 2)
|
||||
|
||||
-- Pads can't teleport to themselves.
|
||||
if destination ~= minetest.pos_to_string(pos) then
|
||||
|
||||
-- Set or clear title and destination meta data.
|
||||
if ( index == 1 ) or ( index > #travelpoints_array ) then
|
||||
meta:set_string("title", "")
|
||||
meta:set_string("destination", "")
|
||||
meta:set_int("tp_index", 1)
|
||||
meta:set_string("travelpoints_array", "return { }")
|
||||
else
|
||||
meta:set_string("title", title)
|
||||
meta:set_string("destination", destination)
|
||||
meta:set_int("tp_index", index)
|
||||
meta:set_string("travelpoints_array", "return { }")
|
||||
end
|
||||
|
||||
-- Save modification timestamp.
|
||||
meta:set_int("modstamp", os.time())
|
||||
|
||||
-- Save formspec.
|
||||
meta:set_string("formspec", travelpoints.get_formspec(meta))
|
||||
|
||||
-- Save infotext.
|
||||
meta:set_string("infotext", travelpoints.get_infotext(meta))
|
||||
|
||||
else
|
||||
|
||||
-- Report
|
||||
travelpoints.print_notice(name, "Error: You can not set the transporter pad's location as its destination.")
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------
|
||||
-- Handle player addition.
|
||||
--------------------------------------------------------------------
|
||||
|
||||
elseif ( fields.add_player == "Add Player" ) and ( string.len(fields.player_name) > 0 ) and ( name == owner) then
|
||||
|
||||
local player = fields.player_name
|
||||
|
||||
-- Validate input.
|
||||
if not string.find(player, "^[^%w_]+$") then
|
||||
|
||||
-- Owner can't add their name.
|
||||
if player ~= name then
|
||||
|
||||
-- Check if player exists.
|
||||
if travelpoints.player_exists(player) then
|
||||
|
||||
-- Check if player is already in array.
|
||||
if not travelpoints.player_in_players(player, meta:get_string("players")) then
|
||||
|
||||
-- Get players array.
|
||||
local players = minetest.deserialize(meta:get_string("players"))
|
||||
|
||||
-- Add player.
|
||||
table.insert(players, player)
|
||||
|
||||
-- Sort values.
|
||||
if #players > 1 then
|
||||
table.sort(players, function(A, B) return A < B end)
|
||||
end
|
||||
|
||||
-- Save players array.
|
||||
meta:set_string("players", minetest.serialize(players))
|
||||
|
||||
-- Save modification timestamp.
|
||||
meta:set_int("modstamp", os.time())
|
||||
|
||||
-- Save formspec.
|
||||
meta:set_string("formspec", travelpoints.get_formspec(meta))
|
||||
|
||||
else
|
||||
|
||||
-- Report
|
||||
travelpoints.print_notice(name, "Error: \"" .. player .. "\" is already listed.")
|
||||
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
-- Report
|
||||
travelpoints.print_notice(name, "Error: \"" .. player .. "\" is not an existing player for this world.")
|
||||
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
-- Report
|
||||
travelpoints.print_notice(name, "Error: You can't add your own name.")
|
||||
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
-- Report
|
||||
travelpoints.print_notice(name, "Error: The name you entered contains disallowed characters.")
|
||||
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------
|
||||
-- Handle remove player.
|
||||
--------------------------------------------------------------------
|
||||
|
||||
elseif ( fields.remove_player == "Remove Player" ) and ( name == owner ) then
|
||||
|
||||
local player = fields.players
|
||||
|
||||
-- Get players array.
|
||||
local players = minetest.deserialize(meta:get_string("players"))
|
||||
|
||||
local player_removed = false
|
||||
|
||||
-- Step through players to find player.
|
||||
for index, value in ipairs(players) do
|
||||
|
||||
-- Remove player when found.
|
||||
if value == player then
|
||||
table.remove(players, index)
|
||||
player_removed = true
|
||||
break
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-- Check if a player was removed.
|
||||
if player_removed then
|
||||
|
||||
-- Sort values.
|
||||
if #players > 1 then
|
||||
table.sort(players, function(A, B) return A < B end)
|
||||
end
|
||||
|
||||
-- Save players array.
|
||||
meta:set_string("players", minetest.serialize(players))
|
||||
|
||||
-- Save modification timestamp.
|
||||
meta:set_int("modstamp", os.time())
|
||||
|
||||
-- Save formspec.
|
||||
meta:set_string("formspec", travelpoints.get_formspec(meta))
|
||||
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------
|
||||
-- Handle unset button press
|
||||
--------------------------------------------------------------------
|
||||
|
||||
elseif fields.unset_destination == "Unset Destination" then
|
||||
|
||||
-- Clear destination.
|
||||
meta:set_string("title", "")
|
||||
meta:set_string("destination", "")
|
||||
meta:set_int("tp_index", 1)
|
||||
|
||||
-- Save modification timestamp.
|
||||
meta:set_int("modstamp", os.time())
|
||||
|
||||
-- Save formspec.
|
||||
meta:set_string("formspec", travelpoints.get_formspec(meta))
|
||||
|
||||
-- Save infotext.
|
||||
meta:set_string("infotext", travelpoints.get_infotext(meta))
|
||||
|
||||
--------------------------------------------------------------------
|
||||
-- Handle pad access mode and save buttun press or escape key press.
|
||||
--------------------------------------------------------------------
|
||||
|
||||
elseif ( fields.save == "Save" ) or ( fields.quit == "true" ) then
|
||||
|
||||
-- Pad Access Mode
|
||||
if ( name == owner ) then
|
||||
if fields.mode then
|
||||
local mode_table = travelpoints.get_pad_modes("table")
|
||||
meta:set_int("mode_index", mode_table[fields.mode])
|
||||
end
|
||||
end
|
||||
|
||||
-- Save modification timestamp.
|
||||
meta:set_int("modstamp", os.time())
|
||||
|
||||
-- Save formspec.
|
||||
meta:set_string("formspec", travelpoints.get_formspec(meta))
|
||||
|
||||
else
|
||||
travelpoints.print_notice(name, "Only the owner of this pad can modify those fields")
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
-- Report
|
||||
travelpoints.print_notice(name, "This transporter pad belongs to \"" .. owner .. "\", you can not modify it")
|
||||
|
||||
end
|
||||
|
||||
end,
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
-- CAN DIG
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
can_dig = function(pos, player)
|
||||
|
||||
-- Get node's metadata.
|
||||
local meta = minetest.get_meta(pos)
|
||||
|
||||
-- Get player's name.
|
||||
local name = player:get_player_name()
|
||||
|
||||
-- Pads can be dug by their owners or by someone with server privilege.
|
||||
if ( minetest.get_player_privs(name)["server"] ) or ( meta:get_string("owner") == name ) then
|
||||
|
||||
-- Check if travelpad is "offline".
|
||||
if meta:get_string("destination") == "" then
|
||||
return true
|
||||
else
|
||||
travelpoints.print_notice(name, "A transporter pad can not be dug unless its destination is set to \"none\".")
|
||||
return false
|
||||
end
|
||||
|
||||
-- Anyone else.
|
||||
else
|
||||
travelpoints.print_notice(name, "You can not dig a transporter pad you do not own.")
|
||||
return false
|
||||
end
|
||||
|
||||
end,
|
||||
can_dig = travelpoints.can_dig,
|
||||
|
||||
})
|
||||
|
||||
@ -1001,7 +232,7 @@ minetest.register_node("travelpoints:receiver_pad", {
|
||||
|
||||
--[travelpoints:transporter_pad/_active]----------------------------------------------------
|
||||
--
|
||||
-- Swaps active and innactive pad nodes, and sends player to destination.
|
||||
-- Swaps active and inactive pad nodes, and sends player to destination.
|
||||
--
|
||||
minetest.register_abm({
|
||||
nodenames = {"travelpoints:transporter_pad", "travelpoints:transporter_pad_active"},
|
||||
@ -1011,9 +242,19 @@ minetest.register_abm({
|
||||
|
||||
local meta = minetest.get_meta(pos)
|
||||
|
||||
--[Convert old pads to version 1.4]-------------------------------------------------
|
||||
if meta:get_string("version") ~= "1.4" then
|
||||
|
||||
meta:set_string("source", "Mine")
|
||||
meta:set_string("version", "1.4")
|
||||
meta:set_string("tp_array", "return { }")
|
||||
meta:set_int("tp_index", 0)
|
||||
meta:set_string("formspec", travelpoints.get_formspec("", meta))
|
||||
meta:set_string("infotext", travelpoints.get_infotext(meta))
|
||||
|
||||
--[travelpoints:transporter_pad]----------------------------------------------------
|
||||
--
|
||||
if node.name == "travelpoints:transporter_pad" then
|
||||
elseif node.name == "travelpoints:transporter_pad" then
|
||||
|
||||
-- If pad has a destination, swap to active pad.
|
||||
if ( meta:get_string("title") ~= "" ) and ( meta:get_string("destination") ~= "" ) then
|
||||
|
255
readme.txt
255
readme.txt
@ -1,6 +1,6 @@
|
||||
--------------------------------------------------------------------------------
|
||||
--
|
||||
-- Minetest Mod "Travelpoints" Version 1.3 2015-03-24
|
||||
-- Minetest Mod "Travelpoints" Version 1.4 2015-03-27
|
||||
--
|
||||
-- By Racso Rhodes
|
||||
--
|
||||
@ -44,6 +44,15 @@
|
||||
--
|
||||
-- 6.0 /travelpads
|
||||
--
|
||||
-- 7.0 /tpgset <title>
|
||||
-- 7.1 /tpgset <title> <desc>
|
||||
--
|
||||
-- 8.0 /tpggo
|
||||
-- 8.1 /tpggo <title>
|
||||
--
|
||||
-- 9.0 /tpgdrop <title>
|
||||
-- 9.1 /tpgdrop all
|
||||
--
|
||||
-- 06. Nodes
|
||||
--
|
||||
-- 1.0 travelpoints:transporter_pad
|
||||
@ -67,6 +76,61 @@
|
||||
01. Changelog
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
1.4 2015-03-27
|
||||
|
||||
! This version adds global travelpoints as requested by dgm5555.
|
||||
! This version does not break existing travelpoint collections. ABM will
|
||||
automatically update existing transporter pads for formspec changes.
|
||||
+ init.lua - Added privilege "tpglobal".
|
||||
* functions.lua/travelpoints.get_travelpoints_table()
|
||||
Added parameter "mode".
|
||||
Added condition for opening either user's table or the global table.
|
||||
* Updated all calls to travelpoints.get_travelpoints_table().
|
||||
* functions.lua/travelpoints.save_travelpoints_table()
|
||||
Added parameter "mode".
|
||||
Added condition for opening either user's table or the global table.
|
||||
* Updated all calls to travelpoints.save_travelpoints_table().
|
||||
+ init.lua - Added chat command "tpgset".
|
||||
* functions.lua/travelpoints.get_travelpoints_array()
|
||||
Added parameter "mode".
|
||||
Added condition for opening either user's table or the global table.
|
||||
* Updated all calls to travelpoints.get_travelpoints_array().
|
||||
+ init.lua - Added chat command "tpggo".
|
||||
+ init.lua - Added chat command "tpgdrop".
|
||||
* functions.lua/travelpoints.get_formspec()
|
||||
Added parameter "mode".
|
||||
Renamed button "List Travelpoints" to "My Travelpoints".
|
||||
Added button "Global Travelpoints".
|
||||
Removed button "Save" (Saves automatically with each modification.)
|
||||
Added button "Exit".
|
||||
Moved timestamp and modstamp text.
|
||||
Added text for mod version.
|
||||
! Mod now requires at least version 0.4.10 of Minetest for changes
|
||||
in formspec.
|
||||
+ functions.lua/travelpoints.on_destruct()
|
||||
+ functions.lua/travelpoints.after_place_node()
|
||||
+ functions.lua/travelpoints.on_receive_fields()
|
||||
+ functions.lua/travelpoints.can_dig()
|
||||
* nodes.lua
|
||||
Transporter_pad definition now uses shared call backs.
|
||||
Transporter_pad_active definition now uses shared call backs.
|
||||
! Players with "server" privilege can now dig active transporter.
|
||||
* functions.lua/travelpoints.get_infotext() - Removed "Placed by "
|
||||
text, now just shows pad owner's name in parentheses.
|
||||
! Added version and source meta tags to pad nodes.
|
||||
* nodes.lua - ABM now updates old pads for changes in meta data.
|
||||
+ functions.lua/travelpoints.set_pad_destination()
|
||||
* functions.lua/travelpoints.get_travelpoints_array() no longer
|
||||
prepends 'none' to the travelpoints array.
|
||||
* Removed all "- 1" math that compensated for the extra index in the
|
||||
travelpoints array.
|
||||
* init.lua - Chat command "/travelpoints", fixed display for those with
|
||||
server privilege.
|
||||
* readme.txt
|
||||
Rewrote "About Travelpoints" section.
|
||||
Added chat commands "/tpgset", "/tpggo" and "/tpgdrop".
|
||||
Fixed minor errors.
|
||||
|
||||
1.3 2015-03-24
|
||||
|
||||
! This version is preparing the project for GitHub and addressing minor
|
||||
@ -115,16 +179,33 @@
|
||||
02. About Travelpoints
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
This mod is for Minetest 0.4.8 or the latest build.
|
||||
This mod is for Minetest 0.4.10 or later.
|
||||
|
||||
Save world specific bookmarks to locations you travel to as "travelpoints",
|
||||
then easily teleport to those travelpoints.
|
||||
|
||||
You can also create transporter pads whose destination can be set to an
|
||||
existing travelpoint, no need to ever enter coords by hand.
|
||||
|
||||
General Usage
|
||||
Singleplayer
|
||||
|
||||
Save world specific bookmarks to locations you travel to as
|
||||
"travelpoints", then easily teleport to those travelpoints.
|
||||
|
||||
You can also create transporter pads whose destination can be set to an
|
||||
existing travelpoint, no need to ever enter coords by hand.
|
||||
|
||||
While meant for multiplayer servers, the global travelpoints features
|
||||
are available in singleplayer mode.
|
||||
|
||||
Multiplayer
|
||||
|
||||
Each user with the "travelpoints' privilege can set and drop their own
|
||||
collection of travelpoints. This privilege also allows the use of global
|
||||
travelpoints.
|
||||
|
||||
Users with the "tpglobal" privilege can set and drop global
|
||||
travelpoints.
|
||||
|
||||
Users with the "travelpads" privilege can place transporter pads which
|
||||
can be set to one of their own travelpoints or to a global travelpoint.
|
||||
|
||||
Chat Commands
|
||||
|
||||
The travelpoints mod allows you to save world specific, location
|
||||
bookmarks to the places you travel using "/tpset <title>".
|
||||
|
||||
@ -138,29 +219,55 @@
|
||||
If you want to delete an old travelpoint you no longer need, use
|
||||
"/tpdrop <title>".
|
||||
|
||||
Make transporter pads for those travelpoints you use quite often.
|
||||
For setting a global travelpoint, use "/tpgset". For listing and using
|
||||
global travelpoints, use "/tpggo". For dropping a global travelpoint
|
||||
use "/tpgdrop".
|
||||
|
||||
After placing a transporter pad, and right clicking it you can see a
|
||||
list of your existing travelpoints, allowing you to choose one as the
|
||||
destination of the transporter pad.
|
||||
For more commands, and more thorough explanation of the above commands,
|
||||
see section 5 of this file below.
|
||||
|
||||
Transporter Pads
|
||||
|
||||
Transporter pads allow you to fast travel without having to use chat
|
||||
commands. They are useful in large complexes so you can go from one area
|
||||
or floor to another just by walking onto a pad.
|
||||
|
||||
Place a transporter pad where you want it, then right click it. There
|
||||
can sometimes be a moment of lag between the time you place it and when
|
||||
it will let you access its interface.
|
||||
|
||||
Before you can choose a destination for the pad, you must list the
|
||||
available travelpoints. Press "My Travelpoints" to list your own, or
|
||||
press "Global Travelpoints" to list the global collection.
|
||||
|
||||
When the list appears you can then choose a destination for the pad.
|
||||
|
||||
After choosing a destination the list will clear, and the pad will
|
||||
become active.
|
||||
|
||||
You can change the destination any time you need to.
|
||||
|
||||
To list all the transporter pads you have placed use the chat command
|
||||
"/travelpads".
|
||||
|
||||
When playing multiplayer you can also set usage modes, allowing only you
|
||||
to use the transporter pad, anyone to use the pad, you and a list of
|
||||
players, or everyone except a list of players.
|
||||
|
||||
There are also decorative nodes. One is a light that you can place above
|
||||
the transporter pad. As well as a receiving pad which you can place at
|
||||
the destination of a transporter pad with a light above it for show.
|
||||
There are also decorative nodes, one is a receiving pad that you can
|
||||
place at the destination of your transporter pad, the other is a light
|
||||
that can be placed above either your transporter pad or receiving pad.
|
||||
|
||||
For more information about the nodes included in this mod see section 6
|
||||
of this file below.
|
||||
|
||||
For more commands, and more thorough explanation of the above
|
||||
commands, see section 5 of this file below.
|
||||
|
||||
Restrictions
|
||||
|
||||
There are no restrictions in singleplayer mode, but those running
|
||||
multiplayer servers are able to set restrictions in the
|
||||
There are no restrictions in singleplayer mode.
|
||||
|
||||
Admins of multiplayer servers are able to set restrictions in the
|
||||
travelpoints/config.lua file, as well as set world specific restrictions
|
||||
using /travelpoints set <restriction> <value> in game.
|
||||
using "/travelpoints set <restriction> <value>" in game.
|
||||
|
||||
Server administrators can restrict the following features:
|
||||
|
||||
@ -188,7 +295,7 @@
|
||||
03. Install Mod
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
This mod is for Minetest 0.4.8 or the latest build.
|
||||
This mod is for Minetest 0.4.10 or later.
|
||||
|
||||
Extract archive, and rename directory "travelpoints-master" to
|
||||
"travelpoints".
|
||||
@ -230,6 +337,9 @@
|
||||
All player travelpoint tables are serialized and saved in the
|
||||
"travelpoints_tables" directory of the current world as
|
||||
<player_name>.tpt.
|
||||
|
||||
The serialized global travelpoints are saved in the world's root
|
||||
directory as "travelpoints_global.tpt"
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
1.0 /travelpoints
|
||||
@ -240,14 +350,19 @@
|
||||
Provides the player with information about the version of Travelpoints
|
||||
the server is running, with an output like:
|
||||
|
||||
Travelpoints -!- Running Travelpoints version 1.2 released on 2013-12-21.
|
||||
Mutiplayer
|
||||
|
||||
Travelpoints -!- Running Travelpoints version 1.4 released on 2015-03-27.
|
||||
Travelpoints -!- Restrictions:
|
||||
Travelpoints -!- Max Travelpoints: [35] You have: [0]
|
||||
Travelpoints -!- Max Transporter Pads: [25] You have [0]
|
||||
Travelpoints -!- Max Travelpoints: [35] You have: [12]
|
||||
Travelpoints -!- Max Transporter Pads: [25] You have [6]
|
||||
Travelpoints -!- Cooldown: [5 minutes] Your cooldown is: [none]
|
||||
Travelpoints -!- Back Location: [not cleared after use]
|
||||
|
||||
In singleplayer mode the restrictions are not displayed.
|
||||
Singleplayer
|
||||
|
||||
Travelpoints -!- Running Travelpoints version 1.4 released on 2015-03-27.
|
||||
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
1.1 /travelpoints set
|
||||
@ -276,8 +391,7 @@
|
||||
|
||||
Requires "travelpoints" privilege.
|
||||
|
||||
Saves a new travelpoint at the player's current position for the current
|
||||
world.
|
||||
Saves a new travelpoint at the player's position for the current world.
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
2.1 /tpset <title> <desc>
|
||||
@ -285,8 +399,8 @@
|
||||
|
||||
Requires "travelpoints" privilege.
|
||||
|
||||
Saves a new travelpoint at the player's current position with a
|
||||
description for the current world.
|
||||
Saves a new travelpoint at the player's position with a description for
|
||||
the current world.
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
3.0 /tpgo
|
||||
@ -340,6 +454,59 @@
|
||||
|
||||
Lists all the player's placed transporter pads for the current world.
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
7.0 /tpgset <title>
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
Requires "tpglobal" privilege.
|
||||
|
||||
Saves a new global travelpoint at the player's position for the current
|
||||
world.
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
7.1 /tpgset <title> <desc>
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
Requires "tpglobal" privilege.
|
||||
|
||||
Saves a new global travelpoint at the player's position with a
|
||||
description for the current world.
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
8.0 /tpggo
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
Requires "travelpoints" privilege.
|
||||
|
||||
Provides a list of global travelpoints for the current world.
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
8.1 /tpggo <title>
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
Requires "travelpoints" privilege.
|
||||
|
||||
Teleports player to the given global travelpoint.
|
||||
|
||||
Also saves the position the player used the command at for use with the
|
||||
/tpback command.
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
9.0 /tpgdrop <title>
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
Requires "tpglobal" privilege.
|
||||
|
||||
Deletes the specified global travelpoint for the current world.
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
9.1 /tpgdrop all
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
Requires "tpglobal" and "server" privileges.
|
||||
|
||||
Deletes all global travelpoints for the current world.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
06. Nodes
|
||||
--------------------------------------------------------------------------------
|
||||
@ -350,23 +517,29 @@
|
||||
|
||||
Requires "travelpads" privilege to place this node in the world.
|
||||
|
||||
Once placed, the owner can right click it and use the form to set one
|
||||
of their existing travelpoints as the transporter pad's destination.
|
||||
Once placed, the owner can right click it to access the interface where
|
||||
they can set a destination to one of their own travelpoints or to one
|
||||
of the global travelpoints.
|
||||
|
||||
Transporter pads have four usage modes the owner can set:
|
||||
In multiplayer, the transporter pads have four usage modes the owner
|
||||
can set:
|
||||
|
||||
1. "Owner Only"
|
||||
2. "Everyone"
|
||||
3. "Owner and..." (list of players)
|
||||
4. "Everyone except..." (list of players)
|
||||
|
||||
A transporter pad can not be dug if it has a destination set.
|
||||
Only the owner of a transporter pad can modify its settings.
|
||||
|
||||
Only the owner or someone with "server" privilege can unset and dig a
|
||||
transporter pad.
|
||||
|
||||
Since anyone can view a transporter pad's form, the list of travelpoints
|
||||
is automatically cleared each time the transporter pad is modified.
|
||||
The owner of the transporter pad can dig it only if they unset the
|
||||
destination first.
|
||||
|
||||
A player with "server" privilege can dig a transporter_pad whether it
|
||||
has a destination or not.
|
||||
|
||||
Since anyone can view a transporter pad's interface, the list of
|
||||
travelpoints is automatically cleared each time the destination is
|
||||
modified.
|
||||
|
||||
A. Recipe
|
||||
|
||||
@ -411,7 +584,7 @@
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
This is a decorative node. Place it at the destination of a transporter
|
||||
pad act as a receiving pad.
|
||||
pad to act as a receiving pad.
|
||||
|
||||
A. Recipe
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user