Advertisement
COOLGAMETUBEorginal

[ComputerCraft] CGTmath (API/Program)

Jul 30th, 2015
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.86 KB | None | 0 0
  1. --[[DONT REMOVE THIS NOTICE!!!
  2. Download: pastebin get Sg5rWMqD CGTmath || http://www.pastebin.com/Sg5rWMqD
  3. Copyright ©COOLGAMETUBE
  4. Copyright ©Buschrolle
  5. Copyright ©JcraftxD
  6.  
  7. Release: 30.07.2015
  8.  
  9. EULA:
  10. -I will not share this API whithout this notice!
  11. -I able to modify aCFFnd reupload it, if this notice was not removed.
  12. -I will credit COOLGAMETUBE.
  13. -I able to set my Credit, if this Programm has modified(New Functions)
  14. -This API will be FREE (no money)
  15. -If i upload a programm, that include this API, i will set the Credits of COOLGAMETUBE]]
  16.  
  17.  
  18.  
  19. tArgs = {...}
  20.  
  21. local function DrawUsage()
  22.     print("Usage: CGTmath help")
  23.     print("Usage: CGTmath Usage")
  24.     print("Usage: CGTmath GetVersion")
  25.     print("Usage: CGTmath GetAuthor")
  26.     print("Usage: CGTmath MagicClear")
  27.     print("Usage: CGTmath MagicSpam")
  28.     print("Usage: CGTmath digit_sum <number>")
  29.     print("Usage: CGTmath invert <number>")
  30.     print("Usage: CGTmath toInt <string (&) number>")
  31. end
  32.  
  33. function Updates(fromTerm)
  34.     rtMSG = "No more Updates will come! All new Functions will be implemeted in the \"WicowsTools\" API! \n Update: http://pastebin.com/REaZXV7W"
  35.     if fromTerm then
  36.         print(rtMSG)
  37.     else
  38.         return rtMSG
  39.     end
  40. end
  41.  
  42. function GetAuthor()
  43.     return "COOLGAMETUBE"
  44. end
  45.  
  46. function GetVersion()
  47.     return 1.1
  48. end
  49.  
  50. function MagicClear()
  51.     l = {"[", "-", "]", " ", 0.5}
  52.     x, y = term.getSize()
  53.     lt = ""
  54.     ct = ""
  55.     for i = 1, x do
  56.         le = l[2]
  57.         if i == 1 then le = l[1] end
  58.         if i == x then le = l[3] end
  59.         lt = lt .. le
  60.         ct = ct .. l[4]
  61.     end
  62.     for i = 1, y do
  63.         term.setCursorPos(1, i -1)
  64.         write(ct)
  65.         term.setCursorPos(1, i)
  66.         write(lt)
  67.         sleep(l[5])
  68.     end
  69.     shell.run("clear")
  70. end
  71.  
  72. function MagicSpam()
  73.     s = 0.1
  74.     x, y = term.getSize()
  75.     lt = ""
  76.     scnd = true
  77.     for i = 1, y do
  78.         for i = 1, x do
  79.             lt = lt .. tostring(math.random(0,9))
  80.         end
  81.         term.setCursorPos(1, i)
  82.         write(lt)
  83.         if scnd then
  84.             sleep(s)
  85.             scnd = false
  86.         else
  87.             scnd = true
  88.         end
  89.     end
  90.     term.setCursorPos(1,y)
  91. end
  92.  
  93. function toInt(str)
  94.     num = ""
  95.     for a = 1, string.len(str) do
  96.         l = string.sub(str, a,a)
  97.         if l == "0" or l == "1" or l == "2" or l == "3" or l == "4" or l == "5" or l == "6" or l == "7" or l == "8" or l == "9" then
  98.             num = num .. l
  99.         end
  100.     end
  101.     if num == "" or num == nil then num = 0 end
  102.     return tonumber(num)
  103. end
  104.  
  105. function digit_sum(num)
  106.     num = toInt(num)
  107.     num = tostring(num)
  108.    
  109.     numlet = {}
  110.     if string.len(num) > 1 then
  111.         for a = 1, string.len(num) do
  112.             numlet[a] = string.sub(num, a,a)
  113.         end
  114.     else
  115.         numlet[1] = num
  116.     end
  117.     local result = nil
  118.     if #numlet > 1 then
  119.         local rn = 0
  120.         for i = 1, #numlet do
  121.             rn = rn + toInt(numlet[i])
  122.         end
  123.         result = rn
  124.     else
  125.         result = toInt(numlet[1])
  126.     end
  127.     return result
  128. end
  129.  
  130. function invert(num)
  131.     num = toInt(num)
  132.     num = tostring(num)
  133.     numlet = {}
  134.     if string.len(num) > 1 then
  135.         for a = 1, string.len(num) do
  136.             numlet[a] = string.sub(num, a,a)
  137.         end
  138.     else
  139.         numlet[1] = num
  140.     end
  141.  
  142.     local result = nil
  143.     if #numlet > 1 then
  144.         local rn = ""
  145.         for i = 1, (#numlet) do
  146.             rn = rn..numlet[#numlet-i+1]
  147.         end
  148.         result = rn
  149.     else
  150.         result = numlet[1]
  151.     end
  152.     return result
  153. end
  154.  
  155.     local Ac = #tArgs
  156.     local mnum = 0
  157.     if Ac > 0 then
  158.         local func = tArgs[1]
  159.        
  160.         if Ac > 1 then mnum = tArgs[2] end
  161.         if     func == "help" then DrawUsage()
  162.         elseif func == "Usage" then DrawUsage()
  163.         elseif func == "GetVersion" then GetVersion()
  164.         elseif func == "GetAuthor" then GetAuthor()
  165.         elseif func == "MagicClear" then MagicClear()
  166.         elseif func == "MagicSpam" then MagicSpam()
  167.         elseif func == "digit_sum" then if Ac > 1 then print("Result: "..tostring(digit_sum(mnum))) else DrawUsage() end
  168.         elseif func == "invert" then if Ac > 1 then print("Result: "..tostring(invert(mnum))) else DrawUsage() end
  169.         elseif func == "toInt" then if Ac > 1 then print("Result: "..tostring(toInt(mnum))) else DrawUsage() end
  170.         else
  171.             DrawUsage()
  172.         end
  173.     end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement