Unbox101

SmartGlasses

Apr 28th, 2022 (edited)
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.19 KB | None | 0 0
  1. local modules = peripheral.find("neuralInterface")
  2. rednet.open("top")
  3.  
  4. local buttons = {
  5.     {
  6.         name = "RocketJump",
  7.         pos = {40, 16},
  8.         size = {50, 10},
  9.         func = function()
  10.             for i=1,4 do
  11.                 modules.launch(0,5,0)
  12.             end
  13.         end
  14.     }
  15. }
  16. --[=[
  17. local function InitButtons()
  18.     for i,v in ipairs(buttons) do
  19.         local group = canvas.addGroup(v.pos)
  20.         group.addRectangle(0,0, v.size[1], v.size[2], 0xFF000064)
  21.         local text = group.addText({ 5, 5 }, v.name or v.text)
  22.     end
  23. end
  24.  
  25. --init stuffs
  26. InitButtons()
  27. ]=]
  28.  
  29. local previousLocationBroadcast = 0
  30.  
  31. local eventFunctions = {
  32.     --[[
  33.     glasses_click = function(event,button,x,y)
  34.        
  35.         for i,v in ipairs(buttons) do
  36.             --collision check
  37.             if x >= v.pos[1] and x < v.pos[1] + v.size[1] and y >= v.pos[2] and y < v.pos[2] + v.size[2] then
  38.                 --fire func if true
  39.                 v.func()
  40.             end
  41.         end
  42.         print( "The mouse button ", button, " was pressed at ", x, " and ", y )
  43.        
  44.     end,
  45.     ]]
  46.    
  47.     key = function(event,key,isHeld,arg4)
  48.         playerMeta = modules.getMetaOwner()
  49.         if not playerMeta then return end
  50.         if key == keys.space then
  51.             --for i=1,2 do
  52.                 modules.launch(playerMeta.yaw, playerMeta.pitch, 1)
  53.                 --modules.launch(0,5,0)
  54.             --end
  55.         end
  56.        
  57.     end,
  58.     customTick = function()
  59.         playerMeta = modules.getMetaOwner()
  60.         if not playerMeta then return end
  61.         if os.clock() - previousLocationBroadcast > 0.1 then
  62.             previousLocationBroadcast = os.clock()
  63.             local x,y,z = gps.locate()
  64.             if x and y and z then
  65.                 local playerPosTable = {
  66.                     x,
  67.                     y,
  68.                     z,
  69.                     playerMeta.yaw,
  70.                     playerMeta.pitch
  71.                 }
  72.                 --print(textutils.serialize(playerPosTable))
  73.                 rednet.broadcast(textutils.serialize(playerPosTable), "u2")
  74.             else
  75.                 --error("Error! Could not get smartGlasses.gps.locate()")
  76.             end
  77.            
  78.         end
  79.     end
  80. }
  81.  
  82.  
  83.  
  84. local str = ""
  85. for i,v in pairs(modules.getMetaOwner()) do
  86.     str = str..i.." : "
  87.    
  88. end
  89. print(str)
  90.  
  91.  
  92. os.queueEvent("abc")
  93. --main loop
  94. while true do
  95.  
  96.         local event, arg2, arg3, arg4 = os.pullEvent()
  97.        
  98.        
  99.         local eventFunc = eventFunctions[event]
  100.         if eventFunc then
  101.             eventFunc(event, arg2, arg3, arg4)
  102.         end
  103.         eventFunctions.customTick()
  104.         if event == "timer" then
  105.             os.startTimer(0.08)
  106.         end
  107.    
  108.    
  109.    
  110. end
Add Comment
Please, Sign In to add comment