Jump to content

Computercraft Creations And Questions


Slit

Recommended Posts

Every few days or so I get questions like "How do I do  [insert request] with computercraft" or "Can you teach me the basics of computercraft?". Sadly I'm not a good teacher, but this is the topic where I'm going to try and help you guys learn some CC as well as give you guys a place to show off your CC based creations.

 

Requesting help:

If you need help with computercraft that's ok keep in mind the more complex your idea, the more in depth you'll need to get into computercraft. To allow me to help you the best please follow this format for asking for help.

Problem:

Problem code (use http://pastebin.com/ if possible):

 

 

 

Starting with CC:

ComputerCraft is a mod that brings real life coding skills into Minecraft (or in this case Tekkit). The mod uses a simple programming language called Lua. The language is a good place to start if you have no programming knowledge at all and just need/want a place to start learning the basics. Along with the core ComputerCraft mod Tekkit has a bunch of other mods that coexist and build off the basic functions of ComputerCraft. These mods range from being able to move things around in chests to reading the in game weather to monitoring Bigreactors to make them even more efficient. To interact with these new addons you'll need to wrap them as a peripheral (like your keyboard or mouse). To do this open the lua prompt by right clicking your computer and typing

lua

in the command line, it should look like this except if you are using Tekkit it will say computercraft 1.5 instead of 1.6

kO4QjGP.png

 

After that press enter to submit your command and the Lua prompt will pop up like this

ZWJI5zg.png

 

Next you will want to wrap your object you are trying to interact with. To do that exit out of the menu by pressing escape and look at where peripheral is in relation to the computer (the object must touch the computer on one of its sides to directly wrap it. For this tutorial I will put my peripheral on the right of my computer. Then go back into the computer by right clicking it and type

<variable name> = peripheral.wrap(<side>)

where <variable name> is whatever you want to name your peripheral and <side> is the side that your peripheral is on so if i wanted to name my peripheral "p" (I'm so creative) and it was on the right i would write

p = peripheral.wrap("right")

If you correctly entered the code and hit enter there will be no error messages and it will look like nothing happened, however now you can use the command

<variable name>.listMethods()

where <variable name> is the name you assigned your peripheral earlier. If the block you wrapped is a valid peripheral it will write a list of functions that you can call by using

<variable name>.<command>

where <command> is one of those functions that was written after you used the listMethods() function.

 

Now the rest is up to your imagination. Almost anything that you can think of can be done with ComputerCraft.

 

 

 

My Projects:

So here is the project that I'm working on. It's a shop system that uses Applied Energistics to supply items and CC to request and manage the shopper part of the transaction. I have a working version of the code, but its very lengthy and its hard to add remove different items. This is my attempt to make it smaller.

MasterTable = {}
PageTables = {}
NumberEntries = 0
ashCount = 0
pTotal = 0
cSide = "left"
directs = "east"
 
clrline = "                                                                                  "
 
function guistart()--Opening GUI.
    clearAll()
    term.setCursorPos(2,9)
    write("Welcome, please insert ash and click the screen.")
    local event = os.pullEvent()
    clearAll()
    checkmoney()
end
 
function checkmoney()--Checks the amount of money in a defined chest.
    chest = peripheral.wrap(cSide)
    chest.condenseItems()
    for i = 1,81 do
        tb = chest.getStackInSlot(i)
        if tb == nil then
        elseif tb.id == 27004 then
                countash = tonumber(tb.qty)
                ashCount = ashCount + countash
                        chest.pushItem(directs,i,64)
        end
    end
end
 
function clearAll()--Clears and resets the screen colors/text.
    term.clear()
    term.setTextColor(colors.black)
    term.setBackgroundColor(colors.white)
    for i=1,27 do
            term.setCursorPos(1,i)
            write(clrline)
    end
    term.setCursorPos(1,1)
end
 
function newline()--Moves cursor to a new line.
local xpos,ypos = term.getCursorPos()
term.setCursorPos(1,ypos + 1)
end
 
function fillorder(id,dmg,qty)--Handles orders over the size of 64.
sleep(1)
    while qty > 64 do
            stack = {id=id,dmg=dmg,qty=64}
            reqitems(stack)
            qty = qty - 64
    end
    if qty < 64 then
            stack = {id=id,dmg=dmg,qty=qty}
            reqitems(stack)
    end
end
 
function reqitems(stack)--Requests items.
    me = peripheral.wrap(meSide)
    me.extractItem(stack,directs)
        stackstr = textutils.serialize(stack)
        print(stackstr)
        rednet.broadcast(stackstr)
        stackstr = {}
end
 
function addSell(itemName,ID,DMG,price,qty)
_G["b"..itemName] = 0
_G["Sell"..itemName] = {itemName=itemName,ID=ID,DMG=DMG,price=price,qty=qty}
table.insert(MasterTable,"Sell"..itemName)
NumberEntries = NumberEntries + 1
end
 
function formatSelling()
entnum = 0
currentTable = 1
persnum = 0
_G["Page"..currentTable] = {}
for _ in pairs(MasterTable) do
persnum = persnum + 1
if entnum == 16 then
entnum = 1
currentTable = currentTable + 1
_G["Page"..currentTable] = {}
end
table.insert(_G["Page"..currentTable],persnum)
entnum = entnum + 1
end
end
 
function printPage(PageNUM)
entnum = 0
term.clear()
term.setCursorPos(1,1)
x,y = term.getSize()
write("-Name------------------Price---------------In cart-")
newline()
for _ in pairs(_G["Page"..PageNUM]) do
entnum = entnum + 1
Page = _G["Page"..PageNUM]
mastnum = textutils.serialize(Page[entnum])
mastvald = textutils.serialize(MasterTable[tonumber(mastnum)])
mastval = string.gsub(mastvald, '"', "")
linewr = _G[mastval]
write(linewr.itemName.." x"..linewr.qty)
prices = "Ash x"..linewr.price
x1,y1 = term.getCursorPos()
cmplen = string.len(prices)
deb = math.floor(x/2)
term.setCursorPos(deb,y1)
write(prices)
deb2 = string.len(_G["b"..linewr.itemName])
term.setCursorPos(x-deb2,y1)
write(_G["b"..linewr.itemName])
newline()
end
term.setCursorPos(1,y-1)
write("------------------------Refund---------------------")
newline()
write("-Previous Page----------BUY IT---------Next Page-")
end
 
--addSell(itemName,ID,DMG,price,qty)
addSell("Diamond Block",57,0,1,1)
addSell("Lapis Block",22,0,1,2)
addSell("Gold Block",41,0,1,1)
addSell("Redstone Block",152,0,1,4)
addSell("Emerald Block",133,0,2,1)
addSell("Glowstone",89,0,1,8)
addSell("Ender Pearl",368,0,1,8)
addSell("Aluminum Block",590,11,1,2)
addSell("Tin Block",928,1,1,4)
addSell("Copper Block",928,0,1,4)
addSell("Yellorium Block",1763,0,1,2)
addSell("Lead Block",928,3,1,4)
addSell("Silver Block",928,2,1,2)
addSell("Leather",334,0,1,4)
addSell("Steel",14239,0,1,8)
addSell("Coal Block",173,0,1,4)
addSell("Singularity",5758,27,16,1)
addSell("Sugarcane",338,0,1,8)
addSell("Wheat",296,0,1,12)
addSell("PArmor Tinker Table",2477,0,10,1)
addSell("PArmor Boots",25030,0,10,1)
addSell("PArmor Legs",25029,0,10,1)
addSell("PArmor Helmet",25027,0,10,1)
addSell("PArmor Chest",25028,0,10,1)
 
 
 
formatSelling()
guistart()
printPage(1)
currentPage = 1
running = true
 
 
while running do
event, side, w, h = os.pullEvent("mouse_click")
if h > 1 and h < 18 then
Page = _G["Page"..currentPage]
mastnum1 = Page[h-1]
mastvald1 = textutils.serialize(MasterTable[tonumber(mastnum1)])
mastval1 = string.gsub(mastvald1, '"', "")
linewr1 = _G[mastval1]
if linewr1 ~= nil and ashCount >= pTotal + linewr1.price then
_G["b"..linewr1.itemName] = _G["b"..linewr1.itemName] + 1
pTotal = pTotal + linewr1.price
end
printPage(currentPage)
elseif h == 19 and w > 40 then
currentPage = currentPage + 1
if _G["Page"..currentPage] ~= nil then
printPage(currentPage)
else
currentPage = currentPage - 1
end
elseif h == 19 and w < 15 then
currentPage = currentPage - 1
if _G["Page"..currentPage] ~= nil then
printPage(currentPage)
else
currentPage = currentPage + 1
end
elseif h == 19 and (w > 25 and w < 34) then
 
i = 0
for _ in pairs(MasterTable) do
clearAll()
i = i + 1
cleanval = string.gsub((textutils.serialize(MasterTable[i])), '"', "")
buyTable = _G[cleanval]
qty = _G["b"..buyTable.itemName]
id = buyTable.ID
dmg = buyTable.DMG
write(buyTable.itemName,id,dmg,qty)
--fillorder(id,dmg,qty)
newline()
end
end
end

 

Random snippits:

Just some tiny things that might be useful

 

This just grabs your code from pastebin and runs it, if you have a program that frequently needs updating this makes it way easier.

shell.run("delete","x")
shell.run("pastebin","get",<pastebin code>,"x")
shell.run("x")

 
Link to comment
Share on other sites

  • 4 weeks later...

Had this script for a while now and finaly tweaked it to a point where I think I can put it out. These scripts will let you send an email to anyone or even a text message. My plan is to make a radar system that sends me a text and email whenever someone gets near my base. (it still needs lots of work)

 

Anyways here are the things you'll need:

 

1 Computercraft computer

1 Webhosting service

and 1 Idea for what you're gonna use this in

 

 

Installing:

What you'll need to do first is get your webhosting service up and running. Get yourself familiar with it. Next upload this script to a place that can be accessed by an outside browser (eg, the 'public_html' folder)

<?php
        $message = urldecode($_GET['message']);
        $email = urldecode($_GET['to']);
        mail("$email", "AUTOMATED_MESSAGE:", "$message" );
?> 

After that go to your ingame terminal and add this script to your script

msg = "YOURMESSAGEHERE"
msgTo = "EXAMPLE@email.com)
http.post("http://example.com/email.php?message="..textutils.urlEncode(tostring(msg)).."&to="..textutils.urlEncode(tostring(msgTo)))

Then run it with your values substituted in and voila you should have an email in your inbox.

 

Have fun with it, talk to yourself, have a sensual conversation with a mysterious you on the other side.. but seriously I thought it would be pretty useful so yea, here it is.

Link to comment
Share on other sites

  • 3 months later...

Been a while since I've posted anything on this topic, but I did things :3

 

While coding I realized that there are a few things that I like to use (centered text, progress bars, buttons, etc) that added loads to the visual appeal of a script, however they were annoying to copy over to each new script each time and often cluttered my otherwise fresh workspace. After looking at api's and their uses in lua I decided to write my own.

 

As of this post it contains functions for:

  • Centered text

  • a print function for monitors

  • Progress bars

  • The ability to scan for all of a certain type of peripheral

  • Buttons


The code is as follows at the time of this post

function centerText(line,color,text,mon) --centerText(1,colors.white,"Hello World",nil)
if mon ~= nil then
local ox,oy = mon.getCursorPos()
local x,y = mon.getSize()
local mid = (x/2)-(string.len(text)/2)
mon.setCursorPos(mid,line)
mon.setTextColor(color)
mon.write(text)
mon.setTextColor(colors.white)
mon.setCursorPos(ox,oy)
else
local ox,oy = term.getCursorPos()
local x,y = term.getSize()
local mid = (x/2)-(string.len(text)/2)
term.setCursorPos(mid,line)
term.setTextColor(color)
term.write(text)
term.setTextColor(colors.white)
term.setCursorPos(ox,oy)
end
end
 
function m_print(mon,text)
local x,y = mon.getCursorPos()
mon.write(text)
mon.setCursorPos(1,y+1)
end
 
function progBar(ypos,pfull,text,barColor,mon) --pfull = percent full as a decimal ex, 80% = .8
if mon ~= nil then
local allText = math.floor(pfull*100).."% "..text
mon.setBackgroundColor(barColor)
local x,y = mon.getSize()
local pfull2 = math.floor(pfull*(x-6))
for i=3,x-3 do
mon.setCursorPos(i,ypos)
mon.write(" ")
end
if pfull < 0.6 then
mon.setBackgroundColor(colors.orange)
elseif pfull > 0.6 and pfull < 0.8 then
mon.setBackgroundColor(colors.yellow)
elseif pfull > 0.8 then
mon.setBackgroundColor(colors.green)
end
for i=3,pfull2 do
mon.setCursorPos(i,ypos)
mon.write(" ")
end
local half = (x/2)-(string.len(allText)/2)
mon.setBackgroundColor(colors.black)
mon.setCursorPos(half,ypos+1)
mon.write(allText)
else
local allText = math.floor(pfull*100).."% "..text
term.setBackgroundColor(barColor)
local x,y = term.getSize()
local pfull2 = math.floor(pfull*(x-6))
for i=3,x-3 do
term.setCursorPos(i,ypos)
term.write(" ")
end
if pfull < 0.6 then
term.setBackgroundColor(colors.orange)
elseif pfull > 0.6 and pfull < 0.8 then
term.setBackgroundColor(colors.yellow)
elseif pfull > 0.8 then
term.setBackgroundColor(colors.green)
end
for i=3,pfull2 do
term.setCursorPos(i,ypos)
term.write(" ")
end
local half = (x/2)-(string.len(allText)/2)
term.setBackgroundColor(colors.black)
term.setCursorPos(half,ypos+1)
term.write(allText)
end
end
 
function allPeripherals(ptype)
local peripherals = {}
for _,perip in pairs(peripheral.getNames()) do
if peripheral.getType(perip) == ptype then
table.insert(peripherals,perip)
end
end
if peripherals ~= nil then return peripherals else return false end
end
 
function buttonRun(buttonsData,mon)  --{{xpos,ypos,ysize,xsize,buttoncolor,textcolor,text,func,args,exitAfter},{...}}
local allButtons = {}
if mon ~=  nil then
else
for _,buttonData in pairs(buttonsData) do
local curButton = {
xmin = buttonData.xpos;
xmax = buttonData.xpos+buttonData.xsize;
ymin = buttonData.ypos;
ymax = buttonData.ypos+buttonData.ysize;
func = buttonData.func;
args = buttonData.args;
exitAfter = buttonData.exitAfter;
}
table.insert(allButtons,curButton)
local oldText = term.getTextColor()
local oldBack = term.getBackgroundColor()
term.setCursorPos(buttonData.xpos,buttonData.ypos)
term.setTextColor(buttonData.textColor)
term.setBackgroundColor(buttonData.buttonColor)
for i=1,buttonData.ysize do
term.setCursorPos(buttonData.xpos,buttonData.ypos+(i-1))
for o=1,buttonData.xsize do
term.write(" ")
end
end
local xhalf = (buttonData.xpos+(buttonData.xsize/2))-(string.len(buttonData.text)/2)
local yhalf = buttonData.ypos+(buttonData.ysize/2)
term.setCursorPos(xhalf,yhalf)
term.write(buttonData.text)
term.setTextColor(oldText)
term.setBackgroundColor(oldBack)
end
local running = true
while running do
local event,button,xpos,ypos = os.pullEvent("mouse_click")
for _,tB in pairs(allButtons) do
if (xpos >= tB.xmin and xpos <= tB.xmax) and (ypos >= tB.ymin and ypos <= tB.ymax)then
if tB.exitAfter then
if tB.func ~= nil then
tB.func(table.unpack(tB.args))
end
running = false
else
tB.func(table.unpack(tB.args))
end
end
end
--local event,side,xpos,ypos = os.pullEvent("monitor_touch") For monitors instead of terminals
end
end
end

 

Or if you want to actually be able to read the script correctly here is the pastebin link (It keeps indentations on pastebin so it actually looks decent)

 

So now you may ask yourself "hm, that's nice and all but I don't understand anything about this, HOW DO I USE IT?!" . Below are instructions/syntax for each function and how to import it into your own projects. Enjoy.

 

"How do I put this into my own script"

If you want an easy way to use this copy the script below into your own program and begin using the api as documented later in this post.

function essentialsAPI()
     shell.run("delete","eAPI")
     shell.run("pastebin","get","f2Ysr4i0","eAPI")
     os.loadAPI("eAPI")
end
essentialsAPI()

However if you have a script that frequently restarts it may fail from time to time. Because of the nature of this snippit, it pulls the most recent version of itself from pastebin which isn't always a working version if I am tweaking or adding things to the script. The better way to use this would be to grab it once while its stable by using

pastebin get f2Ysr4i0 eAPI

and then adding

os.loadAPI("eAPI")

 

"How do I use the centerText() function?"

Assuming you used the aforementioned method for inserting this api into your script the syntax is as follows...

eAPI.centerText(line,textColor,text,monitor)

So if you wanted to put some blue centered text that said "Hello World" on line 3 of your monitor that is on top of your computer you would use the following code

mon = peripheral.wrap("top")
eAPI.centerText(3,colors.blue,"Hello World",mon)

or if you instead wanted to write the text on the computer screen instead you would remove the variable named 'mon'

eAPI.centerText(3,colors.blue,"Hello World")

 

"How do I use the m_print (print function for monitors)?"

m_print() works almost exactly to print() except it is designed to be used on monitors instead. The syntax is as follows

m_print(mon,text)

If you wanted to write "Hello World" on the top monitor the code would look like

mon = peripheral.wrap("top")
eAPI.m_print(mon,"Hello World")

 

"How do I use the progBar() function?"

The progBar function is a basic progress bar.... that's really all it is. 

eAPI.progBar(ypos,pfull,text,barColor,mon)

This one is a little bit more tricky to use. The variable ypos represents the line of the monitor or terminal that the bar appears on. pfull is the percent that the bar is full as a decimal, ex .8 = 80% .25 = 25%. mon behaves the same as the rest of the other functions already stated. If mon is present it must be equal to peripheral.wrap("side") if you want it to display on the monitor, or if you want the bar to be on a monitor just leave that variable out and it will print there instead.

 

The bar used correctly at 37% full on line 3 using colors.red

eaknl1Z.png

 

 

"How do I use allPeripherals()?"

Right out of the gate I'm going to say it. This function isn't useful in the slightest if just used by itself. However paired with a little bit more code it can be fairly powerful. When provided with the name of a peripheral as a string (ex. "monitor") it will search for all of those types of peripherals out of all the ones its connected to and compile them into a table.

 

Syntax

eAPI.allPeripherals(ptype)

Using the code by itself is as easy as it gets, to search for all the monitors on the network the computer is connected to, you would use..

eAPI.allPeripherals("monitor")

However just doing that accomplishes nothing. The real use of the function comes in when you have a large network of monitors connected together that all need to display the same information. For example, you want to use the progBar() function on a ton of monitors to display the same information. To do that you would first connect all of the monitors and the computer together using wired modems and networking cable. Then to display a progress bar with 37%, colors.red, all on line 3 for all connected monitors you would use the following code...

os.loadAPI('eAPI')
for _,mn in pairs(eAPI.allPeripherals("monitor") do
     local temp = peripheral.wrap(mn)
     eAPI.progBar(3,0.37,"rf  Capacity",colors.red,temp)
end

 

"How do I use buttonRun()?"

Here it is, the big one. The problem of easily configurealbe buttons as stumped me for a long time. Oddly enough this came out more as a gui engine than anything, so its a little more difficult to use but still way faster than manually coding in all the touch functionality and the ability to run functions with a button.

 

To use this function requires a few tables and some syntax that I'm not completely set on, so it might change sometime in the future.

Syntax:

buttonRun(buttonsData,mon)

Simple enough right? Drop in the button data and a monitor (don't do that right now, I haven't added monitor support for it yet) and you're good to go...... heh, heh.. yea. buttonsData is a table of tables that contain the data for each button.

 

example: (I strongly advise that you copy this code into your pc and mess around with it to help you learn the syntax and requirements a little better)

os.loadAPI("eAPI")
testArgs = {"reboot'}
testButton = {
     xpos = 2;
     ypos = 2;
     ysize = 5;
     xsize = 20;
     buttonColor = colors.green;
     textColor = colors.red;
     text = "test";
     func = shell.run;
     args = testArgs;
     exitAfter = false;
}
eAPI.buttonRun({testButton},nil)

Thankfully it's not as complicated as it looks once you know what's required and how it's formatted.

 

firstly the table that goes in buttonRun() can be named whatever you want as long as it contains all the buttons you want to display, ex:

allButtons = {button1,button2,button3,etc}
eAPI.buttonRun(allButtons)

Easy enough to put the buttons in a table, now onto the actual requirements for each button. Each button requires the following:

xpos = x position of the top left hand corner of the button
ypos = y position of the top left hand corner of the button
xsize = size of the button along the x axis
ysize = size of the button along the y axis
buttonColor = color of the button
textColor = color of the text
text = text on the button
func = function you want the button to run without the () and arguments, ex shell.run if you wanted to run shell.run() or if you don't want to run a function for some reason use nil
args = arguments for your function in the form of a table (requirements are further in the post), use nil or {" "} if you don't have any arguments
exitAfter = true if you want to stop the buttonRun function after pressing (useful for multiple 'menus') or false if you want to continue responding to button touches.

Now for the last part. If you want to add any arguments to the function you're running with the button, this is where you'll add them. The arguments that you want to pass will be compacted into a table and then passed to the button. If you don't have any arguments for the button you want to use then feel free to skip this.

Arguments should look like this

button1_Args = {"arg1","arg2","arg3",etc}

Provided you could follow that mess of an explanation you are now ready to slap buttons on everything! However I still strongly advice you to copy the button example provided earlier and to mess with that to get a feel for how the function works

 

And that's all I got for now. Hopefully as time goes on I'll find more things to add to the api but for now its mostly done. If you have anything that you feel should be in the api ask me and I'll add it. Otherwise have fun with it and tell me if there are any bugs or if it explodes in your face or something. If you got projects of your own I'd be happy to help as long as ya ask.

Link to comment
Share on other sites

  • 2 weeks later...

Nice!

Here's something of mine I use with ICBM mod:

Master Nuclear Launch Computer:

--[Skynet Nuclear Defense Program by Andrew2060]--
--[To be used with http://pastebin.com/exm7HRhr]--

--[[Settings]]--
local modemSide = "top"
local waitDelay = 2

--[[Init]]--
rednet.open(modemSide)
local silos = {}

--[[Functions]]--
local function clear()
  term.clear()
  term.setCursorPos(1, 1)
end

term.setBackgroundColor(colors.blue)
clear()

local function findSilos()
	rednet.broadcast("ping silo")
  
  local timerID = os.startTimer(waitDelay)
  
  while true do
    event, id, msg, distance = os.pullEvent()
    
    if event == "rednet_message" and msg == "pong" then
      table.insert(silos, id)
      timerID = os.startTimer(waitDelay)
    elseif event == "timer" and id == timerID then
       return
    end
  end
end

local function launch(count, x, y, z)
  local msg = {x = x, y = y, z = z}
  local count = math.max(count, #silos)
  print("launching " .. count .. " rocket(s) at " .. x .. ", " .. y .. ", " .. z)
  for i = 1, count do
    rednet.send(silos[i], msg)
  end
  sleep(3)
end

local function printSilos()
  clear()
    print("===============================")
    print("        [Detected silos]       ")
    for k, v in ipairs(silos) do
    print("  silo #" .. k .. " id = "..v)
  end
    print("===============================")
    term.setBackgroundColor(colors.red)
    print("                               ")
    print("                               ")
    term.setBackgroundColor(colors.blue)
end

--[[Main program]]--
findSilos()

while true do
  printSilos()
  print("===============================")
  print("     [Launch Confirmation]     ")
  print("===============================")
  textutils.slowPrint("Enter Confirmation Code:")
  input  = read("*")
  term.setBackgroundColor(colors.red)
  print("                               ")
  print("                               ")
  term.setBackgroundColor(colors.blue)
  if input == "exit" then
    break
  elseif input == "949-854-3444" then  --Add preferred password within quotes
    local count, x, y, z
    while not (type(count) == "number" and type(x) == "number" and type(y) == "number" and type(z) == "number") do
      print("===============================")
      print("      [Target Selection]       ")
      print("===============================")
      write("Warhead count: ")
      count = tonumber(read())
      print("Coordinates:")
      write("X: ")
      x = tonumber(read())
      write("Y: ")
      y = tonumber(read())
      write("Z: ")
      z = tonumber(read())
    end
    launch(count, x, y, z)
    os.reboot()
  end
end

 

Missile silo controlling computer:

--Silo Launch PC, [working] [By Andrew2060]

--[[Settings]]--
local modemSide = "top"
local icbmSide = "back"
local armed = true
--set armed to false to disarm silo.
 
--[[Init]]--
rednet.open(modemSide)
local icbm = peripheral.wrap(icbmSide)
local masterID
 
--[[Functions]]--
local function clear()
  term.clear()
  term.setCursorPos(1, 1)
end
 
 
--[[Main program]]--
clear()
 
while true do
  print("Waiting for message")
  id, msg, distance = rednet.receive(masterID)
 
  if (msg == "ping silo") then
    print("  master=", id)
    masterID = id;
    rednet.send(masterID, "pong")
  elseif type(msg) == "table" and id == masterID then
    if type(msg.x) == "number" and type(msg.y) == "number" and type(msg.z) == "number" then
      print("  lauch to x=" .. msg.x .. ", y=" .. msg.y .. ", z=" .. msg.z)
      icbm.setTarget(msg.x, msg.y, msg.z)
      if (armed) then
        icbm.launch()
      end
    else
      print("  invalid table command")
    end
  else
    print("  invalid msg '", msg, "' from '", id, "', distance=", distance)
  end
end

It's a wireless system that controls nukes :3

Link to comment
Share on other sites

  • 1 month later...

API UPDATE TIME!

 

Recently I've expanded my lua knowledge quite a bit and felt like my older scripts are a little klunky and overdone. With this new mindset I went ahead and revamped essentialsAPI to start as a base for most if not all of the programs that I use.

 

Changelog:

  • centerText [unchanged]
  • newln [NEW]
  • progressBar [recoded, syntax changed, uses the new paintBox function]
  • paintBox [NEW, made because the tekkit version of cc doesnt have paintutils.drawFilledBox]
  • allPerpherals [unchanged]
  • tableContains [NEW]
  • buttons [recoded, syntax changed, the new version of the buttonRun function]
  • Anything else not listed has been removed

 

Syntax: [required],<optional>

centerText([yPosition],[Text],<Color>)
newln(<# of new lines>)
progressBar([yPosition],[Percent full (as a decimal)],[Text])
paintBox([x1Position],[y1Position],[x2Position],[y2Position],[Color],<Centered text>)
allPeripherals([Peripheral type]) | Returns table of peripherals
table_Contains([Table to search],[What you're searching for]) | Returns true if found, false if not
button([Table containing all buttons]) ex: button({btn1,btn2,...})

 

Button table syntax:

 

[button name]={
xpos;
ypos;
xsize;
ysize;
text;
color;
centerText;
func;
args={};
exit;
}

 

Confusing, yes so here's an example:

 

btn1={
xpos=5;
ypos=2;
xsize=10;
ysize=5;
text="Say Hello!"
color=colors.red;
centerText=true;
func=print;
args={"HELLO!"};
exit=false;
}
button({btn1})

 

So far that's all other than additions and improvements to personal programs.

 

PASTEBIN:http://pastebin.com/f2Ysr4i0

 

RAW CODE:

--essentialsAPI, From:Slitty ;3 (aka Slit)


function centerText(line,text,color) --centerText(1,colors.white,"Hello World")
    local ox,oy = term.getCursorPos()
    local x,y = term.getSize()
    local mid = (x/2)-(string.len(text)/2)
    term.setCursorPos(mid,line)
    if not color then local color = colors.white end
    term.setTextColor(color)
    term.write(text)
    term.setTextColor(colors.white)
    term.setCursorPos(ox,oy)
end

function newln(ln)
    if not ln then ln = 1 end
    local x,y = term.getCursorPos()
    term.setCursorPos(1,y+ln)
end

function progressBar(ypos,percent,text)
    local x,y = term.getSize()
    local text = math.floor(percent*100).."% "..text
    local half = (x/2)-(string.len(text)/2)
    local percent = math.floor(percent*(x-6))
    local colorInput
    local color
    paintutils.drawLine(6,ypos,x-6,ypos,colors.red)
    paintutils.drawLine(6,ypos,percent,ypos,color)
    term.setBackgroundColor(colors.black)
    term.setCursorPos(half,ypos+1)
    write(text)
    term.setCursorPos(1,ypos+2)
end

function paintBox(xpos,ypos,xsize,ysize,color,text,center)
    for i=1,ysize do
        paintutils.drawLine(tonumber(xpos),(tonumber(ypos)+i)-1,tonumber(xpos)+tonumber(xsize),(tonumber(ypos)+i)-1,color)
    end
    if not text then local text = " " end
    if center then
        term.setCursorPos((xpos+xsize/2)-(text:len()/2),ypos+ysize/2)
        write(text)
    elseif not center then
        term.setCursorPos(xpos,ypos)
        write(text)
    end
    term.setBackgroundColor(colors.black)
end

function allPeripherals(ptype)
    local peripherals = {}
    for _,perip in pairs(peripheral.getNames()) do
        if peripheral.getType(perip) == ptype then
            table.insert(peripherals,perip)
        end
    end
    if peripherals ~= nil then return peripherals else return false end
end

function table_contains(table,contain)
    local found = false
    for _,val in pairs(table) do
        if val == contain then
            found = true
        end
    end
    return found
end

function button(buttons)
    for num,btn in pairs(buttons) do
        if btn["xsize"] < btn["text"]:len() then
            term.clear()
            error("Length of text ["..btn["text"]:len().."] is longer than the space available["..btn["xsize"].."]")
        end
        paintBox(btn["xpos"],btn["ypos"],btn["xsize"],btn["ysize"],btn["color"],btn["text"],btn["centerText"])
    end
    local running = true
    while running do
        local _,_,x,y=os.pullEvent("mouse_click")
        for _,btn in pairs(buttons) do
            if (x >= btn["xpos"] and x <= btn["xpos"]+btn["xsize"]) and (y >= btn["ypos"] and y <= btn["ypos"]+btn["ysize"]) then
                if btn["exit"] then
                    running = false
                    btn["func"](unpack(btn["args"]))
                else
                    btn["func"](unpack(btn["args"]))
                end
            end
        end
    end
end
Link to comment
Share on other sites

Small update:

A while ago I built a cc script that was supposed to monitor the shoutbox for the forums, it failed for some reason and as of recently I missed it. Over the last dayish of on and off coding I've managed to recode it to be more robust and hopefully not fail.

 

Its fairly bare bones as of right now and just prints out the raw results for the shoutbox. I plan on working on the formatting in the near future. but for now it looks decent enough. If you want to use it just grab this script make another file named "startup" and put the following code in it.

shell.run("pastebin","run","9cxnPWFH")
sleep(10)
os.reboot()

Connect a monitor to any side of the terminal or use some networking cable and wired modems.After that save the file and just grab my essentialsAPI with

pastebin get f2Ysr4i0 eAPI

and then you're good to reboot the pc and enjoy the forums on the comfort of your own computer connected monitor.

 

Expect updates in the future, hopefully they look better than this does right now.

 

Raw code:

os.loadAPI("eAPI")

local url = "http://forum.craftersland.net/index.php?app=shoutbox&do=popup"

local mon = peripheral.wrap(eAPI.allPeripherals("monitor")[1])
term.redirect(mon)

mon.setTextScale(0.5)

shell.run("delete","shout.filter")
shell.run("pastebin","get","sLtibuvn","shout.filter")

if url then --http.checkURL(url)==
    local data = http.get(url).readAll()
    local f=io.open("shout.raw","w")
    f:write(data)
    f:close()
    local lines={}
    for line in io.lines("shout.raw") do
        table.insert(lines,line)
    end
    term.clear()
    term.setCursorPos(1,1)
    for i=1,#lines do
        if lines[i]:find('class="at_member"') then
            local temp=lines[i].." : "..lines[i+6].." : "..lines[i+8]
            for filter in io.lines("shout.filter") do
                temp=temp:gsub(filter,"")
            end
            print(temp)
            print("----------------------------")
        end
    end
else
    error("Add "..url.." to your http whitelist")
end
Link to comment
Share on other sites

  • 3 months later...

Update time!

 

Pastebin wasn't cutting it. Instead I got myself a domain and with a little php and html I now have my own alternative. However the downside is that initial installation is a bit of a pain. To make it as painless as possible there's only one file that you'll need to download manually. 

lua
url="http://sitenil.comli.com/CC/API/ccget.lua"
f=fs.open("ccget","w")
f.write(http.get(url).readAll())
f.close()

Copying that series of commands into the computer after it starts up for the first time will download the script you need to begin using the new host easily and efficiently.

 

After completing those commands you should have a new file named 'ccget'. the syntax is as follows

ccget <run/get> <type> <id>

The list of scripts are all located here.

 

Examples:

ccget get API essentials.lua

that would download the essentials api as 'essentials'

ccget get Script scrollingText.lua

That would download the scrolling text script as 'scrollingText'

Link to comment
Share on other sites

Dynmap scripts are blank on purpose. Player detector scripts will be locked if they are uploaded. Also there will be no upload system put in place, I'm currently using it as a private host for my own scripts.

Link to comment
Share on other sites

Dynmap scripts are blank on purpose WHY??????????????? Player detector scripts will be locked WHYYYYYYYYYYYYYY? if they are uploaded. Also there will be no upload system put in place, I'm currently using it as a private host for my own scripts. Ok

First I like to keep this version of the dynmap to myself. Second you know perfectly well that player tracking scripts are illegal.

you're writing this and i can't even open paint

Lol git gud sun

Link to comment
Share on other sites

  • 2 months later...

hey slti? HOw do you run a paint programme? I wont to color some colering pages, how do? please help i need to paint and unleash my art beast inside ples respond,

also I am a thred necromancer >:)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

By using this site you agree to the following Terms of Use, Guidelines and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.