Commit 9a473238 authored by Danny SMc's avatar Danny SMc 🎧

Create uHug

parent 89f78163
-- uHug: Sending Hugs
-- Created By DannySMc
-- Version 1.0
-- Platform: Lua Virtual Machine
function downloadAPI()
print("Downloading API...")
getGit = http.get("https://raw.github.com/dannysmc95/uprograms/master/uAPI")
getGit = getGit.readAll()
file = fs.open("uapi", "w")
file.write(getGit)
file.close()
print("Done!")
os.loadAPI("uapi")
end
function checkForModem()
modemSide = uapi.findPeripheral("modem")
if modemSide == nil then
print("Modem Not Found!")
sleep(2)
os.shutdown()
else
rednet.open(modemSide)
home()
end
end
function sendHug(intID)
rednet.send(intID, "hug")
end
function sendKiss(intID)
rednet.send(intID, "kiss")
end
function home()
uapi.cs()
uapi.drawBox(1, 51, 1, 3, " ", tc, bc)
uapi.drawBox(1, 51, 2, 1, " ", tc, bc)
uapi.drawBox(1, 51, 19, 1, " ", tc, bc)
uapi.printC("uHug - Hugging The World! ID: "..intComputerID, 2, false, tc, bc)
drawTime()
term.setCursorPos(1,16)
print("> Press 1 to send a hug to someone!")
print("> Press 2 to send a kiss to someone!")
print("> Press 3 to broadcast a hug!")
term.setCursorPos(1,5)
print("> Hugs Received: "..intHugs)
print(" ")
print("> Kisses Received: "..intKisses)
print(" ")
print("> Hugs Sent: "..intSentHugs)
print(" ")
print("> Kisses Sent: "..intSentKisses)
os.startTimer(1)
while true do
local event, arg1, arg2, arg3, arg4, arg5 = os.pullEvent()
if event == "char" then
if arg1 == "1" then
uapi.drawBox(12, 27, 8, 3, " ", tc, bc)
uapi.drawBox(12, 27, 9, 1, " ", tc, bc)
uapi.printA("What is the receiving ID ?", 12, 8, false, tc, bc)
uapi.setCol(tc, bc)
term.setCursorPos(12, 9)
write("ID> ")
IDToHug = tonumber(read())
uapi.resetCol()
uapi.printC(">> Sending Hug <<", 10, false, tc, bc)
sleep(1)
sendHug(IDToHug)
intSentHugs = intSentHugs + 1
home()
elseif arg1 == "2" then
uapi.drawBox(12, 27, 8, 3, " ", tc, bc)
uapi.drawBox(12, 27, 9, 1, " ", tc, bc)
uapi.printA("What is the receiving ID ?", 12, 8, false, tc, bc)
uapi.setCol(tc, bc)
term.setCursorPos(12, 9)
write("ID> ")
IDToKiss = tonumber(read())
uapi.resetCol()
uapi.printC(">> Sending Hug <<", 10, false, tc, bc)
sleep(1)
sendKiss(IDToKiss)
intSentKisses = intSentKisses + 1
home()
elseif arg1 == "3" then
uapi.drawBox(12, 27, 9, 1, " ", tc, bc)
uapi.printC(">> Broadcasting Hug <<", 9, false, tc, bc)
sleep(1)
rednet.broadcast("hug")
intSentHugs = intSentHugs + 1
home()
end
elseif event == "rednet_message" then
if arg2 == "hug" then
intHugs = intHugs + 1
home()
elseif arg2 == "kiss" then
intKisses = intKisses + 1
home()
end
elseif event == "timer" then
drawTime()
os.startTimer(1)
end
end
end
function drawTime()
worldTime = textutils.formatTime(os.time())
uapi.printC("Created By DannySMc -> Time: "..worldTime, 19, false, tc, bc)
end
if fs.exists("uapi") == false then
downloadAPI()
os.reboot()
else
os.loadAPI("uapi")
end
intHugs = 0
intSentHugs = 0
intKisses = 0
intSentKisses = 0
tc = "white"
bc = "cyan"
intComputerID = os.getComputerID()
checkForModem()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment