FiveM Modding Tutorial
- Set data to any entity or object
- Share the data with server / client
How to use it (Lua)
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
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