Module:GetRandomCreature: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
mNo edit summary |
||
Line 4: | Line 4: | ||
function p.a(seed) | function p.a(seed) | ||
math.randomseed(tonumber(seed)) | math.randomseed(tonumber(seed)) | ||
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"'})[1]['Number'] | 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.ParentObject WITHIN "Door")'})[1]['Number'] | ||
local offsetin = math.random(0 , tonumber(count)-2) | local offsetin = math.random(0 , tonumber(count)-2) | ||
local tables = 'Characters=C, GeneralData=GD' | local tables = 'Characters=C, GeneralData=GD' | ||
local fields = 'GD.PlainName=Name, GD._pageName=Page' | local fields = 'GD.PlainName=Name, GD._pageName=Page' | ||
local args ={join='C._pageName=GD._pageName', where='GD._pageNamespace="0" AND NOT GD.ParentObject WITHIN "Wall"', offset=offsetin,limit = 1} | local args ={join='C._pageName=GD._pageName', where='GD._pageNamespace="0" AND (NOT GD.ParentObject WITHIN "Wall" AND NOT GD.ParentObject WITHIN "Door")', offset=offsetin,limit = 1} | ||
local result = cargo.query(tables, fields, args) | local result = cargo.query(tables, fields, args) | ||
if not next(result) then | if not next(result) then |
Revision as of 00:12, 27 July 2023
Documentation for this module may be created at Module:GetRandomCreature/doc
local p = {}
local cargo = mw.ext.cargo
function p.a(seed)
math.randomseed(tonumber(seed))
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.ParentObject WITHIN "Door")'})[1]['Number']
local offsetin = math.random(0 , tonumber(count)-2)
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 (NOT GD.ParentObject WITHIN "Wall" AND NOT GD.ParentObject WITHIN "Door")', 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