When a player joins, I check their rank, get the privileges in that rank, and then check to see if they are missing any privileges. If they are, I attempt to grant them the missing privilege(s). That's where I have a problem. minetest.check_player_privs returns a table of missing privileges, however, if the player were (for example) missing the fast privilege, the table has this entry: "fast". I then try to iterate through the table with a loop and grant each missing privilege, but that seems impossible since I must first get the player privileges, and then do privs.fast = true, raplacing fast with the name of the missing privilege.
How do I do this? Or should I be taking a completely different approach?
Current Code:
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
local privs = minetest.get_player_privs(name) -- get privileges
local has, missing_privs = minetest.check_player_privs(name, servertools.get_rank_privs(servertools.get_player_rank(name))) -- check privs
if missing_privs ~= "" then
for _,i in pairs(missing_privs) do
table.insert(privs, i) -- insert missing priv
minetest.log("action", "After Insertion: "..dump(privs))
end
minetest.chat_send_player(name, "Granting missing rank privileges.")
end
servertools.get_rank_privs, obviously, returns the privileges of the rank in the same formap as minetest.get_player_privs. servertools.get_player_rank gets the rank of a player. Both of these functions have been proven to work, the only problem is granting the missing privileges.