Advertisement
plytalent

AFHBModule

Apr 1st, 2022 (edited)
539
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.13 KB | None | 0 0
  1. local Real_functions = {
  2.     print = print,
  3.     tostring = tostring
  4. }
  5. local Internal_functions
  6. Internal_functions = {
  7.     tostring = function(inputobject)
  8.         if inputobject then
  9.             typeofinputobject = typeof(inputobject)
  10.             if typeofinputobject == "Userdata" or typeofinputobject == "Instance"  then
  11.                 local vaild, name = pcall(function()
  12.                     return inputobject.Name
  13.                 end)
  14.                 if vaild then
  15.                     print(vaild,name)
  16.                     return name
  17.                 end
  18.             elseif typeofinputobject == "Table" then
  19.                 local buffer = {"{\n"}
  20.                 for i,v in pairs(typeofinputobject) do
  21.                     buffer[#buffer+1] = "\t[" .. Internal_functions.tostring(i) .. "] = " .. Internal_functions.tostring(v) .. ",\n"
  22.                 end
  23.                 buffer[#buffer+1] = "}"
  24.                 local newstring = ""
  25.                 for i=1,#buffer do
  26.                     newstring = newstring .. buffer[i]
  27.                 end
  28.                 buffer = {}
  29.                 return newstring
  30.             else
  31.                 return inputobject
  32.             end
  33.             return Real_functions["tostring"](inputobject)
  34.         end
  35.         return ""
  36.     end,
  37.     print = function(...)
  38.         local buffer1 = {...}
  39.         local buffer2 = {}
  40.         for i=1,#buffer1 do
  41.             buffer2[#buffer2+1] = Internal_functions.tostring(buffer1[i]).."\t"
  42.         end
  43.         local newstring = ""
  44.         for i=1,#buffer2 do
  45.             newstring = newstring .. buffer2[i]
  46.         end
  47.         buffer1 = {}
  48.         buffer2 = {}
  49.         rconsoleinfo(newstring)
  50.         newstring = ""
  51.     end,
  52.     str_replace = function(stringin,find,replacewith)
  53.         local replacewith = Internal_functions.tostring(replacewith)
  54.         local string = Internal_functions.tostring(stringin)
  55.         local find = Internal_functions.tostring(find)
  56.         return stringin:gsub(find, replacewith)
  57.     end
  58. }
  59. local Internal_Event = {}
  60. local AFHB_funcs = {}
  61. local AFHB_EV
  62. do
  63.     local ArtificialHB = Instance.new("BindableEvent")
  64.     ArtificialHB.Name = "ArtificialHeartbeat"
  65.    
  66.     local frame = 1 / 60
  67.     local tf = 0
  68.     local allowframeloss = false
  69.     local tossremainder = false
  70.     local lastframe = tick()    
  71.     ArtificialHB:Fire()
  72.     local laststeptick = tick()
  73.     Internal_Event["ArtificialHeartBeatEvent"] = game:GetService("RunService").Stepped:connect(function(s)
  74.         local steppeddelta = tick() - laststeptick
  75.         laststeptick = tick()
  76.         tf = tf + steppeddelta
  77.         if tf >= frame then
  78.             local delta = tick() - lastframe
  79.             if allowframeloss then
  80.                 ArtificialHB:Fire(delta)
  81.                 lastframe = tick()
  82.             else
  83.                 for i = 1, math.floor(tf / frame) do
  84.                     local delta = tick() - lastframe
  85.                     ArtificialHB:Fire(delta)
  86.                     lastframe = tick()
  87.                 end
  88.                 lastframe = tick()
  89.             end
  90.             if tossremainder then
  91.                 tf = 0
  92.             else
  93.                 tf = tf - frame * math.floor(tf / frame)
  94.             end
  95.         end
  96.     end)
  97.     ArtificialHB.Event:Connect(function()
  98.         for i,func in pairs(AFHB_funcs) do
  99.             if func then
  100.                 local s, error_statement = pcall(function()
  101.                     func()
  102.                 end)
  103.                 if not s then
  104.                     Internal_functions.print("[AFHB ERROR] Event Name",i,"ErrorMessage",error_statement)
  105.                 end
  106.             end
  107.         end
  108.     end)
  109.     AFHB_EV = ArtificialHB.Event
  110. end
  111.  
  112. local sc
  113.  
  114. local sc_metatable = {
  115.     __index = function(self,key)
  116.         local strkey = Internal_functions.tostring(key)
  117.         if strkey then
  118.             Internal_functions.print("[SC_METATABLE] KeyName", typeof(strkey),strkey)
  119.             local retobject = rawget(sc,strkey)
  120.             if not retobject and key.ClassName~="" then
  121.                 retobject = game:GetService(key.ClassName)
  122.             end
  123.             return retobject
  124.         else
  125.             Internal_functions.print("[SC_METATABLE ERROR] ToString Return null", strkey)
  126.         end
  127.     end,
  128.     __call = function(self,...)
  129.         local args = {...}
  130.         if #args~=1 then
  131.             return
  132.         end
  133.         local strkey = Internal_functions.tostring(args[1])
  134.         if strkey then
  135.             Internal_functions.print("[SC_METATABLE] KeyName", typeof(strkey),strkey)
  136.             local retobject = rawget(sc,strkey)
  137.             if not retobject and args[1] .ClassName~="" then
  138.                 retobject = game:GetService(args[1].ClassName)
  139.             end
  140.             return retobject
  141.         else
  142.             Internal_functions.print("[SC_METATABLE ERROR] ToString Return null", strkey)
  143.         end
  144.     end
  145. }
  146. sc = {
  147.     ArtificialHeartBeat = AFHB_EV,
  148.     BindToAFHB = function(self,name,func)
  149.         AFHB_funcs[name] = func
  150.     end,
  151.     UnbindFromAFHB = function(self,name)
  152.         AFHB_funcs[name] = nil
  153.     end
  154. }
  155.  
  156. return setmetatable(sc,sc_metatable)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement