Add .coords to send player co-ordinates into chat.

This commit is contained in:
luk3yx 2018-04-16 11:40:05 +12:00
parent 3c29637838
commit e32643e838
1 changed files with 32 additions and 0 deletions

View File

@ -24,6 +24,9 @@ if not channels then channels = {} end
minetest.register_on_connect(function()
localplayer = minetest.localplayer:get_name()
if localplayer == 'singleplayer' then
connected_players[localplayer] = true
end
end)
local player_in_channel = function(v, c)
@ -391,6 +394,35 @@ minetest.register_chatcommand('who', {
end
})
minetest.register_chatcommand('coords', {
params = "[channel]",
description = "Send your co-ordinates to chat.",
func = function(c)
if c == '' then c = channel end
local pos = minetest.localplayer:get_pos()
local x = math.floor(pos.x)
local y = math.floor(pos.y)
local z = math.floor(pos.z)
local msg = "Current Position: " .. x .. ", " .. y .. ", " .. z .. "."
if c == main_channel then
minetest.send_chat_message(msg)
return
end
local players = get_channel_users(c)
if not players then return false, "The channel does not exist!" end
for p = 1, #players do
if connected_players[players[p]] then
messages_sent = messages_sent + 1
minetest.run_server_chatcommand('msg', players[p] .. ' -' .. c ..
'- ' .. msg)
end
end
if messages_sent == 0 then
return false, "The channel is empty!"
end
end
})
-- Override .list_players to make it display all players, not just players
-- visible to the client.
minetest.override_chatcommand('list_players', {