73 lines
2.1 KiB
Lua
73 lines
2.1 KiB
Lua
--yl_commons.botm_certificate_issuer = "Parrish"
|
|
--yl_commons.botm_certificate_issuer = "whostand"
|
|
yl_commons.botm_certificate_issuer = "daydream"
|
|
|
|
yl_commons.botm_create_certificate = function(place, description)
|
|
if type(description) ~= "string" then
|
|
return false, "* Description must be a string"
|
|
end
|
|
|
|
local place = tonumber(place)
|
|
if not place or place < 1 or place > 3 then
|
|
return false, "* Place must be a number between 1 and 3"
|
|
end
|
|
|
|
local cert_names = {
|
|
"yl_events:certificate_gold_item",
|
|
"yl_events:certificate_silver_item",
|
|
"yl_events:certificate_bronze_item",
|
|
}
|
|
|
|
description = string.gsub(description, "\\n", "\n")
|
|
|
|
local item = ItemStack(cert_names[place])
|
|
local meta = item:get_meta()
|
|
meta:set_string("_infotext", description)
|
|
|
|
return item, "ok"
|
|
end
|
|
|
|
local function botm_cert_command(name, param)
|
|
if name ~= yl_commons.botm_certificate_issuer then
|
|
return false, "* You can't do this"
|
|
end
|
|
if type(param) ~= "string" then
|
|
return false, "* Needs a string argument"
|
|
end
|
|
|
|
local split_idx = string.find(param, " ")
|
|
if not split_idx then
|
|
return false, "Needs at least 2 parameters: 1|2|3 description"
|
|
end
|
|
local place = param:sub(1, split_idx)
|
|
local description = param:sub(split_idx)
|
|
|
|
local res, msg = yl_commons.botm_create_certificate(place, description)
|
|
if res then
|
|
local item = res
|
|
local player = core.get_player_by_name(name)
|
|
if not player then
|
|
return false, "* can't give items to an offline player"
|
|
end
|
|
|
|
local inv = player:get_inventory()
|
|
if not inv:room_for_item("main", item) then
|
|
return false, "* You must have space in your inv"
|
|
end
|
|
inv:add_item("main", item)
|
|
return true, "* Certificate created"
|
|
else
|
|
return res, msg
|
|
end
|
|
end
|
|
|
|
core.register_chatcommand(
|
|
"create_botm_cert",
|
|
{
|
|
params = "1|2|3 description",
|
|
description = "Create a BOTM certificate",
|
|
privs = { interact = true },
|
|
func = botm_cert_command,
|
|
}
|
|
)
|