Fork and convert to server-side mod.
parent
ff994a34f2
commit
05a06cf291
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
# The MIT License (MIT)
|
# The MIT License (MIT)
|
||||||
|
|
||||||
*Copyright © 2018 by luk3yx*
|
*Copyright © 2019 by luk3yx*
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
21
README.md
21
README.md
|
@ -1,20 +1,20 @@
|
||||||
# advmarkers
|
# advmarkers (non-CSM)
|
||||||
|
|
||||||
A marker/waypoint CSM for Minetest, designed for use with the [marker] mod.
|
# Do not release yet, still WIP
|
||||||
|
|
||||||
To display markers, the server currently needs the [marker] mod installed,
|
A marker/waypoint mod for Minetest.
|
||||||
otherwise "command not found" errors will be displayed, as CSMs cannot currently
|
|
||||||
create HUDs on their own.
|
Unlike the [CSM], this mod does not require the [markers] mod to be installed.
|
||||||
|
|
||||||
## How to use
|
## How to use
|
||||||
|
|
||||||
`advmarkers` introduces the following chatcommands:
|
`advmarkers` introduces the following chatcommands:
|
||||||
|
|
||||||
- `.mrkr`: Opens a formspec allowing you to display or delete markers.
|
- `/mrkr`: Opens a formspec allowing you to display or delete markers. If you give this command a parameter (`h`/`here`, `t`/`there` or co-ordinates), it will set your HUD position to those co-ordinates.
|
||||||
- `.add_mrkr`: Adds markers. You can use `.add_mrkr x,y,z Marker name` to add markers. Markers are (currently) cross-server, and adding a marker with (exactly) the same name as another will overwrite the original marker. If you replace `x,y,z` with `here`, the marker will be set to your current position, and replacing it with `there` will set the marker to the last `.coords` position.
|
- `/add_mrkr`: Adds markers. You can use `.add_mrkr x,y,z Marker name` to add markers. Markers are (currently) cross-server, and adding a marker with (exactly) the same name as another will overwrite the original marker. If you replace `x,y,z` with `here`, the marker will be set to your current position, and replacing it with `there` will set the marker to the last `.coords` position.
|
||||||
- `.mrkr_export`: Exports your markers to an advmarkers string. Remember to not modify the text before copying it. You can use `.mrkr_export old` if you want an export string compatible with older versions of advmarkers (it should start with `M` instead of `J`). The old format will probably not work nicely with the planned server-side mod, however.
|
- `/mrkr_export`: Exports your markers to an advmarkers string. Remember to not modify the text before copying it. You can use `.mrkr_export old` if you want an export string compatible with older versions of advmarkers (it should start with `M` instead of `J`). The old format will probably not work nicely with the planned server-side mod, however.
|
||||||
- `.mrkr_import`: Imports your markers from an advmarkers string (`.mrkr_import <advmarkers string>`). Any markers with the same name will not be overwritten, and if they do not have the same co-ordinates, `_` will be appended to the imported one.
|
- `/mrkr_import`: Imports your markers from an advmarkers string (`.mrkr_import <advmarkers string>`). Any markers with the same name will not be overwritten, and if they do not have the same co-ordinates, `_` will be appended to the imported one.
|
||||||
- `.mrkrthere`: Sets a marker at the last `.coords` position.
|
- `/mrkrthere`: Alias for `/mrkr there`.
|
||||||
|
|
||||||
If you die, a marker is automatically added at your death position, and will
|
If you die, a marker is automatically added at your death position, and will
|
||||||
update the last `.coords` position.
|
update the last `.coords` position.
|
||||||
|
@ -27,6 +27,7 @@ advmarkers temporarily stores this position, and you can set a temporary marker
|
||||||
at the `.coords` position with `.mrkrthere`, or add a permanent marker with
|
at the `.coords` position with `.mrkrthere`, or add a permanent marker with
|
||||||
`.add_mrkr there Marker name`.
|
`.add_mrkr there Marker name`.
|
||||||
|
|
||||||
|
[CSM]: https://gitlab.com/luk3yx/minetest-advmarkers-csm
|
||||||
[marker]: https://github.com/Billy-S/kingdoms_game/blob/master/mods/marker
|
[marker]: https://github.com/Billy-S/kingdoms_game/blob/master/mods/marker
|
||||||
[GitHub]: https://github.com/luk3yx/minetest-chat_channels
|
[GitHub]: https://github.com/luk3yx/minetest-chat_channels
|
||||||
[GitLab]: https://gitlab.com/luk3yx/minetest-chat_channels
|
[GitLab]: https://gitlab.com/luk3yx/minetest-chat_channels
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
cloaking?
|
398
init.lua
398
init.lua
|
@ -1,14 +1,15 @@
|
||||||
--
|
--
|
||||||
-- Minetest advmarkers CSM
|
-- Minetest advmarkers mod
|
||||||
--
|
--
|
||||||
-- Needs the https://github.com/Billy-S/kingdoms_game/tree/master/mods/marker
|
-- The advmarkers CSM ported to a server-side mod
|
||||||
-- mod to be able to display HUD elements
|
|
||||||
--
|
--
|
||||||
|
|
||||||
advmarkers = {}
|
advmarkers = {}
|
||||||
|
|
||||||
-- Get the mod storage
|
-- Get the mod storage
|
||||||
local storage = minetest.get_mod_storage()
|
local storage = minetest.get_mod_storage()
|
||||||
|
local hud = {}
|
||||||
|
advmarkers.last_coords = {}
|
||||||
|
|
||||||
-- Convert positions to/from strings
|
-- Convert positions to/from strings
|
||||||
local function pos_to_string(pos)
|
local function pos_to_string(pos)
|
||||||
|
@ -29,53 +30,121 @@ local function string_to_pos(pos)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Get player name or object
|
||||||
|
local get_player_by_name = minetest.get_player_by_name
|
||||||
|
local get_connected_players = minetest.get_connected_players
|
||||||
|
if minetest.get_modpath('cloaking') then
|
||||||
|
get_player_by_name = cloaking.get_player_by_name
|
||||||
|
get_connected_players = cloaking.get_connected_players
|
||||||
|
end
|
||||||
|
|
||||||
|
local function get_player(player, t)
|
||||||
|
local name
|
||||||
|
if type(player) == 'string' then
|
||||||
|
name = player
|
||||||
|
if t ~= 0 then
|
||||||
|
player = get_player_by_name(name)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
name = player:get_player_name()
|
||||||
|
end
|
||||||
|
if t == 0 then
|
||||||
|
return name
|
||||||
|
elseif t == 1 then
|
||||||
|
return player
|
||||||
|
end
|
||||||
|
return name, player
|
||||||
|
end
|
||||||
|
|
||||||
-- Set the HUD position
|
-- Set the HUD position
|
||||||
-- TODO: Make this entirely client-side or allow the command to be changed.
|
function advmarkers.set_hud_pos(player, pos, title)
|
||||||
function advmarkers.set_hud_pos(pos)
|
local name, player = get_player(player)
|
||||||
pos = string_to_pos(pos)
|
pos = string_to_pos(pos)
|
||||||
if not pos then return end
|
if not player or not pos then return end
|
||||||
minetest.run_server_chatcommand('mrkr', tostring(pos.x) .. ' ' ..
|
if not title then
|
||||||
tostring(pos.y) .. ' ' .. tostring(pos.z))
|
title = pos.x .. ', ' .. pos.y .. ', ' .. pos.z
|
||||||
|
end
|
||||||
|
if hud[player] then
|
||||||
|
player:hud_change(hud[player], 'name', title)
|
||||||
|
player:hud_change(hud[player], 'world_pos', pos)
|
||||||
|
else
|
||||||
|
hud[player] = player:hud_add({
|
||||||
|
hud_elem_type = 'waypoint',
|
||||||
|
name = title,
|
||||||
|
text = 'm',
|
||||||
|
number = 0xbf360c,
|
||||||
|
world_pos = pos
|
||||||
|
})
|
||||||
|
end
|
||||||
|
minetest.chat_send_player(name, 'Marker set to ' .. title)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Get and save player storage
|
||||||
|
local function get_storage(name)
|
||||||
|
name = get_player(name, 0)
|
||||||
|
return minetest.deserialize(storage:get_string(name)) or {}
|
||||||
|
end
|
||||||
|
|
||||||
|
local function save_storage(name, data)
|
||||||
|
name = get_player(name, 0)
|
||||||
|
if type(data) == 'table' then
|
||||||
|
data = minetest.serialize(data)
|
||||||
|
end
|
||||||
|
if type(data) ~= 'string' then return end
|
||||||
|
if #data > 0 then
|
||||||
|
storage:set_string(name, data)
|
||||||
|
else
|
||||||
|
storage:set_string(name, '')
|
||||||
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Add a marker
|
-- Add a marker
|
||||||
function advmarkers.set_marker(pos, name)
|
function advmarkers.set_marker(player, pos, name)
|
||||||
pos = pos_to_string(pos)
|
pos = pos_to_string(pos)
|
||||||
if not pos then return end
|
if not pos then return end
|
||||||
storage:set_string('marker-' .. tostring(name), pos)
|
local data = get_storage(player)
|
||||||
return true
|
data['marker-' .. tostring(name)] = pos
|
||||||
|
return save_storage(player, data)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Delete a marker
|
-- Delete a marker
|
||||||
function advmarkers.delete_marker(name)
|
function advmarkers.delete_marker(player, name)
|
||||||
storage:set_string('marker-' .. tostring(name), '')
|
local data = get_storage(player)
|
||||||
|
data['marker-' .. tostring(name)] = nil
|
||||||
|
return save_storage(player, data)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Get a marker
|
-- Get a marker
|
||||||
function advmarkers.get_marker(name)
|
function advmarkers.get_marker(player, name)
|
||||||
return string_to_pos(storage:get_string('marker-' .. tostring(name)))
|
local data = get_storage(player)
|
||||||
|
return string_to_pos(data['marker-' .. tostring(name)])
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Rename a marker and re-interpret the position.
|
-- Rename a marker and re-interpret the position.
|
||||||
function advmarkers.rename_marker(oldname, newname)
|
function advmarkers.rename_marker(player, oldname, newname)
|
||||||
|
player = get_player(player, 0)
|
||||||
oldname, newname = tostring(oldname), tostring(newname)
|
oldname, newname = tostring(oldname), tostring(newname)
|
||||||
local pos = advmarkers.get_marker(oldname)
|
local pos = advmarkers.get_marker(player, oldname)
|
||||||
if not pos or not advmarkers.set_marker(pos, newname) then return end
|
if not pos or not advmarkers.set_marker(player, pos, newname) then
|
||||||
|
return
|
||||||
|
end
|
||||||
if oldname ~= newname then
|
if oldname ~= newname then
|
||||||
advmarkers.delete_marker(oldname)
|
advmarkers.delete_marker(player, oldname)
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Display a marker
|
-- Display a marker
|
||||||
function advmarkers.display_marker(name)
|
function advmarkers.display_marker(player, name)
|
||||||
return advmarkers.set_hud_pos(advmarkers.get_marker(name))
|
return advmarkers.set_hud_pos(player, advmarkers.get_marker(player, name),
|
||||||
|
name)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Export markers
|
-- Export markers
|
||||||
function advmarkers.export(raw)
|
function advmarkers.export(player, raw)
|
||||||
local s = storage:to_table().fields
|
local s = get_storage(player)
|
||||||
if raw == 'M' then
|
if raw == 'M' then
|
||||||
s = minetest.compress(minetest.serialize(s))
|
s = minetest.compress(minetest.serialize(s))
|
||||||
s = 'M' .. minetest.encode_base64(s)
|
s = 'M' .. minetest.encode_base64(s)
|
||||||
|
@ -86,48 +155,47 @@ function advmarkers.export(raw)
|
||||||
return s
|
return s
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Import markers
|
-- Import markers - Note that this won't import strings made by older versions
|
||||||
function advmarkers.import(s)
|
-- of the CSM.
|
||||||
|
function advmarkers.import(player, s)
|
||||||
if type(s) ~= 'table' then
|
if type(s) ~= 'table' then
|
||||||
local ver = s:sub(1, 1)
|
if s:sub(1, 1) ~= 'J' then return end
|
||||||
if ver ~= 'M' and ver ~= 'J' then return end
|
|
||||||
s = minetest.decode_base64(s:sub(2))
|
s = minetest.decode_base64(s:sub(2))
|
||||||
local success, msg = pcall(minetest.decompress, s)
|
local success, msg = pcall(minetest.decompress, s)
|
||||||
if not success then return end
|
if not success then return end
|
||||||
if ver == 'M' then
|
s = minetest.parse_json(msg)
|
||||||
s = minetest.deserialize(msg)
|
|
||||||
else
|
|
||||||
s = minetest.parse_json(msg)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Iterate over markers to preserve existing ones and check for errors.
|
-- Iterate over markers to preserve existing ones and check for errors.
|
||||||
if type(s) == 'table' then
|
if type(s) == 'table' then
|
||||||
|
local data = get_storage(player)
|
||||||
for name, pos in pairs(s) do
|
for name, pos in pairs(s) do
|
||||||
if type(name) == 'string' and type(pos) == 'string' and
|
if type(name) == 'string' and type(pos) == 'string' and
|
||||||
name:sub(1, 7) == 'marker-' and minetest.string_to_pos(pos) and
|
name:sub(1, 7) == 'marker-' and minetest.string_to_pos(pos) and
|
||||||
storage:get_string(name) ~= pos then
|
data[name] ~= pos then
|
||||||
-- Prevent collisions
|
-- Prevent collisions
|
||||||
local c = 0
|
local c = 0
|
||||||
while #storage:get_string(name) > 0 and c < 50 do
|
while data[name] and c < 50 do
|
||||||
name = name .. '_'
|
name = name .. '_'
|
||||||
c = c + 1
|
c = c + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Sanity check
|
-- Sanity check
|
||||||
if c < 50 then
|
if c < 50 then
|
||||||
storage:set_string(name, pos)
|
data[name] = pos
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return true
|
return save_storage(player, data)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Get the markers formspec
|
-- Get the markers formspec
|
||||||
local formspec_list = {}
|
local formspec_list = {}
|
||||||
local selected_name = false
|
local selected_name = {}
|
||||||
function advmarkers.display_formspec()
|
function advmarkers.display_formspec(player)
|
||||||
|
player = get_player(player, 0)
|
||||||
|
if not get_player_by_name(player) then return end
|
||||||
local formspec = 'size[5.25,8]' ..
|
local formspec = 'size[5.25,8]' ..
|
||||||
'label[0,0;Marker list]' ..
|
'label[0,0;Marker list]' ..
|
||||||
'button_exit[0,7.5;1.3125,0.5;display;Display]' ..
|
'button_exit[0,7.5;1.3125,0.5;display;Display]' ..
|
||||||
|
@ -139,29 +207,29 @@ function advmarkers.display_formspec()
|
||||||
-- Iterate over all the markers
|
-- Iterate over all the markers
|
||||||
local id = 0
|
local id = 0
|
||||||
local selected = 1
|
local selected = 1
|
||||||
formspec_list = {}
|
formspec_list[player] = {}
|
||||||
for name, pos in pairs(storage:to_table().fields) do
|
for name, pos in pairs(get_storage(player)) do
|
||||||
if name:sub(1, 7) == 'marker-' then
|
if name:sub(1, 7) == 'marker-' then
|
||||||
id = id + 1
|
id = id + 1
|
||||||
if id > 1 then
|
if id > 1 then
|
||||||
formspec = formspec .. ','
|
formspec = formspec .. ','
|
||||||
end
|
end
|
||||||
name = name:sub(8)
|
name = name:sub(8)
|
||||||
if not selected_name then
|
if not selected_name[player] then
|
||||||
selected_name = name
|
selected_name[player] = name
|
||||||
end
|
end
|
||||||
if name == selected_name then
|
if name == selected_name[player] then
|
||||||
selected = id
|
selected = id
|
||||||
end
|
end
|
||||||
formspec_list[#formspec_list + 1] = name
|
formspec_list[player][#formspec_list[player] + 1] = name
|
||||||
formspec = formspec .. '##' .. minetest.formspec_escape(name)
|
formspec = formspec .. '##' .. minetest.formspec_escape(name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Close the text list and display the selected marker position
|
-- Close the text list and display the selected marker position
|
||||||
formspec = formspec .. ';' .. tostring(selected) .. ']'
|
formspec = formspec .. ';' .. tostring(selected) .. ']'
|
||||||
if selected_name then
|
if selected_name[player] then
|
||||||
local pos = advmarkers.get_marker(selected_name)
|
local pos = advmarkers.get_marker(player, selected_name[player])
|
||||||
if pos then
|
if pos then
|
||||||
pos = minetest.formspec_escape(tostring(pos.x) .. ', ' ..
|
pos = minetest.formspec_escape(tostring(pos.x) .. ', ' ..
|
||||||
tostring(pos.y) .. ', ' .. tostring(pos.z))
|
tostring(pos.y) .. ', ' .. tostring(pos.z))
|
||||||
|
@ -171,45 +239,70 @@ function advmarkers.display_formspec()
|
||||||
else
|
else
|
||||||
-- Draw over the buttons
|
-- Draw over the buttons
|
||||||
formspec = formspec .. 'button_exit[0,7.5;5.25,0.5;quit;Close dialog]' ..
|
formspec = formspec .. 'button_exit[0,7.5;5.25,0.5;quit;Close dialog]' ..
|
||||||
'label[0,6.75;No markers. Add one with ".add_mrkr".]'
|
'label[0,6.75;No markers. Add one with "/add_mrkr".]'
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Display the formspec
|
-- Display the formspec
|
||||||
return minetest.show_formspec('advmarkers-csm', formspec)
|
return minetest.show_formspec(player, 'advmarkers-ssm', formspec)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Get marker position
|
||||||
|
function advmarkers.get_chatcommand_pos(player, pos)
|
||||||
|
local pname = get_player(player, 0)
|
||||||
|
|
||||||
|
-- Validate the position
|
||||||
|
if pos == 'h' or pos == 'here' then
|
||||||
|
pos = get_player(player, 1):get_pos()
|
||||||
|
elseif pos == 't' or pos == 'there' then
|
||||||
|
if not advmarkers.last_coords[pname] then
|
||||||
|
return false, 'No-one has used ".coords" and you have not died!'
|
||||||
|
end
|
||||||
|
pos = advmarkers.last_coords[pname]
|
||||||
|
else
|
||||||
|
pos = string_to_pos(pos)
|
||||||
|
if not pos then
|
||||||
|
return false, 'Invalid position!'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return pos
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Open the markers GUI
|
-- Open the markers GUI
|
||||||
minetest.register_chatcommand('mrkr', {
|
minetest.register_chatcommand('mrkr', {
|
||||||
params = '',
|
params = '',
|
||||||
description = 'Open the advmarkers GUI',
|
description = 'Open the advmarkers GUI',
|
||||||
func = advmarkers.display_formspec
|
func = function(pname, param)
|
||||||
|
if #param:gsub(' ', '') > 0 then
|
||||||
|
local pos, err = advmarkers.get_chatcommand_pos(pname, param)
|
||||||
|
if not pos then
|
||||||
|
return false, err
|
||||||
|
end
|
||||||
|
if not advmarkers.set_hud_pos(pname, pos) then
|
||||||
|
return false, 'Error setting the marker!'
|
||||||
|
end
|
||||||
|
else
|
||||||
|
advmarkers.display_formspec(pname)
|
||||||
|
end
|
||||||
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Add a marker
|
-- Add a marker
|
||||||
minetest.register_chatcommand('add_mrkr', {
|
minetest.register_chatcommand('add_mrkr', {
|
||||||
params = '<pos / "here" / "there"> <name>',
|
params = '<pos / "here" / "there"> <name>',
|
||||||
description = 'Adds a marker.',
|
description = 'Adds a marker.',
|
||||||
func = function(param)
|
func = function(pname, param)
|
||||||
|
-- Get the parameters
|
||||||
local s, e = param:find(' ')
|
local s, e = param:find(' ')
|
||||||
if not s or not e then
|
if not s or not e then
|
||||||
return false, 'Invalid syntax! See .help add_mrkr for more info.'
|
return false, 'Invalid syntax! See /help add_mrkr for more info.'
|
||||||
end
|
end
|
||||||
local pos = param:sub(1, s - 1)
|
local pos = param:sub(1, s - 1)
|
||||||
local name = param:sub(e + 1)
|
local name = param:sub(e + 1)
|
||||||
|
|
||||||
-- Validate the position
|
-- Get the position
|
||||||
if pos == 'here' then
|
local pos, err = advmarkers.get_chatcommand_pos(pname, pos)
|
||||||
pos = minetest.localplayer:get_pos()
|
if not pos then
|
||||||
elseif pos == 'there' then
|
return false, err
|
||||||
if not advmarkers.last_coords then
|
|
||||||
return false, 'No-one has used ".coords" and you have not died!'
|
|
||||||
end
|
|
||||||
pos = advmarkers.last_coords
|
|
||||||
else
|
|
||||||
pos = string_to_pos(pos)
|
|
||||||
if not pos then
|
|
||||||
return false, 'Invalid position!'
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Validate the name
|
-- Validate the name
|
||||||
|
@ -218,34 +311,35 @@ minetest.register_chatcommand('add_mrkr', {
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Set the marker
|
-- Set the marker
|
||||||
return advmarkers.set_marker(pos, name), 'Done!'
|
return advmarkers.set_marker(pname, pos, name), 'Done!'
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Set the HUD
|
-- Set the HUD
|
||||||
minetest.register_on_formspec_input(function(formname, fields)
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||||
|
local pname, player = get_player(player)
|
||||||
if formname == 'advmarkers-ignore' then
|
if formname == 'advmarkers-ignore' then
|
||||||
return true
|
return true
|
||||||
elseif formname ~= 'advmarkers-csm' then
|
elseif formname ~= 'advmarkers-ssm' then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local name = false
|
local name = false
|
||||||
if fields.marker then
|
if fields.marker then
|
||||||
local event = minetest.explode_textlist_event(fields.marker)
|
local event = minetest.explode_textlist_event(fields.marker)
|
||||||
if event.index then
|
if event.index then
|
||||||
name = formspec_list[event.index]
|
name = formspec_list[pname][event.index]
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
name = selected_name
|
name = selected_name[pname]
|
||||||
end
|
end
|
||||||
|
|
||||||
if name then
|
if name then
|
||||||
if fields.display then
|
if fields.display then
|
||||||
if not advmarkers.display_marker(name) then
|
if not advmarkers.display_marker(player, name) then
|
||||||
minetest.display_chat_message('Error displaying marker!')
|
minetest.chat_send_player(pname, 'Error displaying marker!')
|
||||||
end
|
end
|
||||||
elseif fields.rename then
|
elseif fields.rename then
|
||||||
minetest.show_formspec('advmarkers-csm', 'size[6,3]' ..
|
minetest.show_formspec(pname, 'advmarkers-ssm', 'size[6,3]' ..
|
||||||
'label[0.35,0.2;Rename marker]' ..
|
'label[0.35,0.2;Rename marker]' ..
|
||||||
'field[0.3,1.3;6,1;new_name;New name;' ..
|
'field[0.3,1.3;6,1;new_name;New name;' ..
|
||||||
minetest.formspec_escape(name) .. ']' ..
|
minetest.formspec_escape(name) .. ']' ..
|
||||||
|
@ -253,98 +347,81 @@ minetest.register_on_formspec_input(function(formname, fields)
|
||||||
'button[3,2;3,1;rename_confirm;Rename]')
|
'button[3,2;3,1;rename_confirm;Rename]')
|
||||||
elseif fields.rename_confirm then
|
elseif fields.rename_confirm then
|
||||||
if fields.new_name and #fields.new_name > 0 then
|
if fields.new_name and #fields.new_name > 0 then
|
||||||
if advmarkers.rename_marker(name, fields.new_name) then
|
if advmarkers.rename_marker(pname, name, fields.new_name) then
|
||||||
selected_name = fields.new_name
|
selected_name[pname] = fields.new_name
|
||||||
else
|
else
|
||||||
minetest.display_chat_message('Error renaming marker!')
|
minetest.chat_send_player(pname, 'Error renaming marker!')
|
||||||
end
|
end
|
||||||
advmarkers.display_formspec()
|
advmarkers.display_formspec(pname)
|
||||||
else
|
else
|
||||||
minetest.display_chat_message(
|
minetest.chat_send_player(pname,
|
||||||
'Please enter a new name for the marker.'
|
'Please enter a new name for the marker.'
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
elseif fields.teleport then
|
elseif fields.teleport then
|
||||||
minetest.show_formspec('advmarkers-csm', 'size[6,2.2]' ..
|
minetest.show_formspec(pname, 'advmarkers-ssm', 'size[6,2.2]' ..
|
||||||
'label[0.35,0.25;' .. minetest.formspec_escape(
|
'label[0.35,0.25;' .. minetest.formspec_escape(
|
||||||
'Teleport to a marker\n - ' .. name
|
'Teleport to a marker\n - ' .. name
|
||||||
) .. ']' ..
|
) .. ']' ..
|
||||||
'button[0,1.25;2,1;cancel;Cancel]' ..
|
'button[0,1.25;3,1;cancel;Cancel]' ..
|
||||||
'button_exit[2,1.25;1,1;teleport_tpj;/tpj]' ..
|
'button_exit[3,1.25;3,1;teleport_confirm;Teleport]')
|
||||||
'button_exit[3,1.25;1,1;teleport_tpc;/tpc]' ..
|
elseif fields.teleport_confirm then
|
||||||
'button_exit[4,1.25;2,1;teleport_confirm;/teleport]')
|
|
||||||
elseif fields.teleport_tpj then
|
|
||||||
-- Teleport with /tpj
|
|
||||||
local pos = advmarkers.get_marker(name)
|
|
||||||
if pos and minetest.localplayer then
|
|
||||||
local cpos = minetest.localplayer:get_pos()
|
|
||||||
for _, dir in ipairs({'x', 'y', 'z'}) do
|
|
||||||
local distance = pos[dir] - cpos[dir]
|
|
||||||
minetest.run_server_chatcommand('tpj', dir .. ' ' ..
|
|
||||||
tostring(distance))
|
|
||||||
end
|
|
||||||
else
|
|
||||||
minetest.display_chat_message('Error teleporting to marker!')
|
|
||||||
end
|
|
||||||
elseif fields.teleport_confirm or fields.teleport_tpc then
|
|
||||||
-- Teleport with /teleport
|
-- Teleport with /teleport
|
||||||
local pos = advmarkers.get_marker(name)
|
local pos = advmarkers.get_marker(pname, name)
|
||||||
local cmd
|
if not pos then
|
||||||
if fields.teleport_confirm then
|
minetest.chat_send_player(pname, 'Error teleporting to marker!')
|
||||||
cmd = 'teleport'
|
elseif minetest.check_player_privs(pname, 'teleport') then
|
||||||
|
player:set_pos(pos)
|
||||||
|
minetest.chat_send_player(pname, 'Teleported to marker "' ..
|
||||||
|
name .. '".')
|
||||||
else
|
else
|
||||||
cmd = 'tpc'
|
minetest.chat_send_player(pname, 'Insufficient privileges!')
|
||||||
end
|
|
||||||
if pos and minetest.localplayer then
|
|
||||||
minetest.run_server_chatcommand(cmd,
|
|
||||||
pos.x .. ',' .. pos.y .. ',' .. pos.z)
|
|
||||||
else
|
|
||||||
minetest.display_chat_message('Error teleporting to marker!')
|
|
||||||
end
|
end
|
||||||
elseif fields.delete then
|
elseif fields.delete then
|
||||||
minetest.show_formspec('advmarkers-csm', 'size[6,2]' ..
|
minetest.show_formspec(pname, 'advmarkers-ssm', 'size[6,2]' ..
|
||||||
'label[0.35,0.25;Are you sure you want to delete this marker?]' ..
|
'label[0.35,0.25;Are you sure you want to delete this marker?]' ..
|
||||||
'button[0,1;3,1;cancel;Cancel]' ..
|
'button[0,1;3,1;cancel;Cancel]' ..
|
||||||
'button[3,1;3,1;delete_confirm;Delete]')
|
'button[3,1;3,1;delete_confirm;Delete]')
|
||||||
elseif fields.delete_confirm then
|
elseif fields.delete_confirm then
|
||||||
advmarkers.delete_marker(name)
|
advmarkers.delete_marker(pname, name)
|
||||||
selected_name = false
|
selected_name[pname] = nil
|
||||||
advmarkers.display_formspec()
|
advmarkers.display_formspec(pname)
|
||||||
elseif fields.cancel then
|
elseif fields.cancel then
|
||||||
advmarkers.display_formspec()
|
advmarkers.display_formspec(pname)
|
||||||
elseif name ~= selected_name then
|
elseif name ~= selected_name[pname] then
|
||||||
selected_name = name
|
selected_name[pname] = name
|
||||||
advmarkers.display_formspec()
|
if not fields.quit then
|
||||||
|
advmarkers.display_formspec(pname)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
elseif fields.display or fields.delete then
|
elseif fields.display or fields.delete then
|
||||||
minetest.display_chat_message('Please select a marker.')
|
minetest.chat_send_player(pname, 'Please select a marker.')
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Auto-add markers on death.
|
-- Auto-add markers on death.
|
||||||
minetest.register_on_death(function()
|
minetest.register_on_dieplayer(function(player)
|
||||||
if minetest.localplayer then
|
local name = os.date('Death on %Y-%m-%d %H:%M:%S')
|
||||||
local name = os.date('Death on %Y-%m-%d %H:%M:%S')
|
local pos = player:get_pos()
|
||||||
local pos = minetest.localplayer:get_pos()
|
advmarkers.last_coords[player] = pos
|
||||||
advmarkers.last_coords = pos
|
advmarkers.set_marker(player, pos, name)
|
||||||
advmarkers.set_marker(pos, name)
|
minetest.chat_send_player(player:get_player_name(),
|
||||||
minetest.display_chat_message('Added marker "' .. name .. '".')
|
'Added marker "' .. name .. '".')
|
||||||
end
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Allow string exporting
|
-- Allow string exporting
|
||||||
minetest.register_chatcommand('mrkr_export', {
|
minetest.register_chatcommand('mrkr_export', {
|
||||||
params = '[old]',
|
params = '',
|
||||||
description = 'Exports an advmarkers string containing all your markers.',
|
description = 'Exports an advmarkers string containing all your markers.',
|
||||||
func = function(param)
|
func = function(name, param)
|
||||||
local export
|
local export
|
||||||
if param == 'old' then
|
if param == 'old' then
|
||||||
export = advmarkers.export('M')
|
export = advmarkers.export(name, 'M')
|
||||||
else
|
else
|
||||||
export = advmarkers.export()
|
export = advmarkers.export(name)
|
||||||
end
|
end
|
||||||
minetest.show_formspec('advmarkers-ignore',
|
minetest.show_formspec(name, 'advmarkers-ignore',
|
||||||
'field[_;Your marker export string;' ..
|
'field[_;Your marker export string;' ..
|
||||||
minetest.formspec_escape(export) .. ']')
|
minetest.formspec_escape(export) .. ']')
|
||||||
end
|
end
|
||||||
|
@ -355,8 +432,8 @@ minetest.register_chatcommand('mrkr_import', {
|
||||||
params = '<advmarkers string>',
|
params = '<advmarkers string>',
|
||||||
description = 'Imports an advmarkers string. This will not overwrite ' ..
|
description = 'Imports an advmarkers string. This will not overwrite ' ..
|
||||||
'existing markers that have the same name.',
|
'existing markers that have the same name.',
|
||||||
func = function(param)
|
func = function(name, param)
|
||||||
if advmarkers.import(param) then
|
if advmarkers.import(name, param) then
|
||||||
return true, 'Markers imported!'
|
return true, 'Markers imported!'
|
||||||
else
|
else
|
||||||
return false, 'Invalid advmarkers string!'
|
return false, 'Invalid advmarkers string!'
|
||||||
|
@ -366,30 +443,53 @@ minetest.register_chatcommand('mrkr_import', {
|
||||||
|
|
||||||
-- Chat channels .coords integration.
|
-- Chat channels .coords integration.
|
||||||
-- You do not need to have chat channels installed for this to work.
|
-- You do not need to have chat channels installed for this to work.
|
||||||
if not minetest.registered_on_receiving_chat_message then
|
local function get_coords(msg)
|
||||||
minetest.registered_on_receiving_chat_message =
|
local s, e = msg:find('Current Position: %-?[0-9]+, %-?[0-9]+, %-?[0-9]+%.')
|
||||||
minetest.registered_on_receiving_chat_messages
|
local pos = false
|
||||||
|
if s and e then
|
||||||
|
pos = string_to_pos(msg:sub(s + 18, e - 1))
|
||||||
|
end
|
||||||
|
return pos
|
||||||
end
|
end
|
||||||
|
|
||||||
table.insert(minetest.registered_on_receiving_chat_message, 1, function(msg)
|
-- Get global co-ords
|
||||||
local s, e = msg:find('Current Position: %-?[0-9]+, %-?[0-9]+, %-?[0-9]+%.')
|
table.insert(minetest.registered_on_chat_messages, 1, function(name, msg)
|
||||||
if s and e then
|
local pos = get_coords(msg)
|
||||||
local pos = string_to_pos(msg:sub(s + 18, e - 1))
|
if pos then
|
||||||
if pos then
|
advmarkers.last_coords = {}
|
||||||
advmarkers.last_coords = pos
|
for _, player in ipairs(get_connected_players()) do
|
||||||
|
advmarkers.last_coords[player:get_player_name()] = pos
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Add '.mrkrthere'
|
-- Override chat_send_player to get PMed co-ords etc
|
||||||
minetest.register_chatcommand('mrkrthere', {
|
local old_chat_send_player = minetest.chat_send_player
|
||||||
params = '',
|
function minetest.chat_send_player(name, msg, ...)
|
||||||
description = 'Adds a (temporary) marker at the last ".coords" position.',
|
if type(name) == 'string' and type(msg) == 'string' and
|
||||||
func = function(param)
|
get_player_by_name(name) then
|
||||||
if not advmarkers.last_coords then
|
local pos = get_coords(msg)
|
||||||
return false, 'No-one has used ".coords" and you have not died!'
|
if pos then
|
||||||
elseif not advmarkers.set_hud_pos(advmarkers.last_coords) then
|
advmarkers.last_coords[name] = pos
|
||||||
return false, 'Error setting the marker!'
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
return old_chat_send_player(name, msg, ...)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Clean up variables if a player leaves
|
||||||
|
minetest.register_on_leaveplayer(function(player)
|
||||||
|
local name = get_player(player, 0)
|
||||||
|
hud[name] = nil
|
||||||
|
formspec_list[name] = nil
|
||||||
|
selected_name[name] = nil
|
||||||
|
advmarkers.last_coords[name] = nil
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- Add '/mrkrthere'
|
||||||
|
minetest.register_chatcommand('mrkrthere', {
|
||||||
|
params = '',
|
||||||
|
description = 'Alias for "/mrkr there".',
|
||||||
|
func = function(name, param)
|
||||||
|
return minetest.registered_chatcommands['mrkr'].func(name, 'there')
|
||||||
|
end
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue