Advertisement
Unbox101

airshipRemote

Apr 28th, 2022 (edited)
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.68 KB | None | 0 0
  1. rednet.open("back")
  2.  
  3. local pressingKeys = {}
  4.  
  5. local keysToDirectionsMap = {
  6.     [keys.w] = "front",
  7.     [keys.a] = "left",
  8.     [keys.s] = "back",
  9.     [keys.d] = "right",
  10. }
  11.  
  12. local function BroadcastDirection(direction)
  13.     print(direction)
  14.     rednet.broadcast(direction, "u")
  15. end
  16.  
  17. local function IfRemapThenBroadcast()
  18.     for i,v in pairs(pressingKeys) do
  19.         if v==true then
  20.             if keysToDirectionsMap[i] then
  21.                 BroadcastDirection(keysToDirectionsMap[i])
  22.             end
  23.         end
  24.     end
  25. end
  26.  
  27. while true do
  28.     local e, key = os.pullEvent()
  29.     if e == "key" then
  30.         pressingKeys[key] = true
  31.     elseif e == "key_up" then
  32.         pressingKeys[key] = nil
  33.     end
  34.    
  35.     IfRemapThenBroadcast()
  36. end
  37.  
  38. rednet.close("back")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement