multitheftauto / mtasa-blue

Multi Theft Auto is a game engine that incorporates an extendable network play element into a proprietary commercial single-player game.
https://multitheftauto.com
GNU General Public License v3.0
1.41k stars 438 forks source link

Sync vehicle nitro state for nearby players also when it is disabled by setVehicleNitroActivated #2726

Open C0DELEVEL opened 2 years ago

C0DELEVEL commented 2 years ago

Is your feature request related to a problem? Please describe.

Currently, when nitro in a vehicle is activated (by button or by setVehicleNitroActivated function), this information is synchronized to other players. However, the moment we call setVehicleNitroActivated(vehicle, false) in the driver (which is syncer) - nitro will be disabled only for the driver (as localPlayer which executed this function), for other players it will still be active and cause a lot of desynchronization (acceleration is greater than on syncer side).

Describe the solution you'd like

Synchronize the status of nitro according to the current status of syncer (driver).

Describe alternatives you've considered

Currently, you have to work around this with a script, e.g. manually synchronizing nitro state (mainly off, as on by key is synced correctly) - driver -> server -> players nearby

Additional context

The problem mainly relates to the implementation of nitro on the button - hold = on, release = off. Sample script code that turns off the nitro when you release the button:

function toggleNOS(btn, state) local veh = getPedOccupiedVehicle(localPlayer) if veh and getVehicleController(veh) == localPlayer then if isVehicleNitroActivated(veh) then setVehicleNitroActivated (veh, false) -- <- This should be synced with nearby players, as it is when we set it to true. end end end bindKey("vehicle_fire", "up", toggleNOS)

Security Policy

Proxy-99 commented 2 months ago

This should fix the issue #3706

C0DELEVEL commented 2 months ago

This should fix the issue #3706

@Proxy-99 Thank you for your contribution, but I don't think this is a good solution (#3706) to this issue. It is useful in some cases, but not necessarily in the one I reported.

Why? Your solution has 2 drawbacks:

My suggestion was to improve the synchronization packets so that it works like turning on nitro on clientside.

  1. Pressing LPM to turn on nitro -> sends packet to nearby players about active nitro in car
  2. Depressing LPM to disable nitro (nitro is turned off clientside via setVehicleNitroActivated) -> sends an analogous packet to players nearby with disabled nitro status in the car.

Currently, the logic in the MTA only works halfway - a packet is sent about the activation of nitro, but not about its deactivation.

Proxy-99 commented 2 months ago

maybe I should add argument for dimension, if dimension not supplied a packet will be sent to all, so could be optimized a bit