Advertisement
electronic_steve

client

Aug 23rd, 2015
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.23 KB | None | 0 0
  1. --client
  2. component     = require('component')
  3. event         = require('event')
  4. robot         = require('robot')
  5. computer      = require('computer')
  6. serialization = require('serialization')
  7. shell         = require("shell")
  8. red           = component.redstone
  9. internet      = component.tunnel
  10. inv           = component.inventory_controller
  11.  
  12. event.shouldInterrupt = function()  return false end
  13. c={
  14.     up=function(X)
  15.         return fix(robot.up,X)
  16.     end,
  17.     down=function(X)
  18.         return fix(robot.down,X)
  19.     end,
  20.     go=function(X)
  21.         return fix(robot.forward,X)
  22.     end,
  23.     back=function(X)
  24.         return fix(robot.back,X)
  25.     end,
  26.     left=function(X)
  27.         return fix(robot.turnLeft,X)
  28.     end,
  29.     right=function(X)
  30.         return fix(robot.turnRight,X)
  31.     end,
  32.     power=function()
  33.         return (computer.energy()/computer.maxEnergy()*100).."% power"
  34.     end,
  35.     suck=function(X)
  36.         local out=false
  37.         for i=1,inv.getInventorySize(3) do
  38.             out=robot.suck()
  39.         end
  40.         return out
  41.     end,
  42.     drop=function(X)
  43.         for i=1,robot.inventorySize() do
  44.             robot.select(i)
  45.             robot.drop()
  46.         end
  47.         return true
  48.     end,
  49.     inf=function(X)
  50.         local out=""
  51.         for i=16*X-15,16*X do
  52.             local item=inv.getStackInInternalSlot(i)
  53.             if item then  out=out..i..":"..item.label.."|"..item.size.."\n" end
  54.         end
  55.         return out
  56.     end,
  57.     use=function(X)
  58.         return fix(robot.use,X)
  59.     end,
  60.     dig=function(X)
  61.         return fix(robot.swing,X)
  62.     end,
  63. }
  64. function smallfix(func)
  65.     local J=0
  66.     while J~=20 do
  67.  
  68.         J=J+1
  69.         local a=func()
  70.         if a then return true end
  71.     end
  72.     return false
  73. end
  74. function fix(func,arg)
  75.     local out
  76.     for i=1,arg do
  77.         out=smallfix(func)
  78.         if not out then break end
  79.     end
  80.     return out
  81. end
  82.  
  83. function set_msg(msg)
  84.     internet.send(msg)
  85. end
  86.  
  87.  
  88. function loop()
  89.     local _,_,_,_,_,msg=event.pull("modem_message")
  90.     print("s:"..msg)
  91.     local msg,mult=string.match(msg,"(%a+)"),tonumber(string.match(msg,"(%d+)")) or 1
  92.     if c[msg] then
  93.         local nmsg=tostring(c[msg](mult))
  94.         print("c:"..nmsg)
  95.         set_msg(nmsg)
  96.     else
  97.         print("команда не найдена")
  98.         set_msg("команда не найдена")
  99.     end
  100.  
  101. end
  102.  
  103. function errorhandler(b)
  104.     set_msg("c:ERROR: "..b)
  105.     print("c:ERROR "..b)
  106. end
  107.  
  108. while true do
  109.     a,b=xpcall(loop)
  110.     if not a then errorhandler(b) end --защита от дураков.
  111. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement