[OneSync / Server] - CreateVehicle Server-Side

Client

Using canary? No.
Windows version: Windows 10 Pro, 64 bit (Build 19041)
System specifications: i5 8400, GTX 1060 6GB, 16 GB RAM.

Server

Operating system: Windows 10 Pro, 64 bit (Build 19041)
Artifact version: I tested it on 2967 and 3100.
IP address: 127.0.0.1
Resources: Clean server.
System specifications: i5 8400, GTX 1060 6GB, 16 GB RAM.

Incident

Summary: Tried spawning a car on the server, using a command, and after all the player leave, the car dosen’t stay spawned. After all players leave, and at least one joins back the car is not more on the server. The command is set on the server-side script, as many told me to do, in order to keep the car spawned.

Expected behavior: As far as everyone told me, including some moderators, after spawning the car on the server, it should be persistent, and not dissaper, even if there are no players online.
Actual behavior: The car despawns after all the players leave the server, and when they join back, the car is not more there.

Steps to reproduce: Create a resource, and create a command using CreateVehicle to spawn a vehicle on the server side file. Join the server (only 1 player), use the command to create the car, then leave the server. After leaving the server, join back and the car won’t be there anymore.
Server/Client? Server.
Files for repro (if any):

RegisterCommand('vehicle', function()

   CreateVehicle(3486135912, -1446.072, 5411.912, 24.83151, 1.0, true, true)
   

end)

Error screenshot (if any): There are no errors. The cars spawn as they should, but don’t remain spawned after all players leave. https://streamable.com/jq7v88

.dmp files/report IDs: None.

Any additional info: Using +set onesync legacy (in the server start file)

Edit: Some really strange things happen. Tried to print the owner of the entity. Used the same command. One time it returned -1 (server), and one time it printed my ID. Still can’t understand why that happens. Gonna try to replicate it.

Edit #2: Here is the video, along with the code I used: https://streamable.com/jq7v88

The code used:

RegisterCommand('vehicle', function()

    local vehicle = CreateVehicle(3486135912, -1440.072, 5411.912, 24.83151, 1.0, true, true)
    Wait(1000)
    print(NetworkGetEntityOwner(vehicle))

end)

As you can see in the video, using the same command over and over, but the print, sometimes returns different values. Any idea what can cause this?

why do you think if you wait 1000 ms it will create the vehicle in that time being ? just do a loop until that entity is EXIST then check for the entity owner

If I don’t do the Wait there, the script shows an error.

And will what you told me solve the problem? I don’t think that is the root of the problem. I just wanted to see who will be asigned the owner of the vehicle, and as far as I saw, the owner of the vehicle is not always the server (can’t understand why).

CREATE_VEHICLE gets routed to a nearby client as server use of the native is even older than OneSync, there’s a replacement being worked on which you can manually invoke for any cars (but not planes/helis/boats/bikes/…) but it’ll be removed once it’s actually done/default.

i do a

while not DoesEntityExist(vehicle) do
	Citizen.Wait(0)
end

for it to be created then i ask for

print(NetworkGetEntityOwner(vehicle))

works without any issues

bubble could you explain whats wrong with it a little bit more ? i cant undrestand it well because my English is not that good . because i removed all my client side create vehicles and by your text im worried that it get into trouble

So, why some guys say that spawning a car on the server, will keep it persistent? (And some even say that the code is working on their server)

And just to be sure, at the moment, there is no way of keeping a car persistent? (without using different scripts, etc.)

No, that’s not what I’m stating at all. A created vehicle will (or well- should!) stay, assuming it is created.

So whats the best approach currently to spawn vehicle server side? CREATE_VEHICLE or CREATE_AUTOMOBILE?

No, that’s not what I’m stating at all. A created vehicle will (or well- should!) stay, assuming it is created.

I think what he’s asking is whether server side created vehicles can be owned by the server if there is no client around them. On older artifacts this used to happen by default, but it was removed shortly after and the general consensus seemed to be that to achieve the same result you have to spawn the vehicle on the server.

Yes, this still should be the case, AFTER they are already existent.

Is there an ETA for the replacement?

1 Like

I’ve been testing a script I created for persistent cars using server side CreateVehicle, the vehicles created with my script remained on the server for at least 2 days (I never restarted my server during this period), even with no players connected.

When loading in and teleporting to the place the vehicles are at, it may take a few seconds (while the models load) for the vehicles to reappear but they all remained in their original locations.

I used artifacts 2997, with +set onesync legacy for testing this. Have not tested on Infinity. :slight_smile:
Based my script off the repro used in this thread.

1 Like

Ok, so what is the exact code you use? Just CreateVehicle?

The exact code I used can be found here.
It’s a C# resource, but it’s largely based off the repro in the aforementioned thread. :slight_smile:

1 Like

Ok, thanks. Gonna check it out.

How can I compile the resource to test it? Sorry for my inexperience, but I have never worked with C #

1 Like

Where can I read the source code for that? Searching for CREATE_VEHICLE or CreateVehicle didn’t find it.