View difference between Paste ID: fXYd3W6r and 1XNLJD3b
SHOW: | | - or go back to the newest paste.
1
modem = peripheral.find("modem")
2
 
3
local mtable = {}
4
local w, h = term.getSize()
5
 
6
os.loadAPI("ea")
7
 
8
function clear()
9
 
10
        ea.sbc(colors.white)
11
        term.clear()
12
 
13
        ea.stc(colors.blue)
14
        ea.scp(1,18)
15
        ea.sbc(colors.gray)
16
        write("<Type /help for help>")
17
        ea.sbc(colors.white)
18
 ea.scp(1,19)
19
        write("[::> ")
20
        ea.scp(6,19)
21
 
22
end
23
 
24
 
25
function start()
26
 
27
        ea.sbc(colors.white)
28
 ea.stc(colors.black)
29
        term.clear()
30
        ea.scp(16,9)
31
        print("Kosy Chat System")
32
        ea.scp(13,11)
33
        print("Username: ")
34
        ea.scp(13,12)
35
        print("Channel : ")
36
 
37
        ea.scp(22,11)
38
        us = io.read()
39
        ea.scp(22,12)
40
        ch = io.read()
41
 
42
        modem.open(tonumber(ch))
43
        clear()
44
        chatgo()
45
 
46
end
47
 
48
 
49
 
50
function drawm()
51
 
52
        if(#mtable > h-2)then local tt = mtable[h-2] mtable = {} table.insert(mtable,tt) tt = "" end
53
 
54
        for i = 1, #mtable do
55
 
56
                ea.scp(1,i)
57
  print(mtable[i])
58
 
59
        end
60
 
61
end
62
 
63
 
64
function receive()
65
 
66
        e = {os.pullEvent("modem_message")}
67
 
68
 
69
                 table.insert(mtable, e[5])
70
 
71
 end
72
73
 function send()
74
75
76
    
77
                ea.scp(7,19)
78
                readm = read()
79
                modem.transmit(tonumber(ch), tonumber(ch), "<"..us..">: "..readm)
80-
                table.insert(mtable,"me > "..readm)
80+
81
 
82
      
83
 
84
end
85
 
86
 
87
function chatgo()
88
 
89
        while true do
90
 
91
                drawm()
92
                parallel.waitForAny(send, receive)
93
 
94
        end
95
 
96
end
97
start()