Jump to content

[NEED HELP] How to sync fire for server side


Mazen371

Recommended Posts

I made a script that has to do with fire and createFire() function, it worked perfectly for the client, but of course the fire wouldn't appear for other players on the server, what's the best approach to sync the fire in server-side? while making sure the fire is fully functional (burns and damages peds and vehicles)

Link to comment

The best way to sync fire is the same way you'd sync most things, and there are two options: the server creates fire and distributes information about it to clients, or clients create fire and inform the server, which then broadcasts the information to the other clients.

The second option is basically a slightly expanded version of the first, so I'll outline how the first could work:

  • Server runs a resource responsible for synchronizing fires between players.
  • This resource has an exported function or custom event
    • Security point: Don't allow remote trigger for custom events unless necessary, keep it server-triggered to prevent untrusted clients from being able to triggerServerEvent and spam the server with unauthorized fire; or, allow remote trigger but add logic to prevent unruly clients from being able to spawn fire where ever they want.
  • When the exported function is called, or the custom event triggered, the server adds to its table of existing fires certain data about the fire, including position, interior, dimension, size, maximum duration and timestamp or tickcount when spawned, and triggers a client event for all players: onReceiveSyncedFireData (or whatever you choose to name it) and sends this data through
  • Each client handles this event, and calls createFire on the client, along with timers to delete the fire when the current timestamp/tickcount exceeds the spawn timestamp/tickcount plus duration
    • If a tickcount is used, it's best if the client at this point determines their tickcount offset from the server's, and uses its own tickcount plus/minus server offset for further calculations.
  • A new client joining should request existing fires by triggering on the server an event onRequestSyncedFireData (or whatever you choose to name it)
    • The server handles this event by triggering on the new client the previously mentioned receive event for each fire in the server's fires table.
      • This client handles the receive events the exactly the same as if the fires were newly spawned.
  • If your scripts move fires around, you may add events that allow clients to make updates, in a similar way to the above but information flowing from the client to the server, and then broadcast down to the other clients
    • Security point: ideally check that only the element syncer is allowed to make changes to a fire, to prevent cheaters from tampering with fires they're nowhere near
  • Like 1
Link to comment

You can also implement your own fires using createEffect. This is going to require more work because you'll have to remake the fire mechanics in Lua (spreading, dying out, setting peds/vehicles on fire, extinguishing using fire extinguisher/firetruck) but the upside is that you'll be in full control - such fires will not spread or die out outside control of your script, and you can make them fully synced between all players.

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...