Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- ########################################## --
- -- ## TheOnlyCozzy's Timestamp Console Log ## --
- -- ############################# v0.1 ##### --
- createdTimers = {} -- timer IDs to store when messages gets recieved
- interval = 10 -- how often to update timer intervals
- tX,tY = term.getSize() -- get terminal dimensions
- function createTimer(timerName,text) -- create new timer in next slot in createdTimers
- timerName = os.startTimer(interval)
- createdTimers[#createdTimers+1] = {timerID = timerName, interval = 0, message = text}
- end
- rednet.open("right")
- while true do
- event,p1,p2,p3 = os.pullEvent()
- if event == "timer" then -- if a timer event fired
- if #createdTimers > tY-1 then -- if the list is bigger than what can be displayed
- table.remove(createdTimers,1)
- end
- for i=1,#createdTimers do
- if createdTimers[i].timerID == p1 then -- check for a match timer fired to list
- createdTimers[i].interval = createdTimers[i].interval + 1 -- add one to the interval
- --print("timer "..createdTimers[i].timerID.." fired") -- debug
- createdTimers[i].timerID = os.startTimer(interval) -- restart timer
- end --> end check for match
- timeElapsed = createdTimers[i].interval*interval -- store time to convert to seconds and minutes
- if timeElapsed < 60 then -- timestamp formatting
- timeElapsed = tostring(timeElapsed).." sec"
- elseif timeElapsed == 60 then
- timeElapsed = "1 min"
- elseif timeElapsed > 60 then
- formatting = tostring(timeElapsed/60)
- timeElapsed = string.sub(formatting,1,4).." min"
- end
- term.setCursorPos(1,tY-(#createdTimers-i)) -- align messages
- term.clearLine() -- clear line to remove excess text from previous message
- term.write(timeElapsed..") "..createdTimers[i].message) -- write new message
- end --> end of for createdTimers loop
- end --> end of timer event
- if event == "rednet_message" then -- if recieved a rednet message
- rand = math.random(655355) -- generate random 16 bit number
- createTimer(rand,p2)
- end --> end of rednet message event
- end --> end of while true do
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement