Robert_Easter Posted August 2 Posted August 2 (edited) Hello, I have a problem with syncing the vehicle engine for everyone on player exit. So when a player quits the car, the engine always turns off. I was forced to use this code in order to fix it, but the problem is that it fixes the problem only for the player who leaves the car, for the other players outside the engine will always be off. Server side Code : mp.events.add('playerStartExitVehicle', (player) => { if (player.vehicle && player.vehicle.engine) { if (isExcludedVehicle(player.vehicle)) { return; } player.vehicle.engine = true; mp.players.forEach((_player) => { _player.call('syncVehicleEngineState', [player.vehicle.id, true]); }); } }); Client side : Code : mp.events.add('syncVehicleEngineState', (vehicleId, engineState) => { const vehicle = mp.vehicles.at(vehicleId); if (vehicle) { vehicle.engine = engineState; } }); Edited August 2 by Robert_Easter
Kopra Posted August 3 Posted August 3 You actually need to prevent ped from stopping the engine on exit to solve the desync. mp.players.local.setConfigFlag(241, true); // Disable player attempts to run engine causing glitch mp.players.local.setConfigFlag(429, true); // Disable turning off the engine when exiting a vehicle Invoked this on the client side in playerEnterVehicle handler.
Robert_Easter Posted August 4 Author Posted August 4 I already have a well cofigured vehicle engine script for turning off/on vehicle. But I have a question, the problem is that this script is only working starting by the second try(because of this i'm forced to apply de engine state on server side on first try). So the thing is that you need to enter a vehicle once and quit it in order the script to work correctly. mp.events.add('playerLeaveVehicle', (vehicle, seat) => { if (seat === -1) { mp.players.local.setConfigFlag(241, true); } });
Robert_Easter Posted August 4 Author Posted August 4 12 часа назад, Kopra сказал: You actually need to prevent ped from stopping the engine on exit to solve the desync. mp.players.local.setConfigFlag(241, true); // Disable player attempts to run engine causing glitch mp.players.local.setConfigFlag(429, true); // Disable turning off the engine when exiting a vehicle Invoked this on the client side in playerEnterVehicle handler. Ok sorry it's working ; mp.events.add('playerEnterVehicle', (vehicle, seat) => { if (seat === -1) { mp.players.local.setConfigFlag(241, true); mp.players.local.setConfigFlag(429, true); } }); Look but the problem is that when a player is far away and then approaches to the car, the car engine visually turns off(but if he sits he will drive it so server side is ok). the question is how can i sync it with entitystreamin ? is there a way or it's impossible ?
Kopra Posted August 4 Posted August 4 (edited) You can do something like this: Variable "engineStatus" would be set via your engine toggle event on the server mp.events.add('entityStreamIn', (entity) => { if (entity.type !== "vehicle") return; if (entity.getVariable('engineStatus')) { entity.setEngineOn(true, true, true); } else { entity.setEngineOn(false, true, true); } }); Might be worth trying entity.engine so you don't use additional data if it's synced properly already. Edited August 4 by Kopra
Robert_Easter Posted August 6 Author Posted August 6 В 04.08.2024 в 15:31, Kopra сказал: You can do something like this: Variable "engineStatus" would be set via your engine toggle event on the server mp.events.add('entityStreamIn', (entity) => { if (entity.type !== "vehicle") return; if (entity.getVariable('engineStatus')) { entity.setEngineOn(true, true, true); } else { entity.setEngineOn(false, true, true); } }); Might be worth trying entity.engine so you don't use additional data if it's synced properly already. EXCELLENT ! now the vehicle system is visually and logically perfect for me. Anyone can use it the same way you described if wished
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now