Posted 01 July 2012 - 11:48 PM
Hey dear fellow programmers,
I made this program for a bulletin board at my server, however, there is a slight issue with the code.
When set to textscale 2, it works fine, but the text is too big to fit on the screen. Using scale 1, however, will not print the most important parts of the board. It does not print the "layout", "header" and "info" parts, while it does actually print the line from "print1" when receiving the rednet message. I have no idea what causes this problem, so any help would be greatly appreciated!
Also, any tips on how to further improve this code are welcome as well!
http://pastebin.com/D9kMGQr4
I made this program for a bulletin board at my server, however, there is a slight issue with the code.
When set to textscale 2, it works fine, but the text is too big to fit on the screen. Using scale 1, however, will not print the most important parts of the board. It does not print the "layout", "header" and "info" parts, while it does actually print the line from "print1" when receiving the rednet message. I have no idea what causes this problem, so any help would be greatly appreciated!
Also, any tips on how to further improve this code are welcome as well!
http://pastebin.com/D9kMGQr4
rednet.open("right")
monitor = peripheral.wrap("top")
monitor.setTextScale(1)
tw,th = term.getSize()
mw,mh = monitor.getSize()
serverID = 151
incursions = 0
local function mPrint(str, ypos)
monitor.setCursorPos(1, ypos)
monitor.write(str)
end
local function tPrintCentered(str, ypos)
term.setCursorPos(tw/2 - #str/2, ypos)
term.write(str)
end
local function mPrintCentered(str, ypos)
monitor.setCursorPos(mw/2 - #str/2, ypos)
monitor.write(str)
end
local function tPrintD(str1, str2, ypos)
term.setCursorPos(1, ypos)
term.write(str1)
term.setCursorPos(tw/2, ypos)
term.write(str2)
end
local function mPrintD(str1, str2, ypos)
monitor.setCursorPos(1, ypos)
monitor.write(str1)
monitor.setCursorPos(mw/2, ypos)
monitor.write(str2)
end
local function tPrintDC(str1, str2, ypos)
term.setCursorPos((tw/4) - (#str1/2), ypos)
term.write(str1)
term.setCursorPos(tw - (tw/4) -(#str2/2), ypos)
term.write(str2)
end
local function mPrintDC(str1, str2, ypos)
monitor.setCursorPos((mw/4) - (#str1/2), ypos)
monitor.write(str1)
monitor.setCursorPos(mw - (mw/4) - (#str2/2), ypos)
monitor.write(str2)
end
local function layout(line)
for n=2, mh-1, 1 do
monitor.setCursorPos(1, n)
monitor.write("|")
monitor.setCursorPos(mw, n)
monitor.write("|")
end
monitor.setCursorPos(1, line)
monitor.write("+")
for n=2, mw-1, 1 do
monitor.setCursorPos(n, line)
monitor.write("-")
end
monitor.setCursorPos(mw, line)
monitor.write("+")
end
local function redraw(line)
monitor.setCursorPos(mw, line)
monitor.write("|")
end
local function header()
mPrint(" _____ _ _ _ ____ _ ",2)
mPrint(" | ____| |_| |__ ___ _ __ ___ __ _| | / ___| __ _ _ __ ___ (_)_ __ __ _ ",3)
mPrint(" | _| | __| '_ / _ '__/ _ / _` | | | | _ / _` | '_ ` _ | | '_ / _` |",4)
mPrint(" | |___| |_| | | | __/ | | __/ (_| | | | |_| | (_| | | | | | | | | | | (_| |",5)
mPrint(" |_____|__|_| |_|___|_| ___|__,_|_| ____|__,_|_| |_| |_|_|_| |_|__, |",6)
mPrint(" |___/ ",7)
for line=2,7,1 do
redraw(line)
end
end
local function info()
mPrintC("Welcome to the Ethereal Gaming tekkit server!", 9)
mPrintC("Please adhere to the following rules:", 11)
mPrintDC("1. No spam", "3. No hacking", 12)
mPrintDC("2. No griefing", "4. No duping", 13)
mPrintC("5. No hassling admins.", 14)
for n=9,14,1 do
redraw(n)
end
end
local function print1()
mPrintC("This MOTD is currently empty...", 16)
redraw(16)
end
local function print2()
mPrintC("This MOTD is currently empty...", 16)
redraw(16)
end
local function print3()
mPrintC("This MOTD is currently empty...", 16)
redraw(16)
end
local function print4()
mPrintC("This MOTD is currently empty...", 16)
redraw(16)
end
local function print5()
mPrintC("This MOTD is currently empty...", 16)
redraw(16)
end
local function incursion()
mPrintC("INCURSION DETECTED", mh-1)
redraw(mh-1)
incursions = incursions+1
end
local function reboot()
os.reboot()
end
local function terminate()
os.shutdown()
end
local function exit()
break end
local function listen()
id,message = rednet.receive()
if id == serverID then
if message == "print1" then
print1()
elseif message == "print2" then
print2()
elseif message == "print3" then
print3()
elseif message == "print4" then
print4()
elseif message == "print5" then
print5()
elseif message == "reboot" then
reboot()
elseif message == "terminate" then
terminate()
elseif message == "exit" then
exit()
end
elseif id ~= serverID then
incursion()
end
end
function main()
layout(1)
layout(8)
layout(15)
header()
info()
while true do
listen()
end
end
main()