Possible to run client scripts as the server?

Hey guys! I’m trying to figure out something that will be very beneficial to me. I understand that there’s a way to spawn cars and ped client-side and make it do stuff, HOWEVER, I want to spawn a ped in a vehicle SERVER side to do things for the duration of the server life.

ONE example would be a bus driver service where an AI bus is always running on the map with a viewable blip that shows everyone where the bus currently is.

The problem with this (with my current understanding of the fivem model), is that this has to run from a particular player which will cause overhang and lag on the poor bastard who has to run the script.

What Im looking for is a way to run this from the server and put that strain on the server.
One idea I have is a headless client that allows you to execute resources from. This way, I can just have the code execute the server-based client scripts from the client and let that user be (effectively) a part of the server.

Is there any way to run client scripts AS the server, OR should I get some sort of headless / ghost user to run my scripts from (that only the client can execute?)

How would you “do things” on the server without reimplementing all of GTA V on the server?

You can create entities fine, you can assign tasks for use whenever a player takes network ownership if an entity on the server, but anything more than that really makes no sense and is generally not viable at all (nor absolutely necessary! not sure what “overhang and lag” would be but processing one more entity on top of whatever else another client is processing won’t affect much at all).

1 Like

Well, I kinda wanna have my cake and eat it too! (aka I want client capabilities run from a server OR server-like entity)

Is there any documentation for this at all? Or maybe I’m not 100% sure what a player can take ownership of.

So for example, let’s take a train script. Let’s say (for simplicity’s sake), I wanted to make a train viewable and accessible to all players on the server. Blips, stops, the whole shebang. The problem is that the functionality has to be run from a client. When we execute the script, all of the logic (train driver, AI spawning, if statements, etc), end up getting run by the client initiating the script which are resources taken from the player.

If I have a headless player (e.g. playerID 1 or 2) that’s for the purpose of housing such script, those resources are run by a non-player, player, they’re not going to be run by the ACTUAL players.

Hopefully this helps illustrate my understanding (or lack thereof; LOL)

1 Like

That doesn’t make sense at all. Nor would it be possible. Loading the entire game world at once is not what the game code is meant for, so even if you’d massage a GTA V instance to do so it’d be impossibly slow.

‘the client initiating the script’

Not really. Could be the client owning the entity, the closest client, etc.

Also, ‘resources taken from the player’ - hm? The game already processes ~100 entities at once in a busy city area, including for remote-created entities, your concern seems mostly theoretical.

Yeah, a lot of it is theory based on my understanding of scripting. My concern is just that my server will (ideally) have a few resources that get created for and used by ALL players, so naturally, it should be run by the server.

And while a single scripts may not cause lag, you may run into a situation where many, many scripts that run the same function will end up having impact collectively on a client/client. THAT I know isn’t theory, and just how the clients work with regards to scripting. More client scripts = more processing.

Will I end up with THAT many scripts? Hard to say for now, but for people that WANT to leverage large amounts of events server-wide events, it’ll suck that there’s no built-in player to make THAT player process those resources.

No matter how much you’ll want that, it won’t be possible. Not without Rockstar releasing the GTA V source code and even then lots and lots and lots of adaptation.

Without the source code that’s even less likely to be workable.

Afirm. I guess I’ll just get my own player and run the code from there, or something. I’ll try to figure something out.

Thanks for the chat;

@nta One more thing - Do you think (using fivem source), it’s possible to simulate a player on the server to achieve the same thing? e.g. simulate a client from the localhost?

No? Client functions still wouldn’t exist as pretty much all of them are implemented in GTA code.

I think that you are overcomplicating a very simple thing.
You don’t need to have a virtual player on the server to process the game, that’s not a good way of achieving what you said.

What you wanna do is to make a resource that has both a client-side and a server-side script. The server-side script will manage the bus driver logic by triggering events. The client-side script will check if that entity exists and if it owns that entity, if it doesn’t then it just doesn’t do anything.
The client who owns the entity will actually call natives on the ped/vehicle.

But that’s my point. We can’t appoint the server to own a particular entity which would be optimal because its a shared resource. It wouldn’t be fair to add that additional processing power to players because that player may not leverage that resource. There may be a time where no one is using that script. In those cases, who should own the resource. I understand that yes, 1 bus script / route isn’t anything, and it won’t add any resource util to the client, but what about a bus network? A large group of busses and routes that gets leveraged across the server? Yes we can balance the load on all players, but it takes away from the overall experience.

I just don’t think it’s fair to say, let’s pick the most unlucky bastard to handle the load for this resource when its something that all players can leverage. Those types of resources should be processed by the server (or in my case, a general purpose utility-user).

But yes, I know. This is p2p and not client-server, so the resource management is different (which is where the convo ended)…

I think that even a computer with the bare minimum GTA V requirements could run such a script… You’re really worrying about something you shouldn’t worry about at all. It kinda reminds me of me when I was obsessed with making my resources hackers-proof.

1 Like

You are really over complicating your own wants here. You simply want a AI bus driver to be roaming the city on its own.

Several people now have told you that you are over complicating what you want and there is no reason to need to balance any load on any player as the load would be on the server it’s self.

Even if you wanted to make a script for a whole AI bus network, players on your server have no reason to need to “load balance” the script.

Unrelated: I can’t help but chuckle at your “FiveM is Dying” post in the middle of FiveM setting record breaking numbers.

I don’t mind DM’ming you as I feel like I’m going in circles here, but allow me to break it down one more time. My conclusion is based on the following facts:

  1. The more resources that are run on a client the slower the client becomes (even if fractional at first, that fraction concatenates and adds up.)

  2. You can’t run client scripts server sided (for example, there’s no create-vehicle native (CREATE_VEHICLE - Cfx.re Docs) for the server)

  3. At the end of the day certain tasks, threads, and logic will HAVE to be owned by a player

My point is that some tasks and threads are communal and should be instead owned by the server. Sometimes, there IS no ‘best client’ to handle a particular task

I understand, and have understood that this is impossible (based on how the fivem works) for a while now thanks to @nta. I’m just responding because you guys don’t seem to fully grasp my concern.

Also, @createdbyeric - Comparing the lack of activity here vs other modding communities of way older games, I do believe we’re still quite fragile, but I also believe it’s pointless to bring something like this up in an unrelated topic.

Lastly, if you’re gonna get emotional off of this topic, you can ignore it! No harm, no foul

1 Like

FiveM SDK is one of the most top played on Steam.

Who is emotional?

What you are not understanding is that what you want to do, doesn’t need nor makes sense to be ran via a client. You are asking for a “some what” simple script and you are severely over complicating it for absolutely no reason.

CREATE_VEHICLE is part of the rpc natives you can call from the server fivem/rpc_spec_natives.lua at master · citizenfx/fivem · GitHub there is also experimental create_automobile

1 Like

Okay, well THIS I was un-aware of, and will do more research on happily. Thank you @TheIndra for taking the high route and educating me.

Maybe I was phrasing my initial question wrong but based on what I was learning about cfx, Server natives can ONLY be run by the server, and client, ONLY run by the client. Seeing the rpc natives answers my question about functionality and tells me that clearly I have more research and testing to do…

And @createdbyeric Of COURSE the concept is simple. It’s just the example to demonstrate my knowledge of CFX specific-scripting with natives. But thank you for laughing at me, and reiterating what Sasino97 and deterministic_bubble already stated! I appreciate your contribution!

1 Like

Do you happen to have any documentation for said rpc natives, or shall I just reference da git and the forums?

this should be doable in theory: a server can simulate and predict clients’ states given that the simulated logic is shared among the two sides by some means: a shared library that both sides load, but it must be identical or the simulation will be out of sync, of course

however, because of this:

Client functions still wouldn’t exist as pretty much all of them are implemented in GTA code.

the shared logic is the missing piece to do that, in practice

1 Like

Fair enough. The example I gave was for train or bus functionality, but this was for the purposes of abstraction only.
My post history will reveal that the plane-related natives are my true goal here and some natives (namely task-plane-mission) are simply just not available on serverside and unfortunately may never be.
I’ll just have to wait, and just keep on requesting it in the natives;