Add chat channels integration

This commit is contained in:
luk3yx 2018-12-30 17:13:39 +13:00
parent 7922212da8
commit 32444fda73
2 changed files with 48 additions and 2 deletions

View File

@ -8,13 +8,24 @@ create HUDs on their own.
## How to use ## How to use
advmarkers introduces four 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.
- `.add_mrkr`: Adds markers. You can either use `.add_mrkr x,y,z Marker name` or `.add_mrkr here 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. - `.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. - `.mrkr_export`: Exports your markers to an advmarkers string. Remember to not modify the text before copying it.
- `.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.
If you die, a marker is automatically added at your death position. If you die, a marker is automatically added at your death position.
## Chat channels integration
advmarkers works with the `.coords` command from chat_channels ([GitHub],
[GitLab]), even without chat channels installed. When someone does `.coords`,
advmarkers temporarily stores this position, and you can set a temporary marker
at the `.coords` position with `.mrkrthere`, or add a permanent marker with
`.add_mrkr there Marker name`.
[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
[GitLab]: https://gitlab.com/luk3yx/minetest-chat_channels

View File

@ -176,6 +176,11 @@ minetest.register_chatcommand('add_mrkr', {
-- Validate the position -- Validate the position
if pos == 'here' then if pos == 'here' then
pos = minetest.localplayer:get_pos() pos = minetest.localplayer:get_pos()
elseif pos == 'there' then
if not advmarkers.last_coords then
return false, 'No-one has used .coords yet!'
end
pos = advmarkers.last_coords
else else
pos = string_to_pos(pos) pos = string_to_pos(pos)
if not pos then if not pos then
@ -269,3 +274,33 @@ minetest.register_chatcommand('mrkr_import', {
end end
end end
}) })
-- Chat channels .coords integration.
-- You do not need to have chat channels installed for this to work.
if not minetest.registered_on_receiving_chat_message then
minetest.registered_on_receiving_chat_message =
minetest.registered_on_receiving_chat_messages
end
table.insert(minetest.registered_on_receiving_chat_message, 1, function(msg)
local s, e = msg:find('Current Position: %-?[0-9]+, %-?[0-9]+, %-?[0-9]+%.')
if s and e then
local pos = string_to_pos(msg:sub(s + 18, e - 1))
if pos then
advmarkers.last_coords = pos
end
end
end)
-- Add '.mrkrthere'
minetest.register_chatcommand('mrkrthere', {
params = '',
description = 'Adds a (temporary) marker at the last ".coords" position.',
func = function(param)
if not advmarkers.last_coords then
return false, 'No-one has used ".coords" yet!'
elseif not advmarkers.set_hud_pos(advmarkers.last_coords) then
return false, 'Error setting the marker!'
end
end
})