Mindfulhacker

mind API

Mar 27th, 2013
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.60 KB | None | 0 0
  1. --[[
  2. This is the mind.api
  3. Created by Mindfulhacker (appleeater)
  4.  
  5. Table Of Contents
  6. -----------------
  7. 1. Commands
  8. 2. Tributes
  9.  
  10. Commands:
  11.  
  12. 1. mind.DeadLock() - Deadlocks The PC disabling CTRL+T.
  13. 2. mind.unDeadLock() - Disables mind.DeadLock() , Enabling CTRL+T.
  14. 3. mind.getRSinputs() - Gets all of the available sides and puts them into a table.
  15. 3. mind.printRSinputs() - Prints the status of the inputs from mind.getRSinputs().
  16. 4. mind.Lock(password) - Locks the terminal, disabling CTRL+T. Replace password with your desired password.
  17. 5. mind.doorLock(side, password) - Locks a door. Replace side with the side your output is. Replace password with your desired password.
  18. 6. mind.getModems() - Gets all of the available modems. Places them in a table.
  19. 7. mind.openAllModems() - Opens all of the available modems found from mind.getModems()
  20. 8. mind.broadcastModems(message) - Broadcasts a message on all open modems. Use mind.openAllModems() first. Replace message with your desired meaage.
  21. 9. mind.sendModems(id, message) - Sends a message to a computer using any open modems using mind.openAllModems.
  22. Replace ID with the desired computer ID. Replace message with desired message.
  23. 10. mind.reciveModem(timeout) - Recives a message from computers sending messages. Replace timeout with the time to wait before quiting.
  24.  
  25. Tributes:
  26.  
  27. The following people have helped me with creating this API:
  28.  
  29. TheOriginalBit
  30. SuicidalSTDz
  31.  
  32. ]]--
  33.  
  34. print("This is a API! Load it using:")
  35. print("os.loadApi(mind)")
  36.  
  37. local RSinputs = {}
  38. local oldpull = os.pullEvent
  39. local m = {}
  40.  
  41. function DeadLock() --Deadlocks the console disabling CTRL+T Syntax: mind.DeadLock()
  42. os.pullEvent = os.pullEventRaw
  43. end
  44.  
  45. function unDeadLock() --Resets the os.pullEvent back to its original state Syntax: mind.unDeadLock()
  46. os.pullEvent = oldpull
  47. end
  48.  
  49. function getRSinputs() --Gets all of the availale sides Syntax: mind.getRSinputs()
  50. for _,side in pairs(rs.getSides()) do
  51. RSinputs[side] = rs.getInput(side)
  52. end
  53. end
  54.  
  55. function printRSinputs() --Prints redstone inputs from getRSinputs Syntax: mind.getRSinputs()
  56. for side, active in pairs(RSinputs) do
  57. write('The '..side..' redstone input is '..(active and 'on' or 'off'))
  58. end
  59. end
  60.  
  61. function Lock( password ) --locks the terminal Syntax: mind.lock(password)
  62. DeadLock()
  63.  
  64. while true do
  65. term.clear()
  66. print("This Terminal Has Been Locked!")
  67. print("Enter Your Password: ")
  68. if read("*") == password then
  69. print("Succsessfully Authenticated!")
  70. unDeadLock()
  71. break
  72. else
  73. print("Password Invalid!")
  74. print("Authentication Failed!")
  75. term.clear()
  76. end
  77. end
  78. end
  79.  
  80. function doorLock( side, password ) --Locks doors Syntax: mind.doorLock(side, password)
  81. Deadlock()
  82. term.clear()
  83. print("Enter Your Password:")
  84. if read("*") == password then
  85. rs.setOutput(side, true)
  86. sleep(3)
  87. rs.setOutput(side, false)
  88. unDeadLock()
  89. term.clear()
  90. else
  91. print("Password Authentication Failed!")
  92. term.clear()
  93. end
  94. end
  95.  
  96. function getModems()
  97. local m = {}
  98. for _, side in pairs(rs.getSides()) do
  99. if peripheral.getType( side ) == 'modem' then
  100. table.insert( m, side )
  101. end
  102. end
  103. return m
  104. end
  105.  
  106. function openAllModems()
  107. for _, side in pairs( getModems() ) do
  108. rednet.open( side )
  109. end
  110. end
  111.  
  112. function broadcastModems( message )
  113. for _, side in pairs( getModems() ) do
  114. rednet.broadcast( message )
  115. end
  116. end
  117.  
  118. function sendModems( id, message, status )
  119. for _, side in pairs( getModems() ) do
  120. rednet.send( id, message, status )
  121. end
  122. end
  123.  
  124. function reciveModem( timeout )
  125. local senderId, message, distance = rednet.receive( timeout )
  126. term.write(message)
  127. end
Advertisement
Add Comment
Please, Sign In to add comment