@ Briglair: As I see it … The server spawns three cars in the room at the car dealer. My friend and I spawn another place and go together to the car dealer. I stand and look at that he goes into one of the cars. Immediately he begins to ‘jump around’ in the car until he gets out again.
The same happens if he looks and I go into one of the cars? We use cars elsewhere in the system, but it is only with these cars this happens. Therefore, I believe that there is something wrong with the ‘spawn method’ in the script .
@ Briglair: Ohh … I was too quick when I read your answer. Fully okayy …
@SorensenDK - Yes, you are correct. When the car is spawned, it is not enabled with the network. Meaning, that car only exists on YOUR screen. It does not exist on your friend’s screen. You friend also sees a car, but it is a different car. It is the same model, but a completely different entity. It is not synced.
@promethium Worth a shot to try and prevent simultaneous spawning.
Also has a couple other ideas. Although a host really isn’t used (that I know of), the script still finds a host and selects one. We could make it only run if the player is host. Or if that doesn’t work, have a loop on the server to run every several seconds that gets all players. Have it trigger client event only once on the first player. Then after either of these ideas, it would set that variable so it won’t be run again.
As I wrote earlier. I will only use them as a ‘decoration’ in car shop, so If there was a way to “lock” them, so I can use the script as it is now. You do not steal the cars on display in a store, right? …
That should work for you, yes. After the car is spawned, you can use SetVehicleDoorsLocked(vehicle, doorLockStatus). The diffetent lock statuses are: (from http://www.dev-c.com/nativedb/ )
0 - CARLOCK_NONE
1 - CARLOCK_UNLOCKED
2 - CARLOCK_LOCKED (locked)
3 - CARLOCK_LOCKOUT_PLAYER_ONLY
4 - CARLOCK_LOCKED_PLAYER_INSIDE (can get in, can’t leave)
(maybe, these are leftovers from GTA:VC)
5 - CARLOCK_LOCKED_INITIALLY
6 - CARLOCK_FORCE_SHUT_DOORS
7 - CARLOCK_LOCKED_BUT_CAN_BE_DAMAGED
(source: GTA VC miss2 leak, matching constants for 0/2/4, testing)
@Antoine:
I don’t quite understand what is happening. The police script is almost identical to your script (same car spawn method), but it works fine when I test it with my friend, so ?? …
Just have the client trigger a server event when they enter, the server event checks a server variable, such as areVehiclesSpawnedYet then spawns them if it is false and sets the variable to true.
There is nothing wrong with your script comparing with the taxi script. Therefore I don’t understand your script giving problems and not the taxi script, hope you understand my wondering, that’s all …
Citizen.CreateThread(function()
local vehicle = GetHashKey("patriot")
RequestModel(vehicle)
while not HasModelLoaded(vehicle) do
Citizen.Wait(0)
end
CreateVehicle(vehicle, x, y, z, h, true, true)
while true do
Wait(1)
if not IsAnyVehicleNearPoint(x, y, z, 10.0) then
CreateVehicle(vehicle, x, y, z, h, true, true)
end
end
end)
The only issue is that it will spawn a vehicle for each client connecting to the server