Advertisement
AstolfoFate

tradepostClientB.lua

Mar 24th, 2021 (edited)
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.04 KB | None | 0 0
  1. rednet.open("right")
  2. term.clear()
  3. term.setCursorPos(1, 1)
  4. print("Welcome to Ozroth Trading post!\nInput your offer into the chest.\nWhen you are done, enter the command: \"offer\"\nFor a list of commands, enter the command: \"help\"")
  5.  
  6. function send()
  7. menu = true
  8.  
  9.   --commandline interface
  10.   while menu == true do
  11.     write("\nEnter command: ")
  12.     local cmd = read()
  13.     if cmd == "offer" then
  14.       rednet.send(427, "offerB")
  15.  
  16.       --demand command
  17.     elseif cmd == "demand" then
  18.       print("Enter your demands to the other trader. Return to Command mode with \"/exit\"")
  19.       repeat
  20.         menu = false
  21.         local msg = read()
  22.         rednet.send(427, "\""..msg.."\"")
  23.         if msg == "/exit" then
  24.           menu = true
  25.         end
  26.       until menu == true
  27.  
  28.       --exit program
  29.     elseif cmd == "exit" then
  30.       error("Program terminated")
  31.  
  32.       -- clear screen command
  33.     elseif cmd == "clear" then
  34.       term.clear()
  35.       term.setCursorPos(1, 1)
  36.  
  37.       -- decline command
  38.     elseif cmd == "decline" then
  39.       rednet.send(427, "decline")
  40.       rednet.send(427, "reboot")
  41.       os.reboot()
  42.  
  43.     elseif cmd == "accept" then
  44.       rednet.send(427, "acceptTradeB")
  45.  
  46.       --help commands
  47.     elseif cmd == "help" then
  48.       print("Commands: help, demand, exit, clear, offer, accept, decline\nPrefix a command with help to learn more about it.")
  49.     elseif cmd == "help help" then
  50.       print("Displays commands.")
  51.     elseif cmd == "help demand" then
  52.       print("Request items from the other trader.")
  53.     elseif cmd == "help clear" then
  54.       print("clears the terminal of clutter.")
  55.     elseif cmd == "help exit" then
  56.       print("exits the program")
  57.     elseif cmd == "help offer" then
  58.       print("Offers your items to the other trader")
  59.     elseif cmd == "help accept" then
  60.       print("accepts trade.")
  61.     elseif cmd == "help decline" then
  62.       print("declines trade and reboots both trading computers.")
  63.     else
  64.       print("unknown command")
  65.     end
  66.  
  67.   end
  68. end
  69.  
  70. function recv()
  71.   --network listener
  72.   while true do
  73.     local xLine, yLine = term.getCursorPos()
  74.     id, sendermsg = rednet.receive()
  75.     --chat
  76.     if sendermsg == string.match(sendermsg, "\".*\"") and menu == true then
  77.       print("\nTraderA: "..sendermsg.."\nEnter Command: ")
  78.       yLine = yLine + 3
  79.       term.setCursorPos(16, yLine)
  80.     elseif sendermsg == string.match(sendermsg, "\".*\"") and menu == false then
  81.       print("\nTraderA: "..sendermsg.."\nEnter Command: ")
  82.       yLine = yLine + 5
  83.       term.setCursorPos(1, yLine)
  84.       --print item data
  85.     elseif sendermsg == string.match(sendermsg, "offerAItem: .*") then
  86.       print("\n"..sendermsg.."\n")
  87.     elseif sendermsg == string.match(sendermsg, "offerADamage: .*") then
  88.       print("\n"..sendermsg.."\n")
  89.     elseif sendermsg == string.match(sendermsg, "offerACount: .*") then
  90.       print("\n"..sendermsg.."\n")
  91.       --reboot
  92.     elseif sendermsg == "reboot" then
  93.       os.reboot()
  94.     end
  95.   end
  96. end
  97.  
  98. while true do
  99.   parallel.waitForAny(recv, send)
  100. end
  101.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement