Public Transport AI

Hello, I’m trying to develop a resource that makes public transports aviable. The idea is that one or more buses are spawned at the server start and then they will keep following a path with bus stops on the way.

So I wrote all the script client-side and some server-side like the creation of bus and bus driver ped. When the resource starts the server takes the first client and asks it to manage all the stuff (like driving the bus, stop at the bus stops…) and as long as the client who is running the script is online is good, but once he disconnects everything rightfully stops working.
So my question is: is there a way to make everything server-side? Like make the server take care of driving the bus ecc…

Here’s what I’ve done for now: https://github.com/FedericoDeBona/esx_publictransport

1 Like

I found your script a few days ago on github and tested it out.
Worked very well and performance was good.
But it seemed like Buses are not enterable at the moment?

Hi, thanks for testing it out. I’ve uploaded a fix for that problem.
But consider that the first player that connects to the server runs all the code for everyone (give driver the tasks, check for bus stops…), and when he disconnects, the server chooses another client to make it run everything.
By doing this every client connected to the server sees the same buses (and it’s the only way I found, because server can’t run this kind of code except of creating peds and vehicles. Another solution would have been creating everything local but then everyone would see something different and was not what I wanted).
Also the part of code of re-assign all the work to another client it’s bad (or even not working) because it’s hard to test beign alone on the server, so take this resource with a grain of salt.