Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local keyset={}
- local n=0
- local total = 0
- local function random(min, max)
- r = math.random(min, max)
- return r
- end
- function calc(prob, maxi)
- if type(prob) == "string" or type(maxi) == "string" then
- error("Number expected, got string", 2)
- else
- if maxi then
- if prob > maxi then
- error("Prob. higher than "..maxi..". Enter a number at second parameter or decrease the prob. rate.", 2)
- else
- prob = tonumber(prob)
- pr = random(1, maxi)
- if pr < prob then
- return true
- else
- return false
- end
- end
- else
- if prob > 100 then
- error("Prob. higher than 100. Enter a number at second parameter or decrease the prob. rate.", 2)
- else
- prob = tonumber(prob)
- pr = random(1, 100)
- if pr < prob then
- return true
- else
- return false
- end
- end
- end
- end
- end
- function mean(table)
- if table == false then
- error("no table", 2)
- end
- for k,v in pairs(table) do
- n=n+1
- keyset[n]=k
- if type(v) == "string" then
- error("Number expected, got string (all table keys must be numbers)", 2)
- else
- total = total + v
- last = k
- end
- end
- return total/last
- end
- function round(num, idp)
- local mult = 10^(idp or 0)
- return math.floor(num * mult + 0.5) / mult
- end
- function writeFile(file, content, over)
- if over then
- wf = fs.open(file, "w")
- wf.write(content)
- wf.close()
- else
- if fs.exists(file) then
- error("File exists", 2)
- else
- wf = fs.open(file, "w")
- wf.write(content)
- wf.close()
- end
- end
- end
- function readFile(file)
- if not fs.exists(file) then
- error("No such file", 2)
- else
- wf = fs.open(file, "r")
- out = wf.readAll()
- wf.close()
- return out
- end
- end
- function pack(tbl, folder)
- for k, v in pairs(tbl) do
- n = n + 1
- keyset[n]=k
- if not fs.exists(folder) then
- error("Not directory", 2)
- elseif not fs.exists(v) then
- errTBL = textutils.serialize(tbl)
- error("No such file, check table:"..errTBL, 2)
- else
- print(v)
- fs.move(v, folder.."/"..v)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment