Module:NameGenerator: Difference between revisions
Jump to navigation
Jump to search
(name gen that isn't crab specific, i hope?) |
No edit summary |
||
Line 3: | Line 3: | ||
function p.main(frame) | function p.main(frame) | ||
local naming = require'Module:Sandbox/User:Illuminatiswag/namegen/NamingTable' | |||
local prefixes = "" | local prefixes = "" | ||
local infixes = "" | local infixes = "" | ||
Line 21: | Line 22: | ||
end | end | ||
prefixtable = naming[style]['Prefixes'] | |||
infixtable = naming[style]['Infixes'] | |||
postfixtable = naming[style]['Postfixes'] | |||
--[get min/maxprefix stuff]-- | --[get min/maxprefix stuff]-- | ||
minprefix= | minprefix=naming[style]['MinPrefixAmount'] | ||
maxprefix= | maxprefix=naming[style]['MaxPrefixAmount'] | ||
for i=1,math.random(minprefix,maxprefix) do | for i=1,math.random(minprefix,maxprefix) do | ||
prefixes = prefixes.. prefixtable[math.random(table.getn(prefixtable))] | prefixes = prefixes.. prefixtable[math.random(table.getn(prefixtable))] | ||
end | end | ||
mininfix= | mininfix=naming[style]['MinInfixAmount'] | ||
maxinfix= | maxinfix=naming[style]['MaxInfixAmount'] | ||
for i=1,math.random(mininfix,maxinfix) do | for i=1,math.random(mininfix,maxinfix) do | ||
infixes = infixes.. infixtable[math.random(table.getn(infixtable))] | infixes = infixes.. infixtable[math.random(table.getn(infixtable))] | ||
end | end | ||
minpostfix= | minpostfix=naming[style]['MinPostfixAmount'] | ||
maxpostfix= | maxpostfix=naming[style]['MaxPostfixAmount'] | ||
for i=1,math.random(minpostfix,maxpostfix) do | for i=1,math.random(minpostfix,maxpostfix) do | ||
postfixes = postfixes.. postfixtable[math.random(table.getn(postfixtable))] | postfixes = postfixes.. postfixtable[math.random(table.getn(postfixtable))] | ||
Line 79: | Line 45: | ||
--[title template]-- | --[title template]-- | ||
titletemplate=result[1]['TitleTemplate'] | -- titletemplate=result[1]['TitleTemplate'] | ||
--[name fitting]-- | --[name fitting]-- | ||
local heroname= ((prefixes..infixes..postfixes):gsub("^%l", string.upper)) | local heroname= ((prefixes..infixes..postfixes):gsub("^%l", string.upper)) | ||
local a = string.gsub(titletemplate,'NAME',tostring(heroname)) | -- local a = string.gsub(titletemplate,'NAME',tostring(heroname)) | ||
local b = string.gsub(a,('BASETYPE'), style) | -- local b = string.gsub(a,('BASETYPE'), style) | ||
local b = heroname | |||
return b | return b |
Revision as of 21:23, 30 May 2022
Documentation for this module may be created at Module:NameGenerator/doc
local p = {}
local cargo = mw.ext.cargo
function p.main(frame)
local naming = require'Module:Sandbox/User:Illuminatiswag/namegen/NamingTable'
local prefixes = ""
local infixes = ""
local postfixes = ""
local maxprefix
local minprefix
local maxinfix
local mininfix
local maxpostfix
local minpostfix
local titletemplate
local result = {}
local seed = frame.args.seed
local style = frame.args.style or 'Qudish'
if seed ~= nil and seed ~= ''then
math.randomseed(seed:gsub("%w",string.byte))
end
prefixtable = naming[style]['Prefixes']
infixtable = naming[style]['Infixes']
postfixtable = naming[style]['Postfixes']
--[get min/maxprefix stuff]--
minprefix=naming[style]['MinPrefixAmount']
maxprefix=naming[style]['MaxPrefixAmount']
for i=1,math.random(minprefix,maxprefix) do
prefixes = prefixes.. prefixtable[math.random(table.getn(prefixtable))]
end
mininfix=naming[style]['MinInfixAmount']
maxinfix=naming[style]['MaxInfixAmount']
for i=1,math.random(mininfix,maxinfix) do
infixes = infixes.. infixtable[math.random(table.getn(infixtable))]
end
minpostfix=naming[style]['MinPostfixAmount']
maxpostfix=naming[style]['MaxPostfixAmount']
for i=1,math.random(minpostfix,maxpostfix) do
postfixes = postfixes.. postfixtable[math.random(table.getn(postfixtable))]
end
--[title template]--
-- titletemplate=result[1]['TitleTemplate']
--[name fitting]--
local heroname= ((prefixes..infixes..postfixes):gsub("^%l", string.upper))
-- local a = string.gsub(titletemplate,'NAME',tostring(heroname))
-- local b = string.gsub(a,('BASETYPE'), style)
local b = heroname
return b
end
function p.a(seed)
math.randomseed(tonumber(seed))
local count = cargo.query('Characters=C, GeneralData=GD', 'TRIM(COUNT(C._pageName))=Number', {join='C.JoinKey=GD.JoinKey', where='C._pageNamespace="0" AND GD.Categories <> "Walls"'})[1]['Number']
local offsetin = math.random(0 , tonumber(count))
local tables = 'Characters=C, GeneralData=GD'
local fields = 'GD.PlainName=Name, GD._pageName=Page'
local args ={join='C._pageName=GD._pageName', where='GD._pageNamespace="0" AND GD.Categories <> "Walls"', offset=offsetin,limit = 1}
local result = cargo.query(tables, fields, args)
if not next(result) then
error('?????')
end
return '[[' .. result[1]['Page'] .. '|'.. result[1]['Name'] .. ']]'
end
function p.getRandomChara(frame)
return p.a(frame.args.seed)
end
function p.test(seed)
return p.a(tostring(seed))
end
return p