Skip to content
/ SNet Public

A simple module that allows you to create network events within your modules.

License

Notifications You must be signed in to change notification settings

ShibaRed4/SNet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Qualitize Banner

LUA BABY ROBLOX ROBLOX STUDIO

SNet

A simple module that allows you to create network events within your modules. Whether it'd be server-client or client-server, this module can do it all!

Usage:

Main Server Script:

local SNet = require(path.to.SNet).new()
local ExampleModule = require(path.to.ExampleModule)

-- SNet --

SNet:Rollup({
  -- List of ModuleScripts goes here --
  ExampleModule.Package()
})

SNet:Compose()

Example Module Script:

local ExampleModule = {}
ExampleModule.__index = ExampleModule

function ExampleModule.new()
    local self = setmetatable({}, ExampleModule)
    return self
end

function ExampleModule.Package()
  return require(script.EmittableFunctions)
end

Example EmittableFunctions (This goes inside of your module script):

local EmittableFunctions = {
	Server = {
		Events = {
			["TestServerEvent"] = function(player, ...) -- "TestServerEvent" will be known as the "eventName"
			end
		},
		Callbacks = {
			["TestServerCallback"] = function(player, ...)
				return "Hello World"
			end
		},
	},
	Client = {
		Events = {
			["TestClientEvent"] = function(...)
				
			end,
		},
		Callbacks = {
			["TestClientCallback"] = function(...)
				return "Hello World from Client!"
			end,
		}
	},
	Name = script.Parent.Name -- "This will be youir "hostName"
}

return EmittableFunctions

Methods:

  • SNet:EmitCallback(hostName: string, callbackName: string, ...)
  • SNet:EmitEvent(hostName: string, eventName: string, ...)
  • SNet:EmitClientEvent(player: Player, hostName: string, eventName: string, ...)
  • SNet:EmitClientCallback(player: Player, hostName: string, eventName: string, ...)
  • SNet:EmitAllClientEvent(hostName: string, eventName: string, ...)

Why should I use this?

So you don't have multiple server scripts doing RemoteEvent.OnServerEvent:Connect(function(player) end) over and over again. Same thing with ClientSide events, it allows for better organization of your modules and logic. So instead of calling a (probably horribly named) remote event for a specific task, make a module that handles that task and other similar tasks, and when you need something done over the network, you can call methods that do it for you.

About

A simple module that allows you to create network events within your modules.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages