Title says it. Just need to know if it would be harder to do one event for client side things to server side or if each player just has there own event
A remote event if you’re firing to the server from the client, you only need one for 1 (or more) jobs. You can do more jobs because of arguments. When the server is handling the event, the first argument is going to be the player instance that fired to the server. An example would be:
Server Script:
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(Player, ToDo)
if ToDo == 1 or ToDo == "1" then
print(Player.Name .. " Started 1")
elseif ToDo == 2 or ToDo == "2" then
print(Player.Name .. " Started 2")
else
print(Player.Name .. " Started ".. ToDo .. " (unknown)")
end
end)
Local Script:
game.ReplicatedStorage.RemoteEvent:FireServer("1")
Edit: Honestly, I would prefer one remote event, it just doesn’t take up as much space, but but I wouldn’t do all of the functions in one.
but if all local scripts are calling this often? This is for a sol’s rng inspired game
This is what I’d do if the actions are related enough.
I’d also have a dictionary mapping ToDo to functions and do
local actionDict = {
sus = function(player, value) --[[stuff]] end,
mogus = function(player, value, value2) --[[stuff]] end,
}
etc:Connect(function(player, ToDo, ...)
actionDict[ToDo](player, ...)
end
can you explain this better? (I has smooth brain)
Still, all those remote events and scripts would take up more bandwidth, you’d think. But, I’m not forcing you to, I would still make different remote events for different groups.
function attack(player, attackName)
--code to attack
end
function transform(player, form)
--code to transform into form
end
--set up a table of functions
local actionDict = {
attack = attack,
transform = transform,
}
ActionEvent:Connect(function(player, actionName, ...)
--find the function which performs the action actionName and call it
--'...' is a way of packing an unknown number of parameters, in case some actions require more values than others
actionDict[actionName](player, ...)
end
For me personally, I use multiple events for different things. However, functionality that is related to one event I use a command system similar to what @bluechristmas20181 is using. For instance, music playback would have an event called Music
. Within that event are commands that tell it to start, stop, pause, resume, etc… with parameters. Take a look below.
local command = {
Play = 1;
Stop = 2;
Pause = 3
Resume = 4;
}
local function play(sound, timeIndex)
end
local function stop()
end
local function pause(sound, timeIndex, fade)
end
local function resume(sound, timeIndex, fade)
end
local functionCallTable = {
[command.Play] = play;
[command.Stop] = stop;
[command.Pause] = pause;
[command.Resume] = resume;
}
game.ReplicatedStorage.Events.Music.OnClientEvent:Connect(function(command, sound, timeIndex, fade)
if functionCallTable[command] ~= nil then
functionCallTable[command](sound, timeIndex, fade)
end
end)
The above script is for the client, but you can do the same thing from the server.
That’s what I’m trying to get at, I think you did a better job than me at explaining.