Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ws = {}
- local wscd = {}
- for i=1,1 do
- print(string.format("[OverlayUI Debug] Connecting To ws://localhost:182%d",i))
- ws[i]=syn.websocket.connect(string.format("ws://localhost:182%d",i))
- wscd[i] = tick()
- end
- local HttpService = game:GetService("HttpService")
- local uiUpdated = Instance.new("BindableEvent")
- local OverlayUI = {
- OnUpdated=uiUpdated.Event,
- Settings={
- DebugMode = true
- }
- }
- for i=1,#ws do
- ws[i].OnMessage:Connect(function(msg)
- uiUpdated:Fire()
- if OverlayUI.Settings.DebugMode then
- print("[OverlayUI Debug][>>>]",msg)
- end
- end)
- end
- for i=1,#ws do
- ws[i].OnClose:Connect(function()
- if OverlayUI.Settings.DebugMode then
- print("[OverlayUI Debug]Connection lost")
- end
- end)
- end
- game.Close:Connect(function()
- ws:Close()
- end)
- function OverlayUI:CreateTextLabel(Name)
- local json = {
- Operation = "New",
- Name=Name,
- ClassName = "TextLabel",
- Text = "PlaceHolder",
- Alpha = 1,
- Args = {
- 1,
- 1,
- 1,
- 1,
- 1
- }
- }
- return json
- end
- function OverlayUI:CreateBox(Name)
- local json = {
- Operation = "New",
- Name=Name,
- ClassName = "Box",
- Alpha = 1,
- Args = {
- 1,
- 1,
- 1,
- 1
- }
- }
- return json
- end
- function OverlayUI:ValueChange(object, x, y, sizex, sizey, alpha, Text, sizetext)
- object["Operation"] = "ValueChange"
- if object["ClassName"] == TextLabel then
- object["Text"] = Text
- object["Args"][5] = sizetext or object["Args"][5]
- end
- object["Alpha"] = alpha or object["Alpha"]
- object["Args"][1] = x or object["Args"][1]
- object["Args"][2] = y or object["Args"][2]
- object["Args"][3] = sizex or object["Args"][3]
- object["Args"][4] = sizey or object["Args"][4]
- return object
- end
- function OverlayUI:Destroy(object)
- object["Operation"] = "Destroy"
- return object
- end
- function OverlayUI:Close()
- for i=1, #ws do
- ws[i]:Close()
- end
- end
- local packet = {}
- local sd = 0
- game:GetService("RunService").RenderStepped:Connect(function(delta)
- sd = sd + delta
- if sd >= 1/60 then
- sd = 0
- if #packet> 1 then
- OverlayUI:Update(packet)
- packet={}
- end
- end
- end)
- function OverlayUI:PackMultiple_Packet(object)
- packet[#packet+1] = object
- if #packet > 10 then
- OverlayUI:Update(packet)
- packet={}
- end
- end
- function OverlayUI:Update(object)
- object = HttpService:JSONEncode(object)
- for i=1, #ws do
- if tick() - wscd[i] < 1/60 then
- while true do
- if tick() - wscd[i] > 1/60 then
- break
- end
- end
- end
- wscd[i] = tick()
- if OverlayUI.Settings.DebugMode then
- print(string.format("[OverlayUI Debug][Websocket %d][<<<]",i),object)
- end
- ws[i]:Send(object)
- end
- end
- return OverlayUI
Add Comment
Please, Sign In to add comment