Shopping Cart
FiveM script 11abac85b780a6bfb422bb414511bacab31e72a7

OneSync / SERVER/CLIENT-SIDE Data Sharing – Modding Tutorials

FiveM Modding Tutorial

Features

  • Set data to any entity or object
  • Share the data with server / client

How to use it (Lua)

Server-side

GlobalState.mode="open"
--[[ set state mode to 'open' so client-side can share to server]]
local player = Entity(GetPlayerPed(source))
-- get Entity object from Entity id
player.state.anyKeyHere = anyValueHere
-- set any key and value to Entity state
print(player.state.anyKeyHere) 
-- return the 'anyKeyHere' set

Client-side

local player = Entity(PlayerPedId())
--[[ same as server get Entity object from Entity id ]]
print(player.state.anyKeyHere)
-- return the previus value set from server
player.state:set('anyKeyHere', anyValueHere, true --[[ bool | share with server? ]])
-- set any key and value to Entity state from client

Tested with other players. Yes, data is shared with all the players on the net

This is something like Decorators but an advanced Decor.
So that means, when you set data to an Entity and then a new player connect to the server, that data isnโ€™t shared. The data itโ€™s only shared with the currently net players, not new players.



Original source: https://forum.cfx.re/t/onesync-server-client-side-data-sharing/1555925

Leave a Reply

Your email address will not be published. Required fields are marked *

FiveM ESX Scripts

The best scripts and maps

Best support

Problems? We are there to help!

Wide range of products

We have a wide range of products

100% Secure Checkout

Stripe