[Release] SecretCars > car only in local need to be fix

@ 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 :slight_smile:.

@ Briglair: Ohh … I was too quick when I read your answer. Fully okayy :relaxed:

@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.

@ Briglair: Okayy I see… :relaxed:.

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? :grinning:

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)

2 Likes

is there a way to make all parked one and those who drive arround lock so poeple cant steel car ?

@ Briglair: Okayy and thanks…

I will do some experiments to morrow. It is bedtime here in Denmark :relaxed:

@ Briglair: Hi again :relaxed:.

It working very fine. I have placed your command as the last line in the script: SetVehicleDoorsLocked (vehicle, 2). Thanks for your help :relaxed:

@MarkViolla Hey, any updates?

@SorensenDK Glad it worked!

1 Like

that would be cool on all car riding arround so poeple dont steel car every 2 sec

hey maybe whit one of those 2 script we can make it work !?

https://github.com/FiveM-Scripts/FiveM-Taxi

https://github.com/FiveM-Scripts/police-stations

@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 ?? :open_mouth:

idk why its werd ! i will update the script whene we find how to fix the issu

Because the taxi script works fine and yours have a problem. Try to compare the two scripts, they are almost equal (almost :wink:), therefore is it weird :slight_smile:

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.

1 Like

i dont see what is wrong if you can show me ?

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 :relaxed:

Here’s a working script if anyone want it.

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

Oh my lord thank you