Register commands on the server side?

I’ve seen many cases of people registering commands within the client-side using the RegisterCommand function. This made me wonder why no one does this on the server-side. Is it because it’s not possible? Or is it just inconvenient? Or does it only make sense in my imagination?

Example of the logic I think is ideal (ONLY a logic representation, not the way to write the code):

server.lua:

RegisterCommand("getmyposition"....) 
local coords = GetEntityCoords(MyPlayerId) 
SendDataToClientFunction(coords) 
end

client.lua:

ReceiveServerDataFunction(coords) 
SendPlayerNotification("Your actual Pos:" coords)

Just to make it clear, this is only a logic demonstration. I’m learning the technical side from scratch, and since I don’t know anything about Lua/FiveM yet, I’m just trying to understand why the logic isn’t done this way. At least from what I’ve seen, it’s not done the way I presented above. The way people do it here is like this:

client.lua:

RegisterCommand("getmyposition"....) 
local coords = GetEntityCoords(MyPlayerId) 
SendPlayerNotification("Your actual Pos:" coords) 
end

If anyone could explain this to me, I would greatly appreciate it!!!

1 Like

Yes, you can register commands on the server just fine.

There are lots of different reasons people can register the command on the client vs the server. That would depend a lot on the use case.

The example you gave is one that would be fine just registering on the client. It would work just fine doing it from the server and sending the data but there is no need to do it that way.

2 Likes

As far as I understand, without a security concern for the command, clients have more immediate information about the game than the server does. The server only “knows” client position data because the client tells the server their position, so if you can ask the client directly for this information it is just faster, and more accurate to the timing requested. I understand your example is the simplest available function you could think of, but generally clients have access to information about the game sooner than the server, and you skip any network latency, so if security is not an issue offloading functionality on the client is fine.

1 Like