CREATE_VEHICLE doesn't create vehicle on server side until you pass 6th parameter

Client

Using canary: No
Windows version: 1909
System specifications:

Server

Operating system: Windows
Artifact version: 3561 (same with 3539)
IP address: localhost
Resources: default
System specifications:

Incident

Summary: I’ve created vehicle on server side and I am trying to get entity routing bucket, but server is not aware of entity and I receive error about invalid entity.
Expected behavior: I expect awared entity on server side after creation
Actual behavior: Entity is not awared on server side even after 1 minute, however plane is created in game.
Steps to reproduce: Run following code and use command /plane and then /dimveh:

local vehicle
RegisterCommand("plane", function(source, args, raw)
    local playerId = source
    local mode = args[1]    
    vehicle = CreateVehicle(GetHashKey("velum2"), GetEntityCoords(GetPlayerPed(playerId)))
end, false)

RegisterCommand("dimveh", function(source, args, raw)
    local playerId = source
    local dim = args[1]
    
    print("Dim", GetEntityRoutingBucket(vehicle))

    if dim ~= nil then
        SetEntityRoutingBucket(vehicle, tonumber(dim))
    end
end, false)

Server/Client: Server
Files for repro (if any): See above
Error screenshot (if any):


.dmp files/report IDs: *

Any additional info:

Edit:
Issue in function parameters, if you don’t pass a 6th parameter (it can be anything), then vehicle will not exist on server side.

vehicle = CreateVehicle(GetHashKey("blista"), GetEntityCoords(GetPlayerPed(playerId)), 0.0) -- will not exist on server side
vehicle = CreateVehicle(GetHashKey("blista"), GetEntityCoords(GetPlayerPed(playerId))) -- will not exist on server side
vehicle = CreateVehicle(GetHashKey("blista"), GetEntityCoords(GetPlayerPed(playerId)), 0.0, "dfsdfds") -- will exist on server side
1 Like

After reconnecting to server it works now :confused:

1 Like

Now it doesn’t work again. I am trying to investigate how to reproduce this error.

1 Like

This would be because you have to wait for the entity to be created, as CREATE_VEHICLE is an RPC native, the entity isn’t instantly created server-side unless you use the experimental CREATE_AUTOMOBILE native. If you want to use CreateVehicle you have to wait server side for the entity to exist.

1 Like

Yeah, you are right - it is not created instantly, but in this case it is not created at all. I’ve waited for 1 hour, but nothing :grin:

2 Likes

Are you passing a valid model?

1 Like

Yep. Vehicle itself is created in game.

1 Like

Posting those screenshots for better representation:

1 Like

Same happening on 3580 artifacts and now it is always happenin like this!

1 Like

Issue in function parameters, if you don’t pass a 6th parameter which can be anything, then vehicle will not exist on server side.

vehicle = CreateVehicle(GetHashKey("blista"), GetEntityCoords(GetPlayerPed(playerId)), 0.0) -- will not exist on server side
vehicle = CreateVehicle(GetHashKey("blista"), GetEntityCoords(GetPlayerPed(playerId))) -- will not exist on server side
vehicle = CreateVehicle(GetHashKey("blista"), GetEntityCoords(GetPlayerPed(playerId)), 0.0, "dfsdfds") -- will exist on server side
1 Like

Reading the CreateVehicle, wouldn’t it make sense to pass a ‘boolean’ in the 6th param (btw a string is a truthy) to tell the server that the entity is a networked entity? else its just false? Unless the Lua system is defaulting the last two params isNetworked and netMissionEntity as true but no longer is which is why it doesn’t work in the way you’re expecting it.

2 Likes

CREATE_VEHICLE exactly mirrors the client native, which also needs the network flag set.

1 Like

Code -

XD.Functions.CreateCallback('XD:SpawnVehicleSV', function(source, cb, model, coords, heading) 
    local vehicle = CreateVehicle(model, coords.x, coords.y, coords.z, heading, true, true, true)
    print(NetworkGetEntityOwner(vehicle))
    cb(vehicle)
end)

Result -


Code -

XD.Functions.CreateCallback('XD:SpawnVehicleSV', function(source, cb, model, coords, heading) 
    local vehicle = CreateVehicle(model, coords.x, coords.y, coords.z, heading, true, true, true)
    while not DoesEntityExist(vehicle) do
        Citizen.Wait(100)
        print("waiting")
    end
    print(NetworkGetEntityOwner(vehicle))
    cb(vehicle)
end)

Result -

image

So basically you need to wait for entity to be created to avoid any invalid entity errors.

2 Likes