SHOW:
|
|
- or go back to the newest paste.
1 | function split(str, pat) | |
2 | local t = {} -- NOTE: use {n = 0} in Lua-5.0 | |
3 | local fpat = "(.-)" .. pat | |
4 | local last_end = 1 | |
5 | local s, e, cap = str:find(fpat, 1) | |
6 | while s do | |
7 | if s ~= 1 or cap ~= "" then | |
8 | table.insert(t,cap) | |
9 | end | |
10 | last_end = e+1 | |
11 | s, e, cap = str:find(fpat, last_end) | |
12 | end | |
13 | if last_end <= #str then | |
14 | cap = str:sub(last_end) | |
15 | table.insert(t, cap) | |
16 | end | |
17 | return t | |
18 | end | |
19 | term.clear() | |
20 | term.setCursorPos(1,1) | |
21 | print("CraftCoin Alpha 1.0 Mining Server") | |
22 | modem = peripheral.wrap("bottom") | |
23 | modem.open(1) | |
24 | mining={} | |
25 | while true do | |
26 | os.startTimer(0.05) | |
27 | event, a, b, c, d, f = os.pullEventRaw() | |
28 | if event == "timer" then | |
29 | print("Tick") | |
30 | for i,v in pairs(mining) do | |
31 | if mining[i]~= 1337 then | |
32 | mining[i]=v-1 | |
33 | print(v) | |
34 | if mining[i]<0 then | |
35 | print("Finished A Mine") | |
36 | modem.transmit(1,1,"mined "..i) | |
37 | mining[i]=1337 | |
38 | end | |
39 | end | |
40 | end | |
41 | elseif event == "modem_message" then | |
42 | msg = d | |
43 | msgp = split(msg," ") | |
44 | if msgp[1] == "startmine" then | |
45 | if msgp[2] then | |
46 | mining[msgp[2]]= 1000/3.14*math.random(10,20) | |
47 | end | |
48 | end | |
49 | end | |
50 | end |