Rodmastercraft

RoDHabilitis

Apr 5th, 2014
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.13 KB | None | 0 0
  1.  
  2. local keyset={}
  3. local n=0
  4. local total = 0
  5.  
  6. local function random(min, max)
  7.        r = math.random(min, max)
  8.        return r
  9. end
  10.  
  11. function calc(prob, maxi)
  12. if type(prob) == "string" or type(maxi) == "string" then
  13.        error("Number expected, got string", 2)
  14.        else
  15.               if maxi then
  16.                      if prob > maxi then
  17.                      error("Prob. higher than "..maxi..". Enter a number at second parameter or decrease the prob. rate.", 2)
  18.                      else
  19.                             prob = tonumber(prob)
  20.                             pr = random(1, maxi)
  21.                             if pr < prob then
  22.                                    return true
  23.                             else
  24.                                    return false
  25.                             end
  26.                      end
  27.               else
  28.                      if prob > 100 then
  29.                             error("Prob. higher than 100. Enter a number at second parameter or decrease the prob. rate.", 2)
  30.                      else
  31.                             prob = tonumber(prob)
  32.                             pr = random(1, 100)
  33.                             if pr < prob then
  34.                                    return true
  35.                             else
  36.                                    return false
  37.                             end
  38.                      end
  39.               end
  40.        end
  41. end
  42.  
  43. function mean(table)
  44. if table == false then
  45. error("no table", 2)
  46. end
  47.        for k,v in pairs(table) do
  48.               n=n+1
  49.               keyset[n]=k
  50.               if type(v) == "string" then
  51.                      error("Number expected, got string (all table keys must be numbers)", 2)
  52.               else
  53.                      total = total + v
  54.                      last = k
  55.               end
  56.        end
  57.        return total/last
  58. end
  59.  
  60. function round(num, idp)
  61.        local mult = 10^(idp or 0)
  62.        return math.floor(num * mult + 0.5) / mult
  63. end
  64.  
  65. function writeFile(file, content, over)
  66.        if over then
  67.               wf = fs.open(file, "w")
  68.               wf.write(content)
  69.               wf.close()
  70.        else
  71.               if fs.exists(file) then
  72.               error("File exists", 2)
  73.               else
  74.                      wf = fs.open(file, "w")
  75.                      wf.write(content)
  76.                      wf.close()
  77.               end
  78.        end
  79. end
  80.  
  81. function readFile(file)
  82.        if not fs.exists(file) then
  83.               error("No such file", 2)
  84.        else
  85.               wf = fs.open(file, "r")
  86.               out = wf.readAll()
  87.               wf.close()
  88.               return out
  89.        end
  90. end
  91.  
  92. function pack(tbl, folder)
  93.        for k, v in pairs(tbl) do
  94.               n = n + 1
  95.               keyset[n]=k
  96.               if not fs.exists(folder) then
  97.                      error("Not directory", 2)
  98.               elseif not fs.exists(v) then
  99.                      errTBL = textutils.serialize(tbl)
  100.                      error("No such file, check table:"..errTBL, 2)
  101.               else
  102.                      print(v)
  103.                      fs.move(v, folder.."/"..v)
  104.               end
  105.        end
  106. end
Advertisement
Add Comment
Please, Sign In to add comment