plytalent

OverlayUI-LuaClient

Feb 20th, 2022 (edited)
706
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.13 KB | None | 0 0
  1. local ws = {}
  2. local wscd = {}
  3. for i=1,1 do
  4.     print(string.format("[OverlayUI Debug] Connecting To ws://localhost:182%d",i))
  5.     ws[i]=syn.websocket.connect(string.format("ws://localhost:182%d",i))
  6.     wscd[i] = tick()
  7. end
  8.  
  9. local HttpService = game:GetService("HttpService")
  10. local uiUpdated = Instance.new("BindableEvent")
  11. local OverlayUI = {
  12.     OnUpdated=uiUpdated.Event,
  13.     Settings={
  14.         DebugMode = true
  15.     }
  16. }
  17. for i=1,#ws do
  18.     ws[i].OnMessage:Connect(function(msg)
  19.         uiUpdated:Fire()
  20.         if OverlayUI.Settings.DebugMode then
  21.             print("[OverlayUI Debug][>>>]",msg)
  22.         end
  23.     end)
  24. end
  25. for i=1,#ws do
  26.     ws[i].OnClose:Connect(function()
  27.         if OverlayUI.Settings.DebugMode then
  28.             print("[OverlayUI Debug]Connection lost")
  29.         end
  30.     end)
  31. end
  32. game.Close:Connect(function()
  33.     ws:Close()
  34. end)
  35.  
  36. function OverlayUI:CreateTextLabel(Name)
  37.     local json = {
  38.         Operation = "New",
  39.         Name=Name,
  40.         ClassName = "TextLabel",
  41.         Text = "PlaceHolder",
  42.         Alpha = 1,
  43.         Args = {
  44.             1,
  45.             1,
  46.             1,
  47.             1,
  48.             1
  49.         }
  50.     }
  51.     return json
  52. end
  53.  
  54. function OverlayUI:CreateBox(Name)
  55.     local json = {
  56.         Operation = "New",
  57.         Name=Name,
  58.         ClassName = "Box",
  59.         Alpha = 1,
  60.         Args = {
  61.             1,
  62.             1,
  63.             1,
  64.             1
  65.         }
  66.     }
  67.     return json
  68. end
  69.  
  70. function OverlayUI:ValueChange(object, x, y, sizex, sizey, alpha, Text, sizetext)
  71.     object["Operation"] = "ValueChange"
  72.     if object["ClassName"] == TextLabel then
  73.         object["Text"] = Text
  74.         object["Args"][5] = sizetext or object["Args"][5]
  75.     end
  76.     object["Alpha"] = alpha or object["Alpha"]
  77.     object["Args"][1] = x or object["Args"][1]
  78.     object["Args"][2] = y or object["Args"][2]
  79.     object["Args"][3] = sizex or object["Args"][3]
  80.     object["Args"][4] = sizey or object["Args"][4]
  81.     return object
  82. end
  83.  
  84. function OverlayUI:Destroy(object)
  85.     object["Operation"]  = "Destroy"
  86.     return object
  87. end
  88.  
  89. function OverlayUI:Close()
  90.     for i=1, #ws do
  91.         ws[i]:Close()
  92.     end
  93. end
  94. local packet = {}
  95. local sd = 0
  96. game:GetService("RunService").RenderStepped:Connect(function(delta)
  97.     sd = sd + delta
  98.     if sd >= 1/60 then
  99.         sd = 0
  100.         if #packet> 1 then
  101.             OverlayUI:Update(packet)
  102.             packet={}
  103.         end
  104.     end
  105. end)
  106.  
  107. function OverlayUI:PackMultiple_Packet(object)
  108.     packet[#packet+1] = object
  109.     if #packet > 10 then
  110.         OverlayUI:Update(packet)
  111.         packet={}
  112.     end
  113. end
  114. function OverlayUI:Update(object)
  115.     object = HttpService:JSONEncode(object)
  116.     for i=1, #ws do
  117.         if tick() - wscd[i] < 1/60 then
  118.             while true do
  119.                 if tick() - wscd[i] > 1/60 then
  120.                     break
  121.                 end
  122.             end
  123.         end
  124.         wscd[i] = tick()
  125.         if OverlayUI.Settings.DebugMode then
  126.             print(string.format("[OverlayUI Debug][Websocket %d][<<<]",i),object)
  127.         end
  128.         ws[i]:Send(object)
  129.     end
  130. end
  131. return OverlayUI
Add Comment
Please, Sign In to add comment