ITS_SELINASOON

BetterTable

Jun 1st, 2022 (edited)
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 30.84 KB | None | 0 0
  1. local module = {}
  2.  
  3. function module.findDupeInTable(T : "Table") : "Table" | boolean
  4.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
  5.     local seen = {}
  6.     local memory = {}
  7.    
  8.     local hasseenarray = false
  9.    
  10.     local returnStatus = false
  11.    
  12.     for i , key in pairs(T) do
  13.         if (seen[key] ~= nil) or (typeof(key) == "table" and hasseenarray == true) then
  14.             module.insert(memory,key)
  15.             continue
  16.         end
  17.        
  18.         if typeof(key) == "table" then
  19.             hasseenarray = true
  20.         end
  21.        
  22.         seen[key] = true
  23.     end
  24.    
  25.     if module.getn(memory) > 0 then
  26.         returnStatus = true
  27.     end
  28.    
  29.     return memory , returnStatus
  30. end
  31.  
  32. function module.findDupeInTableWithFilter(T : "Table" , filter : string) : "Table" | boolean
  33.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
  34.     assert(typeof(filter) == "string","Second argument expected to receive string, got "..typeof(filter).." instead")
  35.    
  36.     local seen = {}
  37.     local memory = {}
  38.     local hasseenarray = false
  39.     local returnStatus = false
  40.    
  41.     for i , key in pairs(T) do
  42.         local keytype = typeof(key)
  43.        
  44.         if keytype == filter then continue end
  45.        
  46.         if (seen[key] ~= nil) or (typeof(key) == "table" and hasseenarray == true) then
  47.             module.insert(memory,key)
  48.             continue
  49.         end
  50.        
  51.         if typeof(key) == "table" then
  52.             hasseenarray = true
  53.         end
  54.        
  55.         seen[key] = true
  56.     end
  57.    
  58.     if module.getn(memory) > 0 then
  59.         returnStatus = true
  60.     end
  61.    
  62.     return memory , returnStatus
  63. end
  64.  
  65. function module.findDupeInTableWithFilterList(T : "Table" , filterList : "table : {|type : string|}") : "Table" | boolean
  66.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
  67.     assert(typeof(filterList) == "table","Second argument expected to receive table, got "..typeof(filterList).." instead")
  68.  
  69.     local seen = {}
  70.     local memory = {}
  71.     local hasseenarray = false
  72.     local returnStatus = false
  73.  
  74.     for i , key in pairs(T) do
  75.         local keytype = typeof(key)
  76.         local noneedtocheck = module.find(filterList,keytype)
  77.        
  78.         if noneedtocheck then continue end     
  79.        
  80.         if (seen[key] ~= nil) or (typeof(key) == "table" and hasseenarray == true) then
  81.             module.insert(memory,key)
  82.             continue
  83.         end
  84.  
  85.         if typeof(key) == "table" then
  86.             hasseenarray = true
  87.         end
  88.  
  89.         seen[key] = true
  90.     end
  91.  
  92.     if module.getn(memory) > 0 then
  93.         returnStatus = true
  94.     end
  95.  
  96.     return memory , returnStatus
  97. end
  98.  
  99. function module.sort(T : "Table")
  100.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T) .. " instead")
  101.    
  102.     local memory = {}
  103.    
  104.     module.foreach(T,function(i,key)
  105.         local keytype = typeof(key)
  106.        
  107.         if keytype == "number" then
  108.             module.movekey(T,memory,i,true)
  109.         end
  110.     end)
  111.    
  112.     table.sort(memory)
  113.    
  114.     module.insertByTable(T,memory)
  115. end
  116.  
  117. function module.concat(T : "Table", Seperate : "string", Start : "number?", End : "number?") : string
  118.     assert(typeof(T) == "table", "First argument expected to receive table, got "..typeof(T) .. " instead")
  119.    
  120.     Start = Start or 1
  121.     End = End or module.getn(T)
  122.     Seperate = Seperate or ""
  123.    
  124.     local concated = nil
  125.    
  126.     local success, errorM = pcall(function()
  127.         concated = table.concat(T,Seperate,Start,End)
  128.     end)
  129.    
  130.     if not errorM then
  131.         errorM = ""
  132.     end
  133.    
  134.     assert(success == true,"Error : failed to concat whole table, table must have contain illegal value. Error message generated from roblox : "..errorM)
  135.    
  136.     return concated
  137. end
  138.  
  139. function module.create(times : "number" , newValue : any , insertTo : "table?") : "return table if insertTo argument were given"
  140.     assert(times ~= nil and newValue ~= nil, "Error : Failed to create table, argument missing")
  141.     assert(newValue ~= nil, "Error : Did you forget put argument 2? or argument 2 is nil or invalid")
  142.     assert(times ~= nil,"Error : Did you forget argument 1? or argument 1 is nil or invalid")
  143.     assert(typeof(times) == "number", "Error : argument 1 given must be number, got "..typeof(times).." instead")
  144.     assert(times > 0, "Error : argument 1 must be more then 0, cannot be 0 or negative number")
  145.    
  146.     insertTo = insertTo or nil
  147.     if insertTo then
  148.         assert(typeof(insertTo) == "table","Error : argument 3 must be table, got "..typeof(insertTo).." instead")
  149.     end
  150.    
  151.     local t = table.create(times,newValue)
  152.    
  153.     if insertTo then
  154.         local memory = {}
  155.        
  156.         local success, message = pcall(function()
  157.             module.foreach(t,function(i,key)
  158.                 module.insert(memory,key)
  159.             end)
  160.         end)
  161.        
  162.         if not message then
  163.             message = ""
  164.         end
  165.        
  166.         assert(success == true, "Error : Failed to insert table, Error message generated from roblox : "..message)
  167.        
  168.         local success, message = pcall(function()
  169.             module.foreach(memory,function(i,key)
  170.                 module.insert(insertTo,key)
  171.             end)
  172.         end)
  173.        
  174.         if not message then
  175.             message = ""
  176.         end
  177.        
  178.         assert(success == true, "Error : An error occured while module in inserting value into table[argument 3], Error message generated from roblox : "..message)
  179.        
  180.         return "Created table has been inserted to another table, this message is suppose to be 'nil' but module script has returned this message instead of getting nil in the output"
  181.     else
  182.         return t
  183.     end
  184. end
  185.  
  186. function module.clone(T : "Table") : "Table"
  187.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
  188.     return table.clone(T)
  189. end
  190.  
  191. function module.find(T : "Table", needle : "Varient", init : "number?") : number
  192.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
  193.     assert(needle ~= nil,"Second arguement expected to received proper argument, got "..typeof(needle).." instead")
  194.    
  195.     init = init or nil
  196.    
  197.     if init then
  198.         assert(typeof(init) == "number" and init > 0, "Thrid argument expected to received number and number must more than 0")
  199.     end
  200.    
  201.     return table.find(T,needle,init)
  202. end
  203.  
  204. function module.freeze(T : "Table") : "Table"
  205.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
  206.    
  207.     if module.isfrozen(T)  then
  208.         warn("table is already frozen, returning table")
  209.         return T
  210.     else
  211.         return table.freeze(T)
  212.     end
  213. end
  214.  
  215. function module.isfrozen(T : "Table") : boolean
  216.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
  217.    
  218.     if table.isfrozen(T) then
  219.         return true
  220.     else
  221.         return false
  222.     end
  223. end
  224.  
  225. function module.deepFreeze(T : "Table") : "Table"
  226.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
  227.    
  228.     if not module.isfrozen(T) then
  229.         module.freeze(T)
  230.     end
  231.    
  232.     module.foreach(T,function(i,key)
  233.         if typeof(key) == "table" then
  234.             if not module.isfrozen(key) then
  235.                 module.freeze(key)
  236.             end
  237.         end
  238.     end)
  239.    
  240.     return T
  241. end
  242.  
  243. function module.getn(T : "table") : number
  244.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
  245.    
  246.     return table.getn(T)
  247. end
  248.  
  249. function module.filterByType(T : "Table" ,typeName : string) : "Table" | boolean
  250.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
  251.     assert(typeName ~= nil or "", "Second argument expected to receive proper string argument, got "..typeName.." or empty string")
  252.    
  253.     local memory = {}
  254.     local boolean = false
  255.    
  256.     module.foreach(T,function(i,key)
  257.         if typeof(key) == typeName then
  258.             module.insert(memory,key)
  259.         end
  260.     end)
  261.    
  262.     if module.getn(memory) > 0 then
  263.         boolean = true
  264.     end
  265.    
  266.     return memory, boolean
  267. end
  268.  
  269. function module.filterByTypeWithTable(T : "table", typeName : "table  : { | string | }") : "Table" | boolean
  270.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
  271.     assert(typeof(typeName) == "table","Second argument expected to receive table, got "..typeof(typeName).." instead")
  272.    
  273.     local memory = {}
  274.     local boolean = false
  275.    
  276.     module.foreach(T,function(i,key)
  277.         module.foreach(typeName,function(ii,typeRequired)
  278.             if typeof(key) == typeRequired then
  279.                 module.insert(memory,key)
  280.             end
  281.         end)
  282.     end)
  283.    
  284.     if module.getn(memory) then
  285.         boolean = true
  286.     end
  287.    
  288.     return memory, boolean
  289. end
  290.  
  291. function module.filterByName(T : "Table", name : string) : "Table" | boolean
  292.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
  293.     assert(name ~= nil or "", "Second argument expected to receive proper string argument, got empty string or "..typeof(name))
  294.    
  295.     local memory = {}
  296.     local boolean = false
  297.    
  298.     module.foreach(T,function(i,key)
  299.         if typeof(key) == "string" and key == name then
  300.             module.insert(memory,key)
  301.         end
  302.     end)
  303.    
  304.     if module.getn(memory) > 0 then
  305.         boolean = true
  306.     end
  307.    
  308.     return memory, boolean
  309. end
  310.  
  311. function module.insert(T : "Table" , key : any)
  312.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
  313.     assert(key ~= nil,"Argument 2 expected to received proper argument, got ".. typeof(key) .. " instead")
  314.    
  315.     table.insert(T,key)
  316. end
  317.  
  318. function module.insertByTable(T : "Table" , tableKey : "Table")
  319.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
  320.     assert(typeof(tableKey) == "table","Argument 2 is expected to received table, got ".. typeof(tableKey) .. " instead")
  321.  
  322.     module.foreach(tableKey,function(i,key)
  323.         module.insert(T,key)
  324.     end)
  325. end
  326.  
  327. function module.clear(T : "Table")
  328.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
  329.    
  330.     table.clear(T)
  331. end
  332.  
  333. function module.removeByTable(T : "Table", list : "Table")
  334.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
  335.     assert(typeof(list) == "table","Second argument expected to receive table, got "..typeof(list).." instead")
  336.    
  337.     module.foreach(list,function(i,key)
  338.         module.remove(T,module.find(T,key))
  339.     end)
  340. end
  341.  
  342. function module.remove(T : "Table", target : number)
  343.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
  344.     assert(typeof(target) == "number","Second argument expected to receive number, got "..typeof(target).." instead")
  345.    
  346.     table.remove(T,target)
  347. end
  348.  
  349. function module.foreach(T : " Table", callback : "function")
  350.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
  351.     assert(typeof(callback) == "function","Second argument expected to receive uncalled-function, got "..typeof(callback).." instead")
  352.    
  353.     table.foreach(T,callback)
  354. end
  355.  
  356. function module.foreachi(T : " Table", callback : "function")
  357.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
  358.     assert(typeof(callback) == "function","Second argument expected to receive uncalled-function, got "..typeof(callback).." instead")
  359.  
  360.     table.foreachi(T,callback)
  361. end
  362.  
  363. function module.pack(... : any) : " (...) -> table"
  364.     return table.pack(...)
  365. end
  366.  
  367. function module.unpack(T : "Table" , i : number , j : number) : "{ | any | } -> tuple"
  368.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
  369.    
  370.     i = i or 1
  371.     j = j or nil
  372.    
  373.     assert(typeof(i) == "number", "Second argument expected to receive number, got "..typeof(i).. " instead")
  374.    
  375.     if typeof(j) ~= "number" then
  376.         if not j == nil then
  377.             error("Thrid argument can be nil or number, got "..typeof(j).." instead")
  378.         end
  379.     end
  380.    
  381.     return table.unpack(T,i,j)
  382. end
  383.  
  384. function module.setDictionary(T : "Table", key : any, value : any)
  385.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
  386.     assert(key ~= nil,"Second argument expected to receive proper argument, got "..typeof(key).." instead")
  387.     assert(value ~= nil,"Thrid argument expected to receive proper argument, got "..typeof(value).." instead")
  388.  
  389.    
  390.     local success, message = pcall(function()
  391.         T[key] = value
  392.     end)
  393.    
  394.     if not message then
  395.         message = ""
  396.     end
  397.    
  398.     assert(success == true, "Failed to set dictionary, error message generated from roblox : "..message)
  399. end
  400.  
  401. function module.getDictionary(T : "Table", key : any) : any
  402.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
  403.     assert(key ~= nil,"Second argument expected to receive proper argument, got "..typeof(key).." instead")
  404.    
  405.     local returnValue = nil
  406.    
  407.     local success, message = pcall(function()
  408.         returnValue = T[key]
  409.     end)
  410.  
  411.     if not message then
  412.         message = ""
  413.     end
  414.  
  415.     assert(success == true, "Failed to return dictionary, error message generated from roblox : "..message)
  416.    
  417.     return returnValue
  418. end
  419.  
  420. function module.move(T1 : "Table1", f : "number", e : "number", t : "number" ,T2 : "Table2") : "Table2"
  421.     assert(typeof(T1) == "table" and typeof(T2) == "table" , "argument 1 and argument 5 are expected to receive table, argument 1 got ".. typeof(T1) .. " and argument 2 got ".. typeof(T2))
  422.     assert(typeof(f) == "number" , "argument 1 must be number, got "..typeof(f).." instead")
  423.     assert(typeof(e) == "number" , "argument 2 must be number, got "..typeof(e).." instead")
  424.     assert(typeof(t) == "number" , "argument 3 must be number, got "..typeof(t).." instead")
  425.    
  426.     local returnTable = nil
  427.    
  428.     local success, message = pcall(function()
  429.         returnTable = table.move(
  430.             T1,
  431.             f,
  432.             e,
  433.             t,
  434.             T2
  435.         )
  436.     end)
  437.    
  438.     if not message then
  439.         message = ""
  440.     end
  441.    
  442.     assert(success == true , "An error occured when moving key to another key, error message generated from roblox : "..message)
  443.    
  444.     return returnTable
  445. end
  446.  
  447. function module.maxn(T : "Table") : number
  448.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
  449.    
  450.     return table.maxn(T)
  451. end
  452.  
  453. function module.selectRandom(T : "Table" , rolltime : "number?" , seed : "number?" ) : "Table"
  454.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
  455.     rolltime = rolltime or 100 
  456.     assert(typeof(rolltime) == "number","Second argument expected to receive number, got"..typeof(rolltime).. " instead")  
  457.     seed = seed or math.random(0,tick())   
  458.     local random = Random.new(seed)
  459.     local chosen = nil
  460.     local last = nil
  461.    
  462.     local function roll()
  463.         chosen = math.floor(random:NextNumber(1,module.getn(T)))
  464.     end
  465.    
  466.     for i = 0,rolltime,1 do
  467.         roll()
  468.        
  469.         last = chosen
  470.     end
  471.    
  472.     return T[chosen]
  473. end
  474.  
  475. function module.findKeyWhichIsAType(T : "Table", typeName : string) : "Table" | boolean
  476.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
  477.     assert(typeof(typeName) == "string","Second argument expected to receive string, got "..typeof(T).." instead")
  478.     assert(typeName ~= "", "Second argument were expected to receive string but the string is empty")
  479.    
  480.     local memory = {}
  481.     local status = false
  482.    
  483.     module.foreach(T,function(i,key)
  484.         if typeof(key) == typeName then
  485.             module.insert(memory,key)
  486.         end
  487.     end)
  488.    
  489.     if module.getn(memory) > 0 then
  490.         status = true
  491.     end
  492.    
  493.     return memory , status
  494. end
  495.  
  496. function module.findKeyWhichIsInTableType(T : "Table" , typeTable : "table : { | type : string | }") : "Table" | boolean
  497.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
  498.     assert(typeof(typeTable) == "table","Second argument expected to receive table with string inside, got "..typeof(typeTable).." instead")
  499.    
  500.     local memory = {}
  501.     local status = false
  502.    
  503.     module.foreach(T,function(i,key)
  504.         module.foreach(typeTable,function(ii,typename)
  505.             if typeof(key) == typename then
  506.                 module.insert(memory,key)
  507.             end
  508.         end)
  509.     end)
  510.    
  511.     if module.getn(memory) > 0 then
  512.         status = true
  513.     end
  514.    
  515.     return memory , status
  516. end
  517.  
  518. function module.clearType(T : "Table" , typeName : string)
  519.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
  520.     assert(typeof(typeName) == "string","Second argument expected to receive string, got "..typeof(T).." instead")
  521.     assert(typeName ~= "", "Second argument were expected to receive string but the string is empty")
  522.    
  523.     local found, didfound = module.findKeyWhichIsAType(T,typeName)
  524.  
  525.     if found and didfound then
  526.         module.remove(T,found)
  527.     end
  528. end
  529.  
  530. function module.clearTypeWithTable(T : "Table", typeInTable : "{ | type : string | }")
  531.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
  532.     assert(typeof(typeInTable) == "table","Second argument expected to receive table, got "..typeof(typeInTable).." instead")
  533.    
  534.     local found, didfound = module.findKeyWhichIsInTableType(T,typeInTable)
  535.    
  536.     if found and didfound then
  537.         module.removeByTable(T,found)
  538.     end
  539. end
  540.  
  541. function module.selectMultipleByRandom(T : "Table", times : number, rolltime : "number?", seed : "number?") : "Table"
  542.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
  543.     assert(typeof(times) == "number","Second argument expected to receive number, got "..typeof(times).." instead")
  544.    
  545.     rolltime = rolltime or 100
  546.    
  547.     assert(typeof(rolltime) == "number","Thrid argument expected to receive number, got "..typeof(rolltime).." instead")
  548.    
  549.     local chosen = nil
  550.     local last = nil
  551.    
  552.     seed = seed or math.random(0,tick())
  553.    
  554.     local returnT = {}
  555.    
  556.     local random = Random.new(seed)
  557.    
  558.     local function Roll()
  559.         chosen = T[math.floor(random:NextNumber(1,module.getn(T)))]
  560.     end
  561.    
  562.     for i = 1,times,1 do
  563.         for i = 0,rolltime,1 do
  564.             Roll()
  565.            
  566.             last = chosen
  567.         end
  568.        
  569.         module.insert(returnT,chosen)
  570.     end
  571.    
  572.     return returnT
  573. end
  574.  
  575. function module.movekey(fromT1 : "Table" , fromT2 : "Table" , n : number , removekeyfromT1 : "boolean?")
  576.     assert(typeof(fromT1) == "table" and typeof(fromT2) == "table" , "First and second argument expected to receive table, first argument got "..typeof(fromT1).." and second argument got "..typeof(fromT2))
  577.     assert(typeof(n) == "number" and n > 0 , "Thrid argument expected to receive number more than 0")
  578.     removekeyfromT1 = removekeyfromT1 or false
  579.     assert(typeof(removekeyfromT1) == "boolean" ,"forth argument expected to receive boolean, got "..typeof(removekeyfromT1).." instead")
  580.    
  581.     local key = fromT1[n]  
  582.    
  583.     module.insert(fromT2,key)
  584.    
  585.     if removekeyfromT1 then
  586.         module.remove(fromT1,n)
  587.     end
  588. end
  589.  
  590. function module.clearExcept(T : "Table" , list : "Table")
  591.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
  592.     assert(typeof(list) == "table","Second argument expected to receive table, got "..typeof(list).." instead")
  593.     local memory = {}
  594.    
  595.     module.foreach(T,function(i,key)
  596.         module.foreach(list,function(ii,listkey)
  597.             local found = module.find(T,listkey)
  598.            
  599.             if found then
  600.                 local real_key = T[found]
  601.                
  602.                 if real_key then
  603.                     module.movekey(T,memory,found,true)
  604.                 end
  605.             end
  606.         end)
  607.     end)
  608.    
  609.     module.clear(T)
  610.    
  611.     module.insertByTable(T,memory)
  612. end
  613.  
  614. function module.clearExceptType(T : "Table" , typename : string)
  615.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
  616.     assert(typeof(typename) == "string" , "Second argument expected to receive string, got "..typeof(typename).." instead")
  617.    
  618.     local memory = {}
  619.    
  620.     local typeFound , didfound = module.findKeyWhichIsAType(T,typename)
  621.    
  622.     if typeFound and didfound then
  623.         module.insertByTable(memory,typeFound)
  624.     end
  625.    
  626.     module.clear(T)
  627.    
  628.     module.insertByTable(T,memory)
  629. end
  630.  
  631. function module.clearExceptTypeWithTable(T : "Table" , typeTable : "{ |type : string| }")
  632.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
  633.     assert(typeof(typeTable) == "table","Second argument expected to receive table, got "..typeof(typeTable).." instead")
  634.    
  635.     local memory = {}
  636.    
  637.     local typeFound , didfound = module.findKeyWhichIsInTableType(T,typeTable)
  638.    
  639.     if typeFound and didfound then
  640.         module.insertByTable(memory,typeFound)
  641.     end
  642.    
  643.     module.clear(T)
  644.    
  645.     module.insertByTable(T,memory)
  646. end
  647.  
  648. function module.getallinstance(T : "Table") : "Table" | boolean
  649.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
  650.    
  651.     local returnStatus = false
  652.     local typeFound , didfound = module.findKeyWhichIsAType(T,"Instance")
  653.    
  654.     if typeFound and didfound  then
  655.         returnStatus = true
  656.     end
  657.    
  658.     return typeFound , returnStatus
  659. end
  660.  
  661. function module.getallnumber(T : "Table") : "Table" | boolean
  662.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
  663.  
  664.     local returnStatus = false
  665.     local typeFound , didfound = module.findKeyWhichIsAType(T,"number")
  666.  
  667.     if typeFound and didfound  then
  668.         returnStatus = true
  669.     end
  670.  
  671.     return typeFound , returnStatus
  672. end
  673.  
  674. function module.getallboolean(T : "Table") : "Table" | boolean
  675.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
  676.  
  677.     local returnStatus = false
  678.     local typeFound , didfound = module.findKeyWhichIsAType(T,"boolean")
  679.  
  680.     if typeFound and didfound  then
  681.         returnStatus = true
  682.     end
  683.  
  684.     return typeFound , returnStatus
  685. end
  686.  
  687. function module.getallstring(T : "Table") : "Table" | boolean
  688.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
  689.  
  690.     local returnStatus = false
  691.     local typeFound , didfound = module.findKeyWhichIsAType(T,"string")
  692.  
  693.     if typeFound and didfound  then
  694.         returnStatus = true
  695.     end
  696.  
  697.     return typeFound , returnStatus
  698. end
  699.  
  700. function module.getallarray(T : "Table") : "Table" | boolean
  701.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
  702.  
  703.     local returnStatus = false
  704.     local typeFound , didfound = module.findKeyWhichIsAType(T,"table")
  705.  
  706.     if typeFound and didfound  then
  707.         returnStatus = true
  708.     end
  709.  
  710.     return typeFound , returnStatus
  711. end
  712.  
  713. function module.getallnumberthatisunderthen(T : "Table" , min : number) : "Table" | boolean
  714.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
  715.     assert(typeof(min) == "number","Second argument expected to receive number, got "..typeof(min).." instead")
  716.  
  717.     local returnStatus = false
  718.     local memory = {}
  719.    
  720.     local typefound , didfound = module.findKeyWhichIsAType(T,"number")
  721.    
  722.     if typefound and didfound then
  723.         module.insertByTable(memory,typefound)
  724.     end
  725.    
  726.     module.foreach(memory,function(i,key)
  727.         if typeof(key) == "number" then
  728.             if key >= min then
  729.                 module.remove(memory,i)
  730.             end
  731.         end
  732.     end)
  733.    
  734.     if module.getn(memory) > 0  then
  735.         returnStatus = true
  736.     end
  737.    
  738.     return memory , returnStatus
  739. end
  740.  
  741. function module.getallnumberthatismorethen(T : "Table" , min : number) : "Table" | boolean
  742.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
  743.     assert(typeof(min) == "number","Second argument expected to receive number, got "..typeof(min).." instead")
  744.    
  745.     local returnStatus = false
  746.     local memory = {}
  747.  
  748.     local typefound , didfound = module.findKeyWhichIsAType(T,"number")
  749.  
  750.     if typefound and didfound then
  751.         module.insertByTable(memory,typefound)
  752.     end
  753.  
  754.     module.foreach(memory,function(i,key)
  755.         if typeof(key) == "number" then
  756.             if key <= min then
  757.                 module.remove(memory,i)
  758.             end
  759.         end
  760.     end)
  761.  
  762.     if module.getn(memory) > 0  then
  763.         returnStatus = true
  764.     end
  765.  
  766.     return memory , returnStatus
  767. end
  768.  
  769. function module.getallnumberthatissameas(T : "Table" , n : number) : "Table" | boolean
  770.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
  771.     assert(typeof(n) == "number","Second argument expected to receive number, got "..typeof(n).." instead")
  772.    
  773.     local returnStatus = false
  774.     local memory = {}
  775.  
  776.     local typefound , didfound = module.findKeyWhichIsAType(T,"number")
  777.  
  778.     module.foreach(typefound,function(i,key)
  779.         if typeof(key) == "number" and key >= n and key <= n then
  780.             module.insert(memory,key)
  781.         end
  782.     end)
  783.  
  784.     if module.getn(memory) > 0  then
  785.         returnStatus = true
  786.     end
  787.  
  788.     return memory , returnStatus
  789. end
  790.  
  791. function module.getallstringiflettermorethen(T : "Table" , n : number) : "Table" | boolean
  792.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
  793.     assert(typeof(n) == "number","Second argument expected to receive number, got "..typeof(n).." instead")
  794.    
  795.     local returnStatus = false
  796.     local memory = {}
  797.    
  798.     local typefound , didfound = module.getallstring(T)
  799.    
  800.     module.foreach(typefound,function(i,key)
  801.         if typeof(key) == "string" then
  802.             local splited = string.len(key)    
  803.            
  804.             if splited > n then
  805.                 module.insert(memory,key)
  806.             end
  807.         end
  808.     end)
  809.    
  810.     if module.getn(memory) > 0 then
  811.         returnStatus = true
  812.     end
  813.    
  814.     return memory , returnStatus
  815. end
  816.  
  817. function module.getallstringifletterunderthen(T : "Table" , n : number) : "Table" | boolean
  818.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
  819.     assert(typeof(n) == "number","Second argument expected to receive number, got "..typeof(n).." instead")
  820.  
  821.     local returnStatus = false
  822.     local memory = {}
  823.  
  824.     local typefound , didfound = module.getallstring(T)
  825.  
  826.     module.foreach(typefound,function(i,key)
  827.         if typeof(key) == "string" then
  828.             local splited = string.len(key)    
  829.  
  830.             if splited < n then
  831.                 module.insert(memory,key)
  832.             end
  833.         end
  834.     end)
  835.  
  836.     if module.getn(memory) > 0 then
  837.         returnStatus = true
  838.     end
  839.  
  840.     return memory , returnStatus
  841. end
  842.  
  843. function module.getallstringiflettersameas(T : "Table" , n : number) : "Table" | boolean
  844.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
  845.     assert(typeof(n) == "number","Second argument expected to receive number, got "..typeof(n).." instead")
  846.  
  847.     local returnStatus = false
  848.     local memory = {}
  849.  
  850.     local typefound , didfound = module.getallstring(T)
  851.  
  852.     module.foreach(typefound,function(i,key)
  853.         if typeof(key) == "string" then
  854.             local splited = string.len(key)    
  855.  
  856.             if splited >= n and splited <= n then
  857.                 module.insert(memory,key)
  858.             end
  859.         end
  860.     end)
  861.  
  862.     if module.getn(memory) > 0 then
  863.         returnStatus = true
  864.     end
  865.  
  866.     return memory , returnStatus
  867. end
  868.  
  869. function module.getalluncalledfunction(T : "Table") : "Table" | boolean
  870.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
  871.    
  872.     local returnStatus = false
  873.    
  874.     local typefound , didfound = module.findKeyWhichIsAType(T,"function")
  875.    
  876.     if module.getn(typefound) > 0 then
  877.         returnStatus = true
  878.     end
  879.    
  880.     return typefound , returnStatus
  881. end
  882.  
  883. function module.callfunction(T : "Table" , n : number) : any
  884.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
  885.     assert(typeof(n) == "number","Second argument expected to receive number, got "..typeof(n).." instead")
  886.    
  887.     return T[n]()
  888. end
  889.  
  890. function module.callfunctionwithwait(T : "Table" , n : number , delayTime : number) : any
  891.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
  892.     assert(typeof(n) == "number","Second argument expected to receive number, got "..typeof(n).." instead")
  893.     assert(typeof(delayTime) == "number","Thrid argument expected to receive number, got"..typeof(delayTime).." instead")
  894.    
  895.     task.wait(delayTime)
  896.    
  897.     return T[n]()
  898. end
  899.  
  900. function module.callallfunction(T : "Table")
  901.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
  902.    
  903.     local typefound , didfound = module.findKeyWhichIsAType(T,"function")
  904.    
  905.     module.foreach(typefound,function(i,key)
  906.         if typeof(key) == "function" then
  907.             module.callfunction(typefound,i)
  908.         end
  909.     end)
  910. end
  911.  
  912. function module.callallfunctionwithwait(T : "Table" , n : number)
  913.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
  914.     assert(typeof(n) == "number","Second argument expected to receive number, got"..typeof(n).." instead")
  915.  
  916.    
  917.     local typefound , didfound = module.findKeyWhichIsAType(T,"function")
  918.  
  919.     for i , key in pairs(typefound) do
  920.         module.callfunctionwithwait(typefound,i,n)
  921.     end
  922. end
  923.  
  924. function module.callmultiplefunction(T : "Table" , list : "Table : {number}") : any
  925.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
  926.     assert(typeof(list) == "table","Second argument expected to receive table, got "..typeof(list).." instead")
  927.    
  928.     local typefound , didfound = module.findKeyWhichIsAType(T,"function")
  929.    
  930.     module.foreach(list,function(i,n)
  931.         module.callfunction(T,n)
  932.     end)
  933. end
  934.  
  935. function module.callmultiplefunctionwithwait(T : "Table" , list : "Table : {number}", delays : number) : any
  936.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
  937.     assert(typeof(list) == "table","Second argument expected to receive table, got "..typeof(list).." instead")
  938.     assert(typeof(delays) == "number","Thrid argument expected to receive number, got"..typeof(delays).." instead")
  939.    
  940.     local typefound , didfound = module.findKeyWhichIsAType(T,"function")
  941.    
  942.     for i , key in pairs(typefound) do
  943.         module.callfunctionwithwait(typefound,i,delays)
  944.     end
  945. end
  946.  
  947. function module.getalltypesintable(T : "Table") : "Table"
  948.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
  949.    
  950.     local memory = {}
  951.    
  952.     module.foreach(T,function(i,key)
  953.         module.insert(memory,typeof(key))
  954.     end)
  955.    
  956.     return memory
  957. end
  958.  
  959. function module.getalltypesintablewithfilter(T : "Table" , filtername : string) : "Table"
  960.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
  961.     assert(typeof(filtername) == "string","Second argument expected to receive string, got"..typeof(filtername).." instead")
  962.    
  963.     local memory = {}
  964.  
  965.     module.foreach(T,function(i,key)
  966.         local keytype = typeof(key)
  967.        
  968.         if keytype ~= filtername then
  969.             module.insert(memory,keytype)
  970.         end
  971.     end)
  972.  
  973.     return memory
  974. end
  975.  
  976. function module.getalltypesintablewithfilterlist(T : "Table" , filterlist : "table : { |type : string| }") : "Table"
  977.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
  978.     assert(typeof(filterlist) == "table","Second argument expected to receive table, got"..typeof(filterlist).." instead")
  979.  
  980.     local memory = {}
  981.  
  982.     module.foreach(T,function(i,key)
  983.         local keytype = typeof(key)
  984.         local isblacklisted = module.find(filterlist,keytype)
  985.        
  986.         if not isblacklisted then
  987.             module.insert(memory,keytype)
  988.         end
  989.     end)
  990.  
  991.     return memory
  992. end
  993.  
  994. function module.limitindex(T : "Table" , n : number) : "Table" | boolean
  995.     assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
  996.     assert(typeof(n) == "number","Second argument expected to receive number, got "..typeof(n).." instead")
  997.    
  998.     local totalI = module.getn(T)
  999.     local status = false
  1000.     local memory = {}
  1001.    
  1002.     if totalI > n then
  1003.         local removeN = (totalI - n)
  1004.        
  1005.         for i = 1,removeN,1 do
  1006.             module.insert(memory,T[i])
  1007.         end
  1008.     end
  1009.    
  1010.     if module.getn(memory) > 0 then
  1011.         status = true
  1012.     end
  1013.    
  1014.     return memory , status
  1015. end
  1016.  
  1017. return module
  1018.  
  1019.  
Add Comment
Please, Sign In to add comment