Chatcommand Not Working..
I'm working on a rank "module" for my servertools mod. Right now, I'm trying to register a few chatcommands, but though they register, they seem unresponsive. I'm pretty sure that all the functions work, except for servertools.set_player_rank, which is below as well.
Chatcommand:
servertools.set_player_rank:
I'm almost sure that all the other functions work. Any help would be appreciated.
Chatcommand:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
minetest.register_chatcommand("rank", {
description = "Set / Get Player Rank.",
params = "/rank <player> <newrank> | player username (returns rank without <newrank>), rank to give player.",
func = function(name, param)
local target, newrank = string.match(param, "^([^ ]+) *(.*)$") -- separate
if servertools.player_can(name, "setrank") then
-- if not newrank, return rank
if target and not newrank then
local rank = servertools.get_player_rank(target)
minetest.chat_send_player(name, target.." is ranked as a "..rank..".")
elseif not newrank and not target then -- if no newrank and target given, return current player rank
local rank = servertools.get_player_rank(name)
return name.." is ranked as a "..rank.."."
elseif newrank and not target then -- if newrank and no target, require target
return "Please enter a valid target username and new rank."
elseif newrank and target then -- if fields available, continue operation
-- if new rank does not exist, return error
if not servertools.set_player_rank(target, newrank) then -- if unsuccessful, return error
return "There was an error while trying to set "..target.."'s rank to "..newrank.."."
else -- else, return success message
return target.."'s rank set to "..newrank.."."
end
else
return "An error occurred while running the command."
end
else -- else, limit functionality
if target and newrank then
local missing
if not servertools.player_can("getrank") then missing = "getrank, setrank" else missing = "setrank" end
return "You don't have the rankPriv to execute this command. (missing: "..missing..")"
elseif not target and newrank then
return "Please enter a target player."
elseif target and not newrank then
if servertools.player_can("getrank") then
return target.." is ranked as a "..servertools.get_player_rank(target).."."
else
return "You don't have the rankPriv to execute this command. (missing: getrank)"
end
elseif not target and not newrank then
return "You are ranked as a "..servertools.get_player_rank(name).."."
end
end
end,
})
servertools.set_player_rank:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
function servertools.set_player_rank(name, newrank)
-- check params
if not minetest.get_player_by_name(name) then
return "Invalid player: "..name
elseif not newrank then
return "New rank field required."
end
local rank_privs = servertools.get_rank_privs(newrank) -- get rank privileges
-- check that rank exists
if not rank_privs or type(rank_privs) ~= "table" then
return "Rank nonexistent."
end
-- update player privileges
if not minetest.set_player_privs(rank_privs) then return false end -- unsuccessful
-- update database
for _,i in ipairs(mem) do
if i.name == name then
i.rank = newrank -- set new rank value
datalib.table.write(modpath.."/rank.db", mem) -- write updated table
end
end
end
I'm almost sure that all the other functions work. Any help would be appreciated.