Depercated due to idea of “maybe you do not need to use this module”
I will introduce the network module that I made with TypeScript to you.
(Do not worry, you can use it with Roblox script)
for the TypeScript usage tutorial and source code, you can check GitHub source
Here is the Roblox module
Tutorials
Import
local Net = require(game.ReplicatedStorage.NetTS).default
local myevents = Net.new('myevents')
Single Script
local Net = require(game.ReplicatedStorage.NetTS).default
local myevents = Net.new('myevents')
myevents:addListener('print params', function(params)
print(params)
end)
myevents:emit('print params', { test = 111 })
Server To Server | Client To Client
-- Script 1
local Net = require(game.ReplicatedStorage.NetTS).default
local myevents = Net.new('myevents')
myevents:addListener('print params', function(params)
print(params)
end)
-- Script 2
local Net = require(game.ReplicatedStorage.NetTS).default
local myevents = Net.new('myevents')
myevents:emit('print params', { test = 111 })
Server To Client
-- LocalScript
local Net = require(game.ReplicatedStorage.NetTS).default
local myevents = Net.new('myevents')
myevents:addListener('print params', function(params)
print(params)
end, true) -- <--- you have to add extra ",true)" to specify this is a remote event
-- Script
local Net = require(game.ReplicatedStorage.NetTS).default
local myevents = Net.new('myevents')
myevents:emit('print params', { test = 111, _player = game.Players.Monotter }, true) -- <--- you have to add extra ",true)" to specify this is a remote event
-- also to specify a specific player you have to use "_player" parameter
Server To All Clients
-- LocalScript
local Net = require(game.ReplicatedStorage.NetTS).default
local myevents = Net.new('myevents')
myevents:addListener('print params', function(params)
print(params)
end, true) -- <--- you have to add extra ",true)" to specify this is a remote event
-- Script
local Net = require(game.ReplicatedStorage.NetTS).default
local myevents = Net.new('myevents')
myevents:emit('print params', { test = 111 }, true) -- <--- you have to add extra ",true)" to specify this is a remote event
-- if you do not specify "_player" parameter, it will automatically act like FireAllClients
Client To Server
-- Script
local Net = require(game.ReplicatedStorage.NetTS).default
local myevents = Net.new('myevents')
myevents:addListener('kick itself', function(params)
local Player = params._player
local Reason = params.reason
Player:Kick(Reason)
end, true) -- <--- you have to add extra ",true)" to specify this is a remote event
-- LocalScript
local Net = require(game.ReplicatedStorage.NetTS).default
local myevents = Net.new('myevents')
myevents:emit('kick itself', { reason = 'im so pro' }, true) -- <--- you have to add extra ",true)" to specify this is a remote event
Return
-- Script 1
local Net = require(game.ReplicatedStorage.NetTS).default
local myevents = Net.new('myevents')
myevents:addListener('add', function(params)
return params.number1 + params.number2
end)
-- Script 2
local Net = require(game.ReplicatedStorage.NetTS).default
local myevents = Net.new('myevents')
local result = myevents:emit('add', { number1 = 30, number2 = 1 }, false, true)
print(result) -- 31
You can use this "return thing"
on "Server To All Clients"
too, it will give a result of the first returned function
To Do
- data packing and queue system to reduce lag like
BridgeNet
does
that’s all, I hope you love it!