Модуль:Prototypes/Роль/Лодаут: различия между версиями
Материал из Space Station 14 Вики
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
Строка 5: | Строка 5: | ||
local gearloadout = mw.loadData("Модуль:IanComradeBot/loadout.json/data") | local gearloadout = mw.loadData("Модуль:IanComradeBot/loadout.json/data") | ||
function p. | function p.main(frame) | ||
local args = frame.args | local args = frame.args | ||
local searchKey = args[1] | local searchKey = args[1] | ||
local | local roleParam = args[2] | ||
if not | if not roleParam then | ||
return '<div class="role">Параметр roleId не указан</div>' | return '<div class="role">Параметр roleId не указан</div>' | ||
end | end | ||
local roleId = "Job" .. roleParam | |||
local results = {} | local results = {} | ||
local role = nil | local role = nil | ||
Строка 21: | Строка 22: | ||
end | end | ||
if not role then | if not role then | ||
return '<div class="role">Роль с id "' .. | return '<div class="role">Роль с id "' .. roleId .. '" не найдена</div>' | ||
end | end | ||
for _, groupId in ipairs(role.groups or {}) do | for _, groupId in ipairs(role.groups or {}) do |
Версия от 20:28, 13 февраля 2025
Для документации этого модуля может быть создана страница Модуль:Prototypes/Роль/Лодаут/doc
local p = {}
local gearRoleLoadout = mw.loadData("Модуль:IanComradeBot/roleLoadout.json/data")
local gearloadoutGroup = mw.loadData("Модуль:IanComradeBot/loadoutGroup.json/data")
local gearloadout = mw.loadData("Модуль:IanComradeBot/loadout.json/data")
function p.main(frame)
local args = frame.args
local searchKey = args[1]
local roleParam = args[2]
if not roleParam then
return '<div class="role">Параметр roleId не указан</div>'
end
local roleId = "Job" .. roleParam
local results = {}
local role = nil
for _, r in ipairs(gearRoleLoadout) do
if r.id == roleId then
role = r
break
end
end
if not role then
return '<div class="role">Роль с id "' .. roleId .. '" не найдена</div>'
end
for _, groupId in ipairs(role.groups or {}) do
local group = nil
for _, g in ipairs(gearloadoutGroup) do
if g.id == groupId then
group = g
break
end
end
if group then
for _, loadoutId in ipairs(group.loadouts or {}) do
local loadout = nil
for _, l in ipairs(gearloadout) do
if l.id == loadoutId then
loadout = l
break
end
end
if loadout and loadout.equipment then
local eqValue = loadout.equipment[searchKey]
if eqValue then
table.insert(results, eqValue)
end
end
end
end
end
local output = {}
for _, eq in ipairs(results) do
table.insert(output, '<div class="role">' .. eq .. '</div>')
end
return table.concat(output, "\n")
end
return p