-
Notifications
You must be signed in to change notification settings - Fork 0
/
Network.lua
59 lines (43 loc) · 1.61 KB
/
Network.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
local HttpService = game:GetService("HttpService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Network = {}
local networkIndex = {}
function Network.Start()
task.spawn(function()
while true do
for eventName, uniqueId in networkIndex do
local newId = HttpService:GenerateGUID(false)
networkIndex[eventName] = newId
ReplicatedStorage.Network[uniqueId].Name = newId
end
ReplicatedStorage.Network.NetworkSync:FireAllClients(networkIndex)
task.wait(1)
end
end)
end
function Network.GetEvent(eventName)
assert(typeof(eventName) == "string", "Event must be a string")
if networkIndex[eventName] == nil then
local eventId = HttpService:GenerateGUID(false)
local event = Instance.new("RemoteEvent")
event.Name = eventId
event.Parent = ReplicatedStorage.Network
networkIndex[eventName] = eventId
return event
else
return ReplicatedStorage.Network[networkIndex[eventName]]
end
end
function Network.GetFunction(functionName)
assert(typeof(functionName) == "string", "Event must be a string")
if networkIndex[functionName] == nil then
local functionId = HttpService:GenerateGUID(false)
local remoteFunction = Instance.new("RemoteFunction")
remoteFunction.Name = functionId
remoteFunction.Parent = ReplicatedStorage.Network
networkIndex[functionName] = functionId
else
return ReplicatedStorage.Network[networkIndex[functionName]]
end
end
return Network