Advertisement
Wojbie

Swarmstart code

Oct 13th, 2013
3,259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.96 KB | None | 0 0
  1. --Wojbie's Swarm Miner Main Program
  2. --This is a Top Level Overwrite that removed rednet api and coorutine from system
  3. --Also Contains Emergency Beacon that turns of if turtle crashes and drops to shell.
  4. --This should lessen load that turtles make on server by cutting amount of events by half
  5. --Top Level Coorutine Overwrite Downloaded from
  6. --http://www.computercraft.info/forums2/index.php?/topic/14785-a-smaller-top-level-coroutine-override/
  7. --This is part of set of programs
  8. --To get rest of them make instaler Floppy Disk by placing empty disc in disc drive and using pastebin get LXLBZK25 disk/startup
  9.  
  10. --Setting up my globals table -- Mine Table no poking!!
  11. if not _G["wojbieGlobalsTable"] then
  12. _G["wojbieGlobalsTable"]={}
  13. end
  14.  
  15. -- if redner exists preform overwrite and load up beacon
  16. if _G['rednet'] then
  17.  
  18.     local function beacon()
  19.         local channel=15151
  20.         local modem=false
  21.         local pos=false
  22.         local bep=os.startTimer(1)
  23.         local message={["run"]=false,["id"]=os.getComputerID(),["ERROR"]=true}
  24.         local tosend=textutils.serialize(message)
  25.         local function transmit(...) if modem then modem.transmit(...) end end
  26.         for _,i in pairs(redstone.getSides()) do
  27.             if peripheral.isPresent(i) then
  28.                 if peripheral.getType(i)=="modem" then
  29.                     modem=peripheral.wrap(i)
  30.                         if modem["isWireless"] then
  31.                             if modem.isWireless() then
  32.                                 modem.open(channel)
  33.                                 break
  34.                             end
  35.                         else
  36.                             modem.open(channel)
  37.                             break
  38.                         end
  39.                     modem=false
  40.                 end
  41.             end
  42.         end
  43.         while true do
  44.             event={os.pullEventRaw()}
  45.             if event[1]=="timer" then
  46.                 if event[2]==bep then
  47.                     if wojbieGlobalsTable.getTopShellRunningProgram then
  48.                         if wojbieGlobalsTable.getTopShellRunningProgram() then
  49.                             bep=os.startTimer(10)
  50.                         else
  51.                             if not message.pos then local temp temp={gps.locate(2)} message.pos={x=temp[1],y=temp[2],z=temp[3]} tosend=textutils.serialize(message) end
  52.                             transmit(channel,1,tosend)
  53.                             bep=os.startTimer(2)
  54.                         end
  55.                     else
  56.                         bep=os.startTimer(10)
  57.                     end
  58.                 end
  59.             end
  60.         end
  61.     end
  62.  
  63. --top level overwrite start here
  64.     --# this would also cause the shell and rednet routine to stop
  65.     os.startTimer(0)
  66.     coroutine.yield('timer')
  67.  
  68.     os.queueEvent("modem_message")
  69.     local p = _G.printError
  70.     function _G.printError()
  71.         _G.printError = p
  72.         _G['rednet'] = nil
  73.         print("OK")
  74.        
  75.         local ok, err = pcall( function()
  76.             parallel.waitForAny(function() os.run({}, "/rom/programs/shell") end,beacon)
  77.         end )
  78.         -- If the shell errored, let the user read it.
  79.         if not ok then
  80.             printError( err )
  81.         end
  82.         pcall( function()
  83.             term.setCursorBlink( false )
  84.             print( "Press any key to continue" )
  85.             os.pullEvent( "key" )
  86.         end )
  87.         os.shutdown()
  88.     end
  89.        
  90. else -- if not give beacon shell function it needs and act like normal shell startup code
  91.     wojbieGlobalsTable.getTopShellRunningProgram = shell.getRunningProgram
  92.     if turtle then
  93.         shell.run("/swarminer")
  94.     else
  95.         shell.run("/scanner")
  96.     end
  97. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement