|
|
(22 intermediate revisions by the same user not shown) |
Line 2: |
Line 2: |
| local cargo = mw.ext.cargo | | local cargo = mw.ext.cargo |
|
| |
|
| function p.main(frame) | | function p.a(seed) |
| local prefixes = "" | | math.randomseed(tonumber(seed)) |
| local infixes = ""
| | local count = cargo.query('Characters=C, GeneralData=GD', 'TRIM(COUNT(C._pageName))=Number', {join='C.ObjectID=GD.ObjectID', where='C._pageNamespace="0" AND (NOT GD.ParentObject WITHIN "Wall" AND NOT GD.PlainName LIKE "* door")'})[1]['Number'] |
| local postfixes = ""
| | local offsetin = math.random(0 , tonumber(count)-2) |
| local maxprefix | | local tables = 'Characters=C, GeneralData=GD' |
| local minprefix
| | local fields = 'GD.PlainName=Name, GD._pageName=Page' |
| local maxinfix
| | local args ={join='C._pageName=GD._pageName', where='GD._pageNamespace="0" AND (NOT GD.ParentObject WITHIN "Wall" AND NOT GD.PlainName LIKE "* door")', offset=offsetin,limit = 1} |
| local mininfix
| | local result = cargo.query(tables, fields, args) |
| local maxpostfix
| | if not next(result) then |
| local minpostfix
| | error('?????') |
| local titletemplate
| | end |
| local result = {}
| | return '[[' .. result[1]['Page'] .. '|'.. result[1]['Name'] .. ']]' |
| | |
| --[get cargo row]--
| |
| local tables= 'HeroNames' | |
| local fields= 'Prefixes, MinPrefixAmount, MaxPrefixAmount,Infixes, MinInfixAmount,MaxInfixAmount,Postfixes ,MinPostfixAmount,MaxPostfixAmount,TitleTemplate' | |
| local args= { | |
| where= 'BaseType="Crab"'
| |
| } | |
| result = cargo.query(tables,fields,args) | |
| if not next(result) then | |
| error('no base type of that kind found.')
| |
| end | |
| --[get prefixes array]--
| |
| local resultstring = ''
| |
| resultstring = result[1]['Prefixes']
| |
| local prefixtable= {}
| |
| local i = 1
| |
| for j in string.gmatch(resultstring,"%s*(%w+),?%s*") do
| |
| prefixtable[i] = j
| |
| i= i+1
| |
| end
| |
| --[get infixes array]--
| |
| local resultstring = ''
| |
| resultstring = result[1]['Infixes']
| |
| local infixtable= {}
| |
| local i = 1
| |
| for j in string.gmatch(resultstring,"%s*(%w+),?%s*") do
| |
| infixtable[i] = j
| |
| i= i+1
| |
| end
| |
| --[get postfixes array]--
| |
| local resultstring = ''
| |
| resultstring = result[1]['Postfixes']
| |
| local postfixtable= {}
| |
| local i = 1
| |
| for j in string.gmatch(resultstring,"%s*(%w+),?%s*") do
| |
| postfixtable[i] = j
| |
| i= i+1
| |
| end
| |
| | |
| --[get min/maxprefix stuff]--
| |
| minprefix=result[1]['MinPrefixAmount']
| |
| maxprefix=result[1]['MaxPrefixAmount']
| |
| for i=1,math.random(minprefix,maxprefix) do
| |
| prefixes = prefixes.. prefixtable[math.random(table.getn(prefixtable))]
| |
| end | | end |
|
| |
|
| mininfix=result[1]['MinInfixAmount']
| | function p.getRandomChara(frame) |
| maxinfix=result[1]['MaxInfixAmount']
| | return p.a(frame.args.seed) |
| for i=1,math.random(mininfix,maxinfix) do
| |
| infixes = infixes.. infixtable[math.random(table.getn(infixtable))] | |
| end
| |
| minpostfix=result[1]['MinPostfixAmount']
| |
| maxpostfix=result[1]['MaxPostfixAmount']
| |
| for i=1,math.random(minpostfix,maxpostfix) do
| |
| postfixes = postfixes.. postfixtable[math.random(table.getn(postfixtable))]
| |
| end | | end |
|
| |
|
| --[title template]--
| | function p.test(seed) |
| titletemplate=result[1]['TitleTemplate']
| | return p.a(tostring(seed)) |
| | |
| --[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'), 'crab')
| |
| | |
| return b
| |
| end | | end |
|
| |
| return p | | return p |