Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- sHelm API by tripl3dogdare
- http://www.youtube.com/user/tripl3dogdare
- What it does: This API works with and improves the MiscPeripherals Smart Helmet peripheral.
- Why: The Smart Helmet is... a hassle. And not very powerful. (At first glance...) This API attempts to improve the
- user experience of programming for the SH, while also adding some useful and powerful functions. (like the ability
- to print a table straight to the SH without some weird workaround crap)
- Have fun creating awesome stuff with the Smart Helmet HUD!
- ]]--
- function attachSender() -- runs through all sides, if it finds a SmallnetSender it attaches it and stops.
- for i = 1,6 do -- defining side names
- if i == 1 then
- side = "left"
- elseif i == 2 then
- side = "back"
- elseif i == 3 then
- side = "right"
- elseif i == 4 then
- side = "front"
- elseif i == 5 then
- side = "top"
- else
- side = "bottom"
- end
- if peripheral.getType(side) == "smNetSender" then -- check if peripheral type is correct, can also come up nil with no errors
- helm = peripheral.wrap(side) -- if found, wraps to name "helm"
- break
- end
- end
- end
- function send(message) -- simpler sending!
- helm.send("smartHelmet",message) -- simplest function of the bunch, just slaps on the message type and sends
- end
- function sendTable(table, delay) -- send a table with ease!
- delay = delay or nil -- just makes delay optional, ignore this
- for i = 1,#table do -- go through the whole table and nothing more
- send(table[i]) -- send just the message from that index
- if delay ~= nil then
- sleep(delay) -- sleep for the set delay if there is one
- end
- end
- end
- function clear() -- clean your Smart Helmet screen in a jiffy!
- for i = 1,5 do -- rotate five times, once for each line on the Smart Helmet display
- send("") -- send an empty message to bump off a single line
- end
- end
- function sendOnTrigger(side, message, delay) -- wait for a redstone input, and send a message then!
- delay = delay or nil -- again, options.
- while true do
- if rs.getInput(side) then -- check for input on specified side
- if delay ~= nil then -- the delay is put in front this time, since you're only sending one thing.
- sleep(delay)
- end
- send(message) -- send away!
- break -- just so it doesn't keep waiting once it has an input
- else
- sleep(.01) -- just so it doesn't stop waiting before it actually gets an input
- end
- end
- end
- function sendTableOnTrigger(side, table, delay, tableDelay) -- fusion of awesomeness! Send tables on a redstone input!
- delay = delay or nil -- once again, options, options, options.
- tableDelay = tableDelay or nil -- this too
- while true do
- if rs.getInput(side) then -- getting repetitive now =P
- if delay ~= nil then
- sleep(delay)
- end
- sendTable(table, tableDelay)
- break
- else
- sleep(.01) -- this kind of function is still pretty impatient, so you kind of need this.
- end
- end
- end
- function clearOnTrigger(side, delay)
- delay = delay or nil
- while true do
- if delay ~= nil then
- sleep(delay)
- end
- if rs.getInput(side) then
- clear()
- break
- else
- sleep(.01)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement