Advertisement
Guest User

seterownia

a guest
Aug 23rd, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.91 KB | None | 0 0
  1.  
  2. rednet.open("back")
  3. local mon = term
  4.  
  5. local id_spawnera = 3
  6.  
  7. --mon.setTextScale(1)
  8. mon.setTextColor(colors.white)
  9. local button={}
  10. mon.setBackgroundColor(colors.black)
  11. local g_strona = 1
  12. local g_naglowek={}
  13.      
  14. function UstawTabele(p_strona, p_name, p_funkcja, p_parametr, p_xmin, p_xmax, p_ymin, p_ymax, p_color)
  15.    button[p_strona][p_name] = {}
  16.    button[p_strona][p_name]["funkcja"] = p_funkcja
  17.    button[p_strona][p_name]["parametr"] = p_parametr
  18.    button[p_strona][p_name]["aktywny"] = false
  19.    button[p_strona][p_name]["xmin"] = p_xmin
  20.    button[p_strona][p_name]["ymin"] = p_ymin
  21.    button[p_strona][p_name]["xmax"] = p_xmax
  22.    button[p_strona][p_name]["ymax"] = p_ymax
  23.    button[p_strona][p_name]["color"] = p_color
  24. end
  25.  
  26. function Zmien_strona1()
  27.    g_strona = 1
  28. end
  29.  
  30. function Zmien_strona2()
  31.    g_strona = 2
  32. end
  33.  
  34. function Zmien_strona3()
  35.    g_strona = 3
  36. end
  37.  
  38. function Zmien_strona4()
  39.    g_strona = 4
  40. end
  41.  
  42. function Test()
  43.    WyslijRednet("Test", "Wiadomosc testowa","N", 1)
  44.    --print("Nacisneles na przycisk nr 2")
  45. end
  46.    
  47. function Ustaw_spawner(p_kolor, p_on)
  48.   if p_on == true then
  49.     WyslijRednet("Ustaw_spawner", p_kolor,"N", id_spawnera)
  50.   else
  51.     WyslijRednet("Ustaw_spawner", p_kolor,"T", id_spawnera)
  52.   end
  53. end
  54.    
  55. function UtworzStrony()
  56.    button[1] = {}
  57.    button[2] = {}
  58.    button[3] = {}
  59.    button[4] = {}
  60.    g_naglowek[1] = "Sterownia SafemodTV"
  61.    g_naglowek[2] = "Mob Grinder"
  62.    g_naglowek[3] = "Farmy i automaty"
  63.    g_naglowek[4] = "Elektrownie"
  64. end      
  65.        
  66. function UtworzTabele()
  67.    --  Strona 1
  68.    UstawTabele(1, "Mob Grinder", Zmien_strona2, nil, 2, 25, 3, 5, colors.cyan)
  69.    UstawTabele(1, "Farmy i automaty", Zmien_strona3, nil, 2, 25, 7, 9, colors.green)
  70.    UstawTabele(1, "Elektrownie", Zmien_strona4, nil, 2, 25, 11, 13, colors.purple)
  71.    
  72.    --  Strona 2
  73.    UstawTabele(2, "Creeper", Ustaw_spawner, "white", 2, 12, 3, 3)
  74.    UstawTabele(2, "Szkielet", Ustaw_spawner, "orange", 2, 12, 5, 5)
  75.    UstawTabele(2, "Spider", Ustaw_spawner, "magenta", 2, 12, 7, 7)
  76.    UstawTabele(2, "Zombie", Ustaw_spawner, "lightBlue", 2, 12, 9, 9)
  77.    UstawTabele(2, "ZombiePig", Ustaw_spawner, "yellow", 2, 12, 11, 11)  
  78.    UstawTabele(2, "Enderman", Ustaw_spawner, "lime", 2, 12, 13, 13)
  79.    UstawTabele(2, "Pig", Ustaw_spawner, "pink", 2, 12, 15, 15)
  80.    UstawTabele(2, "Sheep", Ustaw_spawner, "gray", 2, 12, 17, 17)
  81.    
  82.    UstawTabele(2, "Magma Cube", Ustaw_spawner, "lightGray", 15, 25, 3, 3)
  83.    UstawTabele(2, "Witch", Ustaw_spawner, "cyan", 15, 25, 5, 5)
  84.    UstawTabele(2, "Villager", Ustaw_spawner, "purple", 15, 25, 7, 7)
  85.    UstawTabele(2, "Iron Golem", Ustaw_spawner, "blue", 15, 25, 9, 9)
  86.    UstawTabele(2, "Cave Spider", Ustaw_spawner, "brown", 15, 25, 11, 11)  
  87.    UstawTabele(2, "B. Szkielet", Ustaw_spawner, "green", 15, 25, 13, 13)
  88.    UstawTabele(2, "Cow", Ustaw_spawner, "red", 15, 25, 15, 15)
  89.    UstawTabele(2, "Chicken", Ustaw_spawner, "black", 15, 25, 17, 17)
  90.    
  91.    UstawTabele(2, "Powrot", Zmien_strona1, nil, 2, 25, 19, 19, colors.cyan)
  92.    
  93.    --  Strona 3
  94.    UstawTabele(3, "Powrot", Zmien_strona1, nil, 2, 25, 19, 19, colors.cyan)
  95.    
  96.    --  Strona 4
  97.    UstawTabele(4, "Powrot", Zmien_strona1, nil, 2, 25, 19, 19, colors.cyan)
  98. end    
  99.  
  100. function UtworzPrzycisk(p_text, p_color, p_bData)
  101.    mon.setBackgroundColor(p_color)
  102.    local l_yspot = math.floor((p_bData["ymin"] + p_bData["ymax"]) /2)
  103.    local l_xspot = math.floor((p_bData["xmax"] - p_bData["xmin"] - string.len(p_text)) /2) +1
  104.    for j = p_bData["ymin"], p_bData["ymax"] do
  105.       mon.setCursorPos(p_bData["xmin"], j)
  106.       if j == l_yspot then
  107.          for k = 0, p_bData["xmax"] - p_bData["xmin"] - string.len(p_text) +1 do
  108.             if k == l_xspot then
  109.                mon.write(p_text)
  110.             else
  111.                mon.write(" ")
  112.             end
  113.          end
  114.       else
  115.          for i = p_bData["xmin"], p_bData["xmax"] do
  116.             mon.write(" ")
  117.          end
  118.       end
  119.    end
  120.    mon.setBackgroundColor(colors.black)
  121. end
  122.      
  123. function Wyswietl()
  124.    local l_currColor
  125.    for name,data in pairs(button[g_strona]) do
  126.       local on = data["aktywny"]
  127.       local color = data["color"]
  128.      
  129.       if color ~= nil then
  130.         l_currColor = color
  131.       elseif on == true then
  132.         l_currColor = colors.lime
  133.       else
  134.         l_currColor = colors.red
  135.       end
  136.      
  137.       UtworzPrzycisk(name, l_currColor, data)
  138.    end
  139. end
  140.      
  141. function SprawdzXY(x, y)
  142.    for name, data in pairs(button[g_strona]) do
  143.       if y>=data["ymin"] and  y <= data["ymax"] then
  144.          if x>=data["xmin"] and x<= data["xmax"] then
  145.             data["funkcja"](data["parametr"], data["aktywny"])
  146.         --if data["color"] == nil then
  147.               data["aktywny"] = not data["aktywny"]
  148.         --end
  149.          end
  150.       end
  151.    end
  152. end
  153.      
  154. function Kodow_znaki(p_id, p_znaki)
  155.  p_id = tostring(p_id)
  156.  for tidlenc=1, p_znaki do
  157.   if string.len(p_id) == tidlenc
  158.   then
  159.    p_id = ("_"..p_id)
  160.   end
  161.  end
  162.  return p_id
  163. end
  164.  
  165. function WyslijRednet(p_typ, p_wiadomosc, p_aktywny, p_IdDocelowe)
  166.  if p_wiadomosc and p_IdDocelowe then
  167.     rednet.broadcast(Kodow_znaki(os.getComputerID(),4)..Kodow_znaki(p_IdDocelowe,4)..p_aktywny..Kodow_znaki(p_typ,16)..p_wiadomosc)
  168.  end
  169. end
  170.  
  171. function OdczytRednet(p_id, p_message)
  172.   if p_id and p_message then
  173.     if string.sub(p_message,6,10) == Kodow_znaki(os.getComputerID(),4) then
  174.      
  175.     end
  176.   end
  177. end  
  178.  
  179. function Naglowek(p_text)
  180.    w, h = mon.getSize()
  181.    mon.setCursorPos((w-string.len(p_text))/2+1, 1)
  182.    mon.write(p_text)
  183. end
  184.  
  185.  
  186.  
  187. UtworzStrony()
  188. UtworzTabele()
  189.  
  190. while true do
  191.    mon.clear()
  192.    Naglowek(g_naglowek[g_strona])
  193.    Wyswietl()
  194.    local event,p1,p2,p3 = os.pullEvent("mouse_click")
  195.    if event == "mouse_click" then --  Event, Side, X, Y  
  196.      SprawdzXY(p2,p3)
  197.    elseif  event == "rednet_message" then  --  Event, Id, Message
  198.      OdczytRednet(p1, p2)
  199.    end
  200.    
  201.    sleep(.1)
  202. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement