Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- com = peripheral.wrap("left")
- local w, h = term.getSize()
- local sbc = term.setBackgroundColor
- local stc = term.setTextColor
- local scp = term.setCursorPos
- local clr = term.clear
- local plist = {}
- local c = colors
- local pa = paintutils
- local yoff = 0
- local selname = 1
- local insystem = true
- local colorencode = {
- ['&l'] = nil,
- ['&m'] = nil,
- ['&n'] = nil,
- ['&o'] = nil,
- ['&k'] = 123,
- ['&r'] = "white",
- ['&1'] = "blue",
- ['&2'] = "green",
- ['&3'] = "cyan",
- ['&4'] = "red",
- ['&5'] = "purple",
- ['&6'] = "brown",
- ['&7'] = "lightGray",
- ['&8'] = "gray",
- ['&9'] = "lightBlue",
- ['&a'] = "lime",
- ['&b'] = "lightBlue",
- ['&c'] = "pink",
- ['&d'] = "magenta",
- ['&e'] = "yellow",
- ['&f'] = "white",
- }
- function cwrite(t,y)
- scp((w/2) - (#t/2),y)
- write(t)
- end
- local function getinput()
- scp(1,1)
- sbc(colors.orange)
- term.clearLine()
- return read()
- end
- local function drawtop(tx,nw)
- scp(1,1)
- sbc(colors.orange)
- term.clearLine()
- write(tx)
- if(not nw)then os.pullEvent("mouse_click") end
- end
- local function resettop()
- sbc(colors.orange)
- scp(1,1)
- term.clearLine()
- stc(colors.white)
- write("FakePlayer - Enhanced")
- end
- local function checkforname(nm)
- for i = 1, #plist do
- if(plist[i] == nm)then return true end
- end
- return false
- end
- function talk(nc,c,notpl)
- if(notpl)then suff = "&f " else suff = "&f: " end
- com.setCommand("sudo @a ping " .. plist[nc] .. suff .. c)
- com.runCommand()
- end
- local function addpname(nm)
- plist[#plist+1] = nm
- end
- local futils = {
- writeLine = function (to,ln)
- if(fs.exists(to))then
- local f = fs.open(to,"w")
- f.writeLine(ln)
- f.close()
- else
- error("No such file: " .. to .. ". ")
- end
- end,
- readLine = function (to,ln)
- if(fs.exists(to))then
- local f = fs.open(to,"r")
- local cont = f.readLine(ln)
- f.close()
- return cont
- else
- error("No such file: " .. to .. ". ")
- end
- end,
- readAll = function (to)
- if(fs.exists(to))then
- local f = fs.open(to,"r")
- local cont = f.readAll()
- f.close()
- return cont
- else
- error("No such file: " .. to .. ". ")
- end
- end,
- write = function (to,ln)
- if(fs.exists(to))then
- local f = fs.open(to,"w")
- f.write(ln)
- f.close()
- else
- error("No such file: " .. to .. ". ")
- end
- end,
- }
- function getnames()
- if(not fs.exists(".pnames"))then
- futils.write(".pnames",{})
- end
- plist = textutils.unserialize(futils.readAll(".pnames"))
- end
- local function clearname()
- write(string.rep(" ",w-42)
- drawback()
- drawoptions()
- end
- local function drawencodestr(str)
- for a = 1, #str do
- if(a >= 42)then
- else
- if(string.sub(str,a,a) == "&")then
- if(colorencode[string.sub(str,a,a+1)] ~= nil)then
- stc(colors[colorencode[string.sub(str,a,a+1)]])
- end
- str = string.sub(str,1,a-1) .. string.sub(str,a+1,#str)
- else
- write(string.sub(str,a,a))
- end
- end
- end
- end
- local function drawlist(offupd)
- for i = 1+yoff, (h-2)+yoff do
- scp(3,(i-yoff)+2)
- sbc(colors.white)
- stc(colors.black)
- if(plist[i] == nil)then
- scp(1,(i-yoff)+2)
- clearname()
- else
- clearname()
- scp(1,(i-yoff)+2)
- sbc(colors.blue)
- stc(colors.white)
- write("~")
- local nowrite = false
- scp(2,(i-yoff)+2)
- if(i == selname)then
- sbc(colors.lightBlue)
- stc(colors.white)
- if(string.find(plist[i],"&"))then
- write(" ")
- drawencodestr(plist[i])
- else
- write(" " .. string.sub(plist[i],1,42))
- end
- else
- sbc(colors.white)
- stc(colors.black)
- if(string.find(plist[i],"&"))then
- write(" ")
- drawencodestr(plist[i])
- else
- write(" " .. string.sub(plist[i],1,42))
- end
- end
- end
- end
- end
- local options = {
- {n="Add name",func = function()
- local name = getinput()
- if(checkforname(name))then
- drawtop("Name already in database! ")
- resettop()
- else
- addpname(name)
- drawtop("Named added: " .. string.sub(name,1,30) .. "...")
- resettop()
- drawlist()
- end
- end},
- {n='Del name',func = function()
- drawtop("Named removed: " .. string.sub(plist[selname],1,30) .. "... ! ")
- resettop()
- table.remove(plist,selname)
- drawlist()
- end},
- {n='Chat as',func = function()
- local rchat = true
- while rchat do
- drawtop("type /exit to exit: ",true)
- local ms = read()
- if(ms == "/exit")then
- rchat = false
- break
- end
- talk(selname,ms)
- end
- return
- end},
- {n='Say as',func = function()
- local rchat = true
- while rchat do
- drawtop("type /exit to exit: ",true)
- local ms = read()
- if(ms == "/exit")then
- rchat = false
- break
- end
- talk(selname,ms,true)
- end
- return
- end},
- {n='Save names',func = function()
- f = fs.open(".pnames","w")
- f.write(textutils.serialize(plist))
- f.close()
- drawtop("Names saved!")
- resettop()
- end},
- {n='Quit',func = function()
- sbc(colors.black)
- clr()
- stc(colors.white)
- scp(1,1)
- cwrite("Thank you for using advanced FakePlayer system!",1)
- cwrite("Created by: Lewisk3",2)
- print(" ")
- insystem = false
- return
- end},
- }
- local function drawoptions()
- sbc(colors.gray)
- stc(colors.white)
- for i = 1, #options do
- scp(w-10,i+2)
- write(options[i].n)
- end
- end
- local function flashoption(num)
- sbc(colors.black)
- scp(w-10,num+2)
- stc(colors.white)
- write(options[num].n)
- sleep(0.1)
- sbc(colors.gray)
- scp(w-10,num+2)
- stc(colors.white)
- write(options[num].n)
- end
- local function reselect()
- drawlist()
- if(selname > 1)then -- up
- selname = selname - 1
- if(yoff > 0)then yoff = yoff - 1 end
- drawlist()
- elseif(selname < #plist)then -- down
- selname = selname + 1
- if(selname >= (h+yoff)-1)then yoff = yoff + 1 end
- drawlist()
- end
- end
- local function update(e)
- if(plist[selname] == nil)then
- reselect()
- end
- if(e[1] == "mouse_scroll")then
- if(e[2] == -1 and selname > 1)then -- up
- selname = selname - 1
- if(yoff > 0)then yoff = yoff - 1 end
- drawlist()
- elseif(e[2] == 1 and selname < #plist)then -- down
- selname = selname + 1
- if(selname >= (h+yoff)-1)then yoff = yoff + 1 end
- drawlist()
- end
- end
- if(e[1] == "mouse_click" or e[1] == "mouse_drag")then
- local x,y = e[3], e[4]
- if(x < w-11)then
- for i = 1+yoff, (h-2)+yoff do
- if(y-2 == i-yoff)then
- if(x >= 2 and x <= 2+#tostring(plist[i]))then
- selname = i
- drawlist()
- drawback()
- drawoptions()
- end
- end
- end
- else
- for i = 1, #options do
- if(x >= w-11 and x <= (w-11)+#options[i].n and y == i+2)then
- flashoption(i)
- options[i].func()
- end
- end
- end
- end
- end
- local function drawback()
- sbc(colors.white)
- clr()
- pa.drawFilledBox(w-12,2,w,h,colors.gray)
- sbc(colors.orange)
- scp(1,1)
- term.clearLine()
- stc(colors.white)
- write("FakePlayer - Enhanced")
- end
- drawback()
- getnames()
- drawlist()
- drawoptions()
- while insystem do
- local e = {os.pullEvent()}
- update(e)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement