{"id":"cluelessd3v/remotehub","name":"remotehub","scope":"cluelessd3v","platform":"roblox","description":"An interface to streamline Remote Events instancing, Remote Function, and Object Values through code. Inspired by Sleitnick's Signal, & Net. Includes some useful Event functions, read more at https://github.com/CluelessD3v/RemoteHub","version":"0.7.1","latest":"0.7.1","versions":["0.1.0","0.1.1","0.1.2","0.1.4","0.1.5","0.2.0","0.3.0","0.3.1","0.4.0","0.4.1","0.5.0","0.5.1","0.6.0","0.6.1","0.7.0","0.7.1"],"license":"MIT","licenseRating":"safe","licenseCaveats":[],"licenseVerified":false,"dependencies":{},"integrity":"62601722a8beeb62512d484953e5dd17d26f3555269f6a93a71ff0591c7706e4","likes":0,"downloads":0,"install":"forest install cluelessd3v/remotehub","url":"https://forest.dev/p/roblox/cluelessd3v/remotehub","files":"https://api.forest.dev/ai/package/roblox/cluelessd3v/remotehub/files","readme":"# Remote Hub\r\n\r\n\"An interface to streamline Remote Events, Remote Function, and Object Values instancing through code. Inspired by Sleitnick's Signal, & Net. \r\n\r\nThis utility does not tries to pull magic wizardry, or meta-brograming, simply put: I made this because I like to create remote communication instances  through code.\r\n\r\nAlso added some useful functions to event because why not.\r\n\r\n**This is a library, not a class/service! I'm not returning special objects or tables in the constructors,  you're always dealing with a remote instance** \r\n\r\n\r\n### **WARNING: Remote functions and events are parented to the module, you are free to reparent them, but do note that the client getter will NOT work unless the remote is childed to the module were it was created originaly** \r\n\r\n**[Get it on wally](https://wally.run/package/cluelessd3v/remotehub)**\r\n\r\n\r\n***Proper Documentation coming soon***\r\n\r\n\r\n# API's\r\nRemote Hub includes 3 API's:\r\n- Remote Events API called \"Event\" (For Remote Events)\r\n- Remote Functions API called \"Function\" (For Remote Functions)\r\n- Object Values API called \"Value\" (For Object values) **Not finalized**\r\n\r\n\r\n\r\n## Event\r\n\r\n### Functions\r\n#### `new`\r\n>**Params: `(name: string?, namespace: string?)`**\r\n> *Creates a new Remote Event Instance of the given name within the given namespace if any. if no parent is given then the remote event will be childed to the module.*\r\n\r\n\r\n\r\n#### `FireSomeClients`\r\n>**Params: `(anEvent: RemoteEvent, thePlayersTable: {Player} | {any: Player}, ...:any)`**\r\n> *Fires the event exclusively to the players in the given players table, essentially a whitelist*\r\n\r\n\r\n\r\n#### `FireSomeClientsExcept`\r\n>**Params: (anEvent: RemoteEvent, theExcludedPlayersTable: {Player} | {any: Player}, ...:any)**\r\n> *The opposite of FireSomeClients, Fires the event exclusively to the players THAT ARE NOT in the given players table, essentially a blacklist*\r\n\r\n\r\n\r\n\r\n\r\n#### `FireAllClientsInRadius`\r\n>**Params: `(anEvent: RemoteEvent, aRadius: number, inPosition: Vector3, ...:any)`**\r\n> *Fires the event exclusively to the players within the given radius of the given position*\r\n\r\n\r\n### `FireAllClientsInRadiusExcept`\r\n>**Params: `(anEvent: RemoteEvent, thePlayersToExcludeTable: {Player} | {[any]: Player}, theRadius: number, thePosition: Vector3, ...:any)`**\r\n> *Fires the event exclusively to the players within the given radius of the given position*\r\n\r\n\r\n[[note | Wildcard function]]\r\n| A general use case Fire function in the case you *really* want to keep the event firing condition as a single logical unit, I don't really use it since it's redundant and less readable (IMO), but hey it's there if you really want to use it.\r\n\r\n#### `FireIfTrue`\r\n>**Params: (anEvent: RemoteEvent, thePlayersTable: {Player} | {any: Player}, thePredicateFunction: (player: player) -> nil ...:any)**\r\n> *Fires the event to the players in the given players table if the predicate function returns true*\r\n\r\n\r\n**Client**\r\n\r\n### `get`\r\n>**Params: `(name: string?, namespace: string?)`**\r\n> *Attempts to get an existing remote event from RemoteHub, if it's not found then it'll wait 10 seconds for it to appear*\r\n\r\n\r\n\r\n\r\n\r\n## Function\r\n\r\n\r\n### Functions\r\n\r\n\r\n#### `new`\r\n>**Params: `(name: string?, namespace: string?)`**\r\n> *Creates a new Remote Function Instance of the given name within the given namespace if any. if no parent is given then the Remote Function will be childed to the module.*\r\n\r\n\r\n**Client**\r\n\r\n### `get`\r\n>**Params: `(name: string?, namespace: string?)`**\r\n> *Attempts to get an existing Remote Function from RemoteHub, if it's not found then it'll wait 10 seconds for it to appear*\r\n\r\n\r\n\r\n\r\n\r\n# Example\r\n\r\n*Notify the players in your team that you joined them* \r\n\r\n**In a server script**\r\n```lua\r\nlocal Teams = game:GetService(\"Teams\")\r\n\r\nlocal RemoteHub = require(game.ReplicatedStorage.RemoteHub)\r\nlocal Event = RemoteHub.Event\r\n\r\n\r\n\r\nlocal BlueTeam = Instance.new(\"Team\", Teams)\r\nBlueTeam.Name = \"BlueTeam\"\r\n\r\nlocal RedTeam = Instance.new(\"Team\", Teams)\r\nRedTeam.Name = \"RedTeam\"\r\n\r\n\r\nlocal NotifyPlayerJoinedTeam = Event.new(\"NotifyPlayerJoinedTeam\")\r\n\r\ngame.Players.PlayerAdded:Connect(function(player)\r\n     player.characterAdded:Wait()\r\n     local teamsList = Teams:GetTeams()\r\n\r\n     player.Team = teamsList[math.random(1, #teamsList)]\r\n     Event.FireSomeClients(NotifyPlayerJoinedTeam, player.Team:GetPlayers(), player)\r\nend)\r\n```\r\n\r\n**In a local script**\r\n```lua\r\nlocal RemoteHub = require(game.ReplicatedStorage.RemoteHub)\r\nlocal Event = RemoteHub.Event\r\n\r\nlocal NotifyPlayerJoinedTeam: RemoteEvent = Event.get(\"NotifyPlayerJoinedTeam\")\r\n\r\nNotifyPlayerJoinedTeam.OnClientEvent:Connect(function(player)\r\n     print(player, \"joined our team!\")\r\nend)\r\n```\r\n\r\n\r\n*That's pretty much the pattern to use Remote hub, Function works exactly the same*\r\n\r\n\r\n# Footnotes:\r\nDeveloping this I realized that it would actually be useful to pull metabrogramming for this, lol. It would be nice that you could access these methods from the remote event instance itself, as in: `SomeRemoteEvent:FireSomeClients`, *[which would require me to wrap a metatable around remote comms instances](https://devforum.roblox.com/t/wrapping-with-metatables-or-how-to-alter-the-functionality-of-roblox-objects-without-touching-them/221611)*\r\n\r\nBut oh well, right now it's out of scope for now as I don't really need it, it just would be nice though.\r\n\r\n\r\n","readmeTruncated":false}