Added new waypoint permission and modified chat commands to use them

This commit is contained in:
0siribix 2021-07-09 18:18:17 -05:00
parent e81b225dd0
commit 04d2ce7297

View File

@ -4,6 +4,11 @@ local world_path = minetest.get_worldpath()
local world_name = world_path:match( "([^/]+)$" )
local waypoints = minetest.deserialize(modstorage:get_string(world_name)) or {}
minetest.register_privilege("waypoint", {
description = "Can create server waypoints (visible to everyone)"
})
--------------- HELPER FUNCTIONS ---------------
local function save() -- dumps table to modstorage
modstorage:set_string(world_name, minetest.serialize(waypoints))
@ -142,7 +147,7 @@ end
minetest.register_chatcommand("wc", {
params = "<waypoint_name>",
description = "create a waypoint at current position using a unique name",
privs = {shout = true},
privs = {waypoint = true},
func = function (name, params)
local player = minetest.get_player_by_name(name)
local p_pos = player:get_pos()
@ -165,7 +170,7 @@ minetest.register_chatcommand("wc", {
minetest.register_chatcommand("wd", {
params = "<waypoint_name>",
description = "Delete a waypoint using its name.",
privs = {shout = true},
privs = {waypoint = true},
func = function(name,params)
local player = minetest.get_player_by_name(name)
local targetIndex = getIndexByName(waypoints, params)
@ -185,7 +190,7 @@ minetest.register_chatcommand("wd", {
-- LIST WAYPOINTS
minetest.register_chatcommand("wl", {
params = "",
description = "Lists your waypoints.",
description = "Lists server waypoints.",
privs = {shout = true},
func = function(name)
local player = minetest.get_player_by_name(name)
@ -216,7 +221,7 @@ minetest.register_chatcommand("wt", {
-- SHOW WAYPOINTS FORMSPEC
minetest.register_chatcommand("wf", {
privs = {teleport = true},
privs = {waypoint = true},
func = function(name)
minetest.show_formspec(name, "simple_waypoints:waypoints_formspec", waypoints_formspec.get_main())
end,