bio_api/init.lua
2023-03-23 06:51:02 -04:00

51 lines
No EOL
1.3 KiB
Lua

bio_api = {mods = {}}
function bio_api.update(userobj)
if userobj == nil then return end
if not userobj:is_player() then
return
end
local name = userobj:get_player_name()
local meta = userobj:get_meta()
local bio = meta:get_string("bio")
if bio_api.mods[name] then
for key, value in pairs(bio_api.mods[name]) do
bio = bio.."\n"..value
end
end
local props = {infotext = bio}
userobj:set_properties(props)
end
minetest.register_on_joinplayer(bio_api.update)
function bio_api.set_custom_bio(username,biotext)
local obj = minetest.get_player_by_name(username)
if obj == nil then return end
local meta = obj:get_meta()
meta:set_string("bio", biotext)
bio_api.update(obj)
return true,"Bio updated."
end
function bio_api.set_mod_bio(username,bioname,biotext)
local obj = minetest.get_player_by_name(username)
if obj == nil then return end
if not bio_api.mods[username] then
bio_api.mods[username] = {}
end
bio_api.mods[username][bioname] = biotext
bio_api.update(obj)
end
minetest.register_privilege("bio", {
description = "Can set thair own bio.",
})
minetest.register_chatcommand("set_bio", {
params = "<bio text>",
description = "Set user bio",
privs = {bio=true},
func = bio_api.set_custom_bio
})