Module:NameGenerator: Difference between revisions

From Caves of Qud Wiki
Jump to navigation Jump to search
(deleted irrelevant stuff, i think)
No edit summary
Line 22: Line 22:
end
end


prefixtable = naming[style]['Prefixes']
local prefixtable = naming[style]['Prefixes']
infixtable = naming[style]['Infixes']
local infixtable = naming[style]['Infixes']
postfixtable = naming[style]['Postfixes']
local postfixtable = naming[style]['Postfixes']
local hyphenationchance = naming[style]['HyphenationChance'] or 0
local twonameschance = naming[style]['TwoNamesChance'] or 0
local namecount
if math.random(0, 100) < twonameschance then
namecount = 2
else
namecount = 1
end
local heroname = ''
for i = 1,namecount do
--[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


--[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']
--[name fitting]--
maxinfix=naming[style]['MaxInfixAmount']
heroname = heroname .. ((prefixes..infixes..postfixes):gsub("^%l", string.upper))
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
end
--[title template]--
--[title template]--
-- titletemplate=result[1]['TitleTemplate']
-- titletemplate=result[1]['TitleTemplate']
--[name fitting]--
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)

Revision as of 21:45, 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

local prefixtable = naming[style]['Prefixes']
local infixtable = naming[style]['Infixes']
local postfixtable = naming[style]['Postfixes']
local hyphenationchance = naming[style]['HyphenationChance'] or 0
local twonameschance = naming[style]['TwoNamesChance'] or 0
local namecount
if math.random(0, 100) < twonameschance then
 namecount = 2
else
 namecount = 1
end
local heroname = ''
for i = 1,namecount do
 --[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


 --[name fitting]--
 heroname = heroname .. ((prefixes..infixes..postfixes):gsub("^%l", string.upper))
end
--[title template]--
-- titletemplate=result[1]['TitleTemplate']
-- local a = string.gsub(titletemplate,'NAME',tostring(heroname))
-- local b = string.gsub(a,('BASETYPE'), style)
local b = heroname

return b
end

return p